Provide location information for objects and templates in the API

fixes #12566
This commit is contained in:
Gunnar Beutner 2016-08-27 19:25:38 +02:00
parent eafe4c578d
commit 602643b93d
3 changed files with 21 additions and 2 deletions

View File

@ -387,7 +387,7 @@ The following URL parameters are available:
-----------|--------------|---------------------------- -----------|--------------|----------------------------
attrs | string array | **Optional.** Limits attributes in the output. 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`). 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. 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' $ 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 ## <a id="icinga2-api-variables"></a> Variables

View File

@ -201,6 +201,15 @@ bool ObjectQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& re
refInfo->Set("name", configObj->GetName()); refInfo->Set("name", configObj->GetName());
used_by->Add(refInfo); 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 { } else {
HttpUtility::SendJsonError(response, 400, "Invalid field specified for meta: " + meta); HttpUtility::SendJsonError(response, 400, "Invalid field specified for meta: " + meta);
return true; return true;

View File

@ -41,6 +41,16 @@ public:
Dictionary::Ptr target = new Dictionary(); Dictionary::Ptr target = new Dictionary();
target->Set("name", item->GetName()); target->Set("name", item->GetName());
target->Set("type", item->GetType()); 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; return target;
} }