How to filter Services by the host_name?

I try to filter services by the hostname - but I do not get it…

curl -k -s -u api:api -X GET -H 'Accept: application/json' 'https://localhost:5665/v1/objects/services' -d '{ "attrs": ["host_name"] }'

I have services of host Ch1 - they show up if if query ALL services without a filter.

...
{
      "attrs": {
        "host_name": "Ch1"
      },
      "joins": {},
      "meta": {},
      "name": "Ch1!load",
      "type": "Service"
    },
    {
      "attrs": {

        "host_name": "Ch1"
      },
      "joins": {},
      "meta": {},
      "name": "Ch1!ssh",
      "type": "Service"
    }
...

But I do not get them if I try to query them.

curl -k -s -u api:api -H 'Accept: application/json' 'https://localhost:5665/v1/objects/services' -d '{ "filter": "service.host_name==Ch1"}'

Also tried by URL-parameters.

curl -k -s -u api:api -H 'Accept: application/json' 'https://localhost:5665/v1/objects/services?filter=service.host_name==Ch1'| jq

Result is in both cases HTTP-404/No objects found.

Any idea what I am doing wrong? Thanks!

Icinga 2.12.3 on Debian 11

that is not the right filter syntax, try that:

curl -k -s -S -i -u root:password -H 'Accept: application/json' -H 'X-HTTP-Method-Override: GET'  'https://localhost:5665/v1/objects/services' -d '{ "type": "Service", "filter": "host.name==\"YOURHOSTNAME\"" }' 
1 Like

Thanks, it does work.
But how should I know that with “host.name”.

I am not sure that is desribed in that way in
https://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#advanced-filters

Sadly this example is not in the docs but other examples use the host.name.

1 Like