REST API compound filter

I have been trying to get a list of unacknowleged critical status hosts with curl but for the life of me I can only get one or the other (critical hosts or unackloweged hosts not in critical) . I’ve tried multiple variations of the URL below.

curl -k -s -S -i -u user:pass ‘https://server:5665/v1/objects/hosts?filter=host.state==1&+host.acknowledgement==0&attrs=name&attrs=state&attrs=last_check_result&pretty=1

I’d prefer not to have to build the query as JSON but I couldn’t find a working example of how to chain the filter like you can do in the web interface.
Can you do that this type of query with plain curl GET?

Did you try to build the query in the web interface and use the resulting URL as a base for your curl call?

I did, the URL is:
icingaweb2/monitoring/list/hosts?host_state=1&host_acknowledged=0&modifyFilter=1

Which is what I tried somehow to recreate using REST API but as I said cannot get the two conditions in the filter to apply at the same time

here you go…

curl -k -s -S -i -u 'root:pass' -H 'Accept: application/json' \
 -H 'X-HTTP-Method-Override: GET' -X POST \
 'https://localhost:5665/v1/objects/hosts' \
 -d '{ "filter": "host.state==1 && host.acknowledgement==0"}'

Does it work with URL encoding the ampersands?

But for readability I would prefer the JSON filter that @moreamazingnick posted.

Thanks @moreamazingnick this seems to work and I already employed way too much time trying a “plain” cURL request with different approaches so I’ll go with yours and move forward.

2 Likes