API request with logical operators in filter

I want to use a filter with logical operators comparing variables in attrs.vars of Hosts/Services e.g.

curl -k -s -u username:password -H 'Accept: application/json' -X GET '' -d '{ "type": "Host", "filter": "host.vars.reboot>0" }'

response: { "error": 404.0, "status": "No objects found." }

When I use equals host with 1 reboot are found:

curl -k -s -u username:password -H 'Accept: application/json' -X GET '' -d '{ "type": "Host", "filter": "host.vars.reboot==1" }'

response: [...some hosts where vars.reboot == 0...]

but when I filter for a default variable like state it does function

curl -k -s -u username:password -H 'Accept: application/json' -X GET '' -d '{ "type": "Host", "filter": "host.state>0" }'

response: [...some hosts...]

My current workaround:

curl -k -s -u username:password -H 'Accept: application/json' -X GET '' -d '{ "type": "Host", "filter":"host.vars.reboot!=0 && host.vars.reboot!=null"}'

response: [...correctly filtered hosts ...]

Is it possible that the content of host.vars.reboot is a string instead of a number?

You could try and see what happens if you define the variable as a number type instead of a string type.
In the Icinga Director you could simply change the type of the datafield.

In the config files you would need to write variable = 1 instead of variable = "1", if I am not mistaken.

Tried both string and number.

Have you tried overriding the request method, maybe this will help. But as your other queries are returning results, I doubt it.

Otherwise I suggest opening an issue on github that queries with > (and most likely < as well) do not work properly.

1 Like

GitHub Issue