...I just want to enable/disable alerts... I want to just do it globally for all services during maintenance/deployments...
I don't believe this can be done via the API. Disabling notifications globally for all hosts and services is easy, but there is no "out of the box" option for disabling notifications for services ONLY.
Having said that, I have a "workaround" for you. You can disable notifications for all services associated with hosts in a particular hostgroup via external command. See this:
https://old.nagios.org/developerinfo/ex ... mand_id=80
https://old.nagios.org/developerinfo/ex ... ndlist.php
So, do the following:
1. Create a host group in the CCM, for example called "all", and add all hosts to it, using the "*" option.
Code: Select all
define hostgroup {
hostgroup_name all
alias All hosts
members *
}
2. Create a simple shell script, for example, called "disable_service_notifications.sh", and place it somewhere on the Nagios XI server.
Code: Select all
#!/bin/sh
now=`date +%s`
commandfile='/usr/local/nagios/var/rw/nagios.cmd'
/usr/bin/printf "[%lu] DISABLE_HOSTGROUP_SVC_NOTIFICATIONS;all\n" $now > $commandfile
3. Make the script executable, and run it from the command line to disable all service notifications:
Code: Select all
chmod +x disable_service_notifications.sh
./disable_service_notifications.sh
I' d like to see an API to create a host and assign a template to it. The same for services.
You can easily add the "use=" directive to a host/service definition while creating the objects via the REST API. The trick is to use the "force=1" option. Also, keep in mind that the configs are not verified for errors. Make sure that you have ALL of the required directives defined in your host/service templates!
Example (adding a host that uses the "xiwizard_generic_host" template):
Code: Select all
curl -XPOST "https://x.x.x.x/nagiosxi/api/v1/config/host?apikey=qiPs26vMelrpfiFWTCroZBmrtbX6LjZcU5XWqsIH7a7mL2CFD3jTTZkmaBLcU0nO&pretty=1" -d "host_name=testapihost&address=127.0.0.1&use=xiwizard_generic_host&force=1&applyconfig=1"
Example (adding a services that uses the "xiwizard_generic_service" template):
Code: Select all
curl -XPOST "https://x.x.x.x/nagiosxi/api/v1/config/service?apikey=qiPs26vMelrpfiFWTCroZBmrtbX6LjZcU5XWqsIH7a7mL2CFD3jTTZkmaBLcU0nO&pretty=1" -d "host_name=testapihost&service_description=testapiservice&use=xiwizard_generic_service&force=1&applyconfig=1"
Let us know if this helped. Thank you!