[icinga-checkins] icinga.org: icinga2/support/2.5: Provide location information for objects and templates in the API

git at icinga.org git at icinga.org
Mon Aug 29 12:22:52 CEST 2016


Module: icinga2
Branch: support/2.5
Commit: 132ecfccc5230fb4d35c140bfd33cbd9e9f21982
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=132ecfccc5230fb4d35c140bfd33cbd9e9f21982

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Sat Aug 27 19:25:38 2016 +0200

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 9f18a2d..0ed18f2 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.
 
 ## <a id="icinga2-api-variables"></a> Variables
 
diff --git a/lib/remote/objectqueryhandler.cpp b/lib/remote/objectqueryhandler.cpp
index 85a7c75..19b160b 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 0494b21..7e95218 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;
 	}
 



More information about the icinga-checkins mailing list