Get Downtime ID For Specific Service

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
jh129666
Posts: 98
Joined: Mon Feb 11, 2013 3:45 pm

Get Downtime ID For Specific Service

Post 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
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: Get Downtime ID For Specific Service

Post 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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked