Search code examples
curlcommandcginagiosdowntime

Automate schedule and Cancel downtime in Nagios


I am trying to schedule and cancel downtime in Nagios core 4.x.

I could schedule a downtime for a host using the following cmd:

curl --silent --show-error  --data cmd_typ=55 --data cmd_mod=2 --data host=automichost1  --data "com_data=Updating+application" --data trigger=0 --data "start_time=05-15-2016 19:00:00" --data "end_time=05-15-2016 19:15:00" --data fixed=1 --data btnSubmit=Commit --insecure http://localhost:80/nagios/cgi-bin/cmd.cgi -u "nagiosadmin:XXXXXX"

This cmd does not return the downtime id generated and simply returns a html file.

but to cancel the schedule downtime i need to use following

curl --silent --show-error  --data cmd_typ=78 --data cmd_mod=2 --data down_id=2  --data "com_data=Updating+application" --data btnSubmit=Commit --insecure http://localhost:80/nagios/cgi-bin/cmd.cgi -u "nagiosadmin:xxxxxxx"

Here I need down_id to Cancel a downtime. In an automation script there is no way to get this downtime id from any nagios external command. I also tried the following external command mentioned on http://docs.icinga.org/latest/en/cgiparams.html CMD_DEL_DOWNTIME_BY_HOST_NAME 171

but this is not working on Nagios and gives message "Sorry, but you are not authorized to commit the specified command.".

I am stuck now and cannot move forward. does anyone knows how to acheive this?


Solution

  • Since it is long I did not get an answer to my query, I am posting how I solved it.

    I asked the same question on nagios Customer Forum and got a reply. The JSON Query Generator is super handy for this sort of thing (where x.x.x.x is your Core install):

    x.x.x.x/nagios/jsonquery.html

    A brief intro to the JSON Query Generator:

    labs.nagios.com/2014/06/19/expl ... -7-part-1/

    If you wanted to check if host y.y.y.y has scheduled downtime, you could try the following query (where x.x.x.x is your Core install):

    http://x.x.x.x/nagios/cgi-bin/statusjson.cgi?query=downtimelist&formatoptions=whitespace&hostname=y.y.y.y&downtimeobjecttypes=host&downtimetimefield=starttime

    downtimelist will be empty if there is no downtime scheduled, otherwise it will contain the downtime id for each scheduled downtime for host y.y.y.y.

    Also if you wanted a graphical response, drop the json from the script you are running:

    http://x.x.x.x/nagios/cgi-bin/status.cgi?query=downtimelist&formatoptions=whitespace&hostname=y.y.y.y&downtimeobjecttypes=host&downtimetimefield=starttime