Instead of using a filter you can optionally specify the object name in the
URL path when querying a single object. For objects with composite names
-(e.g. services) the full name (e.g. `localhost!http`) must be specified:
+(e.g. services) the full name (e.g. `example.localdomain!http`) must be specified:
- $ curl -k -s -u root:icinga 'https://localhost:5665/v1/objects/services/localhost!http'
+ $ curl -k -s -u root:icinga 'https://localhost:5665/v1/objects/services/example.localdomain!http'
You can limit the output to specific attributes using the `attrs` URL parameter:
attrs | dictionary | **Required.** Set specific object attributes for this [object type](9-object-types.md#object-types).
The object name must be specified as part of the URL path. For objects with composite names (e.g. services)
-the full name (e.g. `localhost!http`) must be specified.
+the full name (e.g. `example.localdomain!http`) must be specified.
If attributes are of the Dictionary type, you can also use the indexer format. This might be necessary to only override specific custom variables and keep all other existing custom variables (e.g. from templates):
Service objects must be created using their full name ("hostname!servicename") referencing an existing host object:
- $ curl -k -s -u root:icinga -H 'Accept: application/json' -X PUT 'https://localhost:5665/v1/objects/services/localhost!realtime-load' \
+ $ curl -k -s -u root:icinga -H 'Accept: application/json' -X PUT 'https://localhost:5665/v1/objects/services/example.localdomain!realtime-load' \
-d '{ "templates": [ "generic-service" ], "attrs": { "check_command": "load", "check_interval": 1,"retry_interval": 1 } }'
"results": [
{
"code": 200.0,
- "status": "Successfully rescheduled check for object 'localhost!ping6'."
+ "status": "Successfully rescheduled check for object 'example.localdomain!ping6'."
}
]
}
to fetch the checkable object, its check result and the executed shell command.
* Alternatively enable the [debug log](15-troubleshooting.md#troubleshooting-enable-debug-output) and look for the executed command.
+Example for a service object query using a [regex match]() on the name:
+
+ $ curl -k -s -u root:icinga -H 'Accept: application/json' -H 'X-HTTP-Method-Override: GET' -X POST 'https://localhost:5665/v1/objects/services' \
+ -d '{ "filter": "regex(pattern, service.name)", "filter_vars": { "pattern": "^http" }, "attrs": [ "__name", "last_check_result" ] }' | python -m json.tool
+ {
+ "results": [
+ {
+ "attrs": {
+ "__name": "example.localdomain!http",
+ "last_check_result": {
+ "active": true,
+ "check_source": "example.localdomain",
+ "command": [
+ "/usr/local/sbin/check_http",
+ "-I",
+ "127.0.0.1",
+ "-u",
+ "/"
+ ],
+
+ ...
+
+ }
+ },
+ "joins": {},
+ "meta": {},
+ "name": "example.localdomain!http",
+ "type": "Service"
+ }
+ ]
+ }
+
+Example for using the `icinga2 console` CLI command evaluation functionality:
+
+ $ ICINGA2_API_PASSWORD=icinga icinga2 console --connect 'https://root@localhost:5665/' \
+ --eval 'get_service("example.localdomain", "http").last_check_result.command' | python -m json.tool
+ [
+ "/usr/local/sbin/check_http",
+ "-I",
+ "127.0.0.1",
+ "-u",
+ "/"
+ ]
+
+Example for searching the debug log:
+
+ # icinga2 feature enable debuglog
+ # systemctl restart icinga2
+ # tail -f /var/log/icinga2/debug.log | grep "notice/Process"
+
+
### <a id="checks-not-executed"></a> Checks are not executed
* Check the [debug log](15-troubleshooting.md#troubleshooting-enable-debug-output) to see if the check command gets executed.