From 602643b93d9bd7c08d4de2d8cd0483309ac67f64 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sat, 27 Aug 2016 19:25:38 +0200 Subject: [PATCH] Provide location information for objects and templates in the API fixes #12566 --- doc/12-icinga2-api.md | 4 ++-- lib/remote/objectqueryhandler.cpp | 9 +++++++++ lib/remote/templatequeryhandler.cpp | 10 ++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/doc/12-icinga2-api.md b/doc/12-icinga2-api.md index 9f18a2d8f..0ed18f25e 100644 --- a/doc/12-icinga2-api.md +++ b/doc/12-icinga2-api.md @@ -387,7 +387,7 @@ The following URL parameters are available: -----------|--------------|---------------------------- attrs | string array | **Optional.** Limits attributes in the output. joins | string array | **Optional.** Join related object types and their attributes (`?joins=host` for the entire set, or selectively by `?joins=host.name`). - meta | string array | **Optional.** Enable meta information using `?meta=used_by`. Defaults to disabled. + meta | string array | **Optional.** Enable meta information using `?meta=used_by` (references from other objects) and/or `?meta=location` (location information). Defaults to disabled. In addition to these parameters a [filter](12-icinga2-api.md#icinga2-api-filters) may be provided. @@ -663,7 +663,7 @@ URL path when querying a single object: $ curl -k -s -u root:icinga 'https://localhost:5665/v1/templates/hosts/generic-host' -The result set contains the type and name of the template. +The result set contains the type, name as well as the location of the template. ## Variables diff --git a/lib/remote/objectqueryhandler.cpp b/lib/remote/objectqueryhandler.cpp index 06684b156..a33763349 100644 --- a/lib/remote/objectqueryhandler.cpp +++ b/lib/remote/objectqueryhandler.cpp @@ -201,6 +201,15 @@ bool ObjectQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& re refInfo->Set("name", configObj->GetName()); used_by->Add(refInfo); } + } else if (meta == "location") { + DebugInfo di = obj->GetDebugInfo(); + Dictionary::Ptr dinfo = new Dictionary(); + dinfo->Set("path", di.Path); + dinfo->Set("first_line", di.FirstLine); + dinfo->Set("first_column", di.FirstColumn); + dinfo->Set("last_line", di.LastLine); + dinfo->Set("last_column", di.LastColumn); + metaAttrs->Set("location", dinfo); } else { HttpUtility::SendJsonError(response, 400, "Invalid field specified for meta: " + meta); return true; diff --git a/lib/remote/templatequeryhandler.cpp b/lib/remote/templatequeryhandler.cpp index 0645cf4ae..83d518674 100644 --- a/lib/remote/templatequeryhandler.cpp +++ b/lib/remote/templatequeryhandler.cpp @@ -41,6 +41,16 @@ public: Dictionary::Ptr target = new Dictionary(); target->Set("name", item->GetName()); target->Set("type", item->GetType()); + + DebugInfo di = item->GetDebugInfo(); + Dictionary::Ptr dinfo = new Dictionary(); + dinfo->Set("path", di.Path); + dinfo->Set("first_line", di.FirstLine); + dinfo->Set("first_column", di.FirstColumn); + dinfo->Set("last_line", di.LastLine); + dinfo->Set("last_column", di.LastColumn); + target->Set("location", dinfo); + return target; } -- 2.40.0