Page 1 of 1

Get Downtime ID For Specific Service

Posted: Fri Jan 22, 2021 2:00 pm
by jh129666
I can use the below command to get a list of downtime ids for a specific host, but how do I get the downtime id for a specific service on a host?


curl -XGET 'http://xxxxxx:xxxxx@<nagios server>/nagios/cgi-bin/statusjson.cgi?query=downtimelist&formatoptions=whitespace&hostname=<hostname>&downtimeobjecttypes=service&downtimetimefield=starttime' -o down-id-list

Re: Get Downtime ID For Specific Service

Posted: Fri Jan 22, 2021 5:13 pm
by benjaminsmith
Hi,

One way to go about this is to use the REST API GET objects/downtime endpoint and just loop through to find the id for the service.

For example (change the ipaddress and apikey accordingly)

Code: Select all

import requests
import json

ipaddress = '192.168.23.113'

apikey = 'sCWXTQ3rHtm483AgRUUtLi04v5ECCVmktCCGoU8mINpPPflWafJbRKeGO8fGjUh6'

data = requests.get("http://" + ipaddress + "/nagiosxi/api/v1/objects/downtime?apikey=" + apikey )

objects = json.loads(data.text)

def get_internal_downtime_id(hostname, service):
    for item in objects['scheduleddowntime']:
        if item['host_name'] == hostname and item['service_description']== service:
            return item['internal_id']

print(get_internal_downtime_id('localhost', 'Current Load'))
Let me know if that would work for you.