Skip to content

Commit

Permalink
Provide location information for objects and templates in the API
Browse files Browse the repository at this point in the history
fixes #12566
  • Loading branch information
gunnarbeutner committed Aug 27, 2016
1 parent eafe4c5 commit 602643b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions doc/12-icinga2-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions lib/remote/objectqueryhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions lib/remote/templatequeryhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ class TemplateTargetProvider : public TargetProvider
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;
}

Expand Down

0 comments on commit 602643b

Please sign in to comment.