How do I use the Nagios 5 api's to disable service checks?
All docs so far are for actually deleting the host or service.
will simply using "DISABLE" and "ENABLE" work?
Disable Service Check via API
-
kyang
Re: Disable Service Check via API
Are you disabling active checks? correct?
It's long, but after recreating the same service I have using the correct host_name and description etc etc..
I added &active_checks_enabled=0 before the &applyconfig=1, and it disabled off my active check for that service.
Is this what you were looking for?
I don't think it will work for service_groups though if that is what you wanted.
It's long, but after recreating the same service I have using the correct host_name and description etc etc..
I added &active_checks_enabled=0 before the &applyconfig=1, and it disabled off my active check for that service.
Code: Select all
curl -XPOST "http://192.168.4.125/nagiosxi/api/v1/config/service?apikey=t0bMmNo0qFu70qFZO93e8sSIqREI82WV2nHna5oTZc0gWFgK4ier47qOe4smlohm&pretty=1" -d "host_name=192.168.4.125&service_description=httpd&&max_check_attempts=5&check_interval=5&retry_interval=5&check_period=24x7¬ification_interval=10¬ification_period=24x7&contacts=nagiosadmin&active_checks_enabled=0&applyconfig=1"
I don't think it will work for service_groups though if that is what you wanted.
You do not have the required permissions to view the files attached to this post.
-
matson-itops
- Posts: 133
- Joined: Wed Nov 18, 2015 11:19 pm
Re: Disable Service Check via API
thanks so much KYANG . I managed to get that far
I was hoping to avoid re-creating the service painstakingly when I just want to enable/disable alerts. I'd have to check all the parameters, and I want to just do it globally for all services during maintenance/deployments.
I was hoping to avoid re-creating the service painstakingly when I just want to enable/disable alerts. I'd have to check all the parameters, and I want to just do it globally for all services during maintenance/deployments.
-
kyang
Re: Disable Service Check via API
No problem,
I think as of now there is no way to actually do this.
Although there are more API endpoints coming in XI 5.5 which has a release date for Q1 2018.
https://www.nagios.com/roadmaps/
Otherwise, using the Bulk Modifications Tool is probably the easiest way for now all services globally.
Using the same active checks enabled option and set it to off and select services.
I think as of now there is no way to actually do this.
Although there are more API endpoints coming in XI 5.5 which has a release date for Q1 2018.
https://www.nagios.com/roadmaps/
Otherwise, using the Bulk Modifications Tool is probably the easiest way for now all services globally.
Using the same active checks enabled option and set it to off and select services.
Re: Disable Service Check via API
Can you tell us something about the new API endpoints?kyang wrote:Although there are more API endpoints coming in XI 5.5 which has a release date for Q1 2018.
I' d like to see an API to create a host and assign a template to it. The same for services.
Re: Disable Service Check via API
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....I just want to enable/disable alerts... I want to just do it globally for all services during maintenance/deployments...
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 *
}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 > $commandfileCode: Select all
chmod +x disable_service_notifications.sh
./disable_service_notifications.shYou 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!I' d like to see an API to create a host and assign a template to it. The same for services.
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"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"Be sure to check out our Knowledgebase for helpful articles and solutions!