How to find out, which service is down more than XX days

Hi guys,

icinga2 - The Icinga 2 network monitoring daemon (version: r2.13.1-1)
System information:
Platform: Debian GNU/Linux
Platform version: 9 (stretch)
Kernel: Linux
Kernel version: 4.9.0-12-amd64
Architecture: x86_64

I have a question. Which query I can use to find out (could be via API), which services do I have which are down more than XX days.
I tried a lot but failed always :slight_smile:

Kind regards
Peer-Mario

Please write down what you tried, that helps to narrow it down

Get the timestamp of your cutoff and replace 1682028009 with yours.

https://icinga.example.com/icingaweb2/monitoring/list/services?service_problem=1&service_last_state_change<1682028009&sort=service_last_state_change&modifyFilter=1

Hi,

thank you so much for your answer, the URL works like expected (with username/login).

Is there any change to do this with an API call as well?

Like:

url = ‘https://MyIcingaHost:5665/v1/services
params = {
‘service_problem’: ‘1’,
‘service_last_state_change’: ‘<1682028009’,
‘sort’: ‘service_last_state_change’,
‘modifyFilter’: ‘1’
}

I get always URL does not exists so the URL for the API call behin /v1/services is wrong.

Regards
Peer-Mario

The data structure in your example isn’t what the Icinga2 REST API requires.
modifyFilter for example is a switch that has no meaning in Icinga2, only in Icingaweb2 and all the search parameters need to be in the filter replacing "match(\"ping*\", service.name)":

request_url = "https://localhost:5665/v1/objects/services"
headers = {
        'Accept': 'application/json',
        'X-HTTP-Method-Override': 'GET'
        }
data = {
        "attrs": [ "name", "state", "last_check_result" ],
        "joins": [ "host.name", "host.state", "host.last_check_result" ],
        "filter": "match(\"ping*\", service.name)",
}

Have a look at the code examples in the documentation: Icinga2 Api - Icinga 2

1 Like