REST API filter for services or hosts by last_check

I’d like to query the Icinga2 REST API for all services (or hosts) where the last_check time was more than X minutes ago. Is it possible to use service.last_check or host.last_check in the /v1/objects/services or /v1/objects/hosts endpoint?

I’ve tried some variations of the following and get 404s:

/v1/objects/services?filter=service.last_check<“1666203366”
/v1/objects/services?filter=service.last_check<1666203366

If this is not possible with the REST API, could it be done with the CLI?

The Icinga Web UI has the ability to search for hosts or services by “Last Check” in both the monitoring plugin and the IcingaDB plugin.

  • Icinga DB Web version (System - About): 1.0.1
  • Icinga Web 2 version (System - About): 2.11.1
  • Icinga 2 version (icinga2 --version): r2.13.5-1
  • Icinga DB version (icingadb --version): v1.0.0
  • PHP version used (php --version): 7.3.29 (for icinga web)
  • Server operating system and version: rhel 7.6
1 Like

I’m not sure what I was doing differently before, but this query now works for me.

While specifying the filter in the URL works, the equivalent specified with the filter in the body does not work and results in a 404:

{"filter": "service.last_check<time", "filter_vars": { "time": "1666203366"} }

Hello,

I am having the same question, I would like to ask you if you find a solution

thx

Can you post the output of the service object you’re trying to get without the filter? and also your code for however you’re making the API call (curl/python code/etc)?


I did like that. Is in php.
I can hold all the services with hosts, but just from the current day not for exemple yesterday. Do you know how I could do that?

did you program with CLI? how you did?

Filtering inside the body didn’t work for me either. It works when specifying the filter in the URI.

Example:

https://server:port/v1/objects/services?filter=service.last_check<1668028092

I tried that but it does not work.
I think the only solutions is hold the data direct from the database

So you’re trying to get all services where the last_check was more than 1 day ago?

https://server:port/v1/objects/services?filter=service.last_check<1668703215

Like the above where 1668703215 is 24 hours ago?