]> granicus.if.org Git - icinga2/commitdiff
Provide location information for objects and templates in the API
authorGunnar Beutner <gunnar.beutner@netways.de>
Sat, 27 Aug 2016 17:25:38 +0000 (19:25 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Sat, 27 Aug 2016 17:25:38 +0000 (19:25 +0200)
fixes #12566

doc/12-icinga2-api.md
lib/remote/objectqueryhandler.cpp
lib/remote/templatequeryhandler.cpp

index 9f18a2d8faf25cc8a611d58a2a3be313f95720be..0ed18f25e22b2e030c1dfa05ecb6d8a21c6cd7c4 100644 (file)
@@ -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
 
index 06684b156d51031a6988a7ea93b08c8984084423..a337633490fc36e63adf68afd6c13d2baeffb2c4 100644 (file)
@@ -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;
index 0645cf4ae885a2d265c59673d572fcad021b0185..83d518674f73e0378f98250501f2c751f8f266c0 100644 (file)
@@ -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;
        }