Disable Service Check via API

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
matson-itops
Posts: 133
Joined: Wed Nov 18, 2015 11:19 pm

Disable Service Check via API

Post by matson-itops »

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?
kyang

Re: Disable Service Check via API

Post by kyang »

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.

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&notification_interval=10&notification_period=24x7&contacts=nagiosadmin&active_checks_enabled=0&applyconfig=1"
Capture.PNG
Is this what you were looking for?

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

Post by matson-itops »

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.
kyang

Re: Disable Service Check via API

Post by kyang »

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.
mopp
Posts: 64
Joined: Thu Aug 20, 2015 7:15 am

Re: Disable Service Check via API

Post by mopp »

kyang wrote:Although there are more API endpoints coming in XI 5.5 which has a release date for Q1 2018.
Can you tell us something about the new API endpoints?
I' d like to see an API to create a host and assign a template to it. The same for services.
User avatar
lmiltchev
Former Nagios Staff
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Disable Service Check via API

Post by lmiltchev »

...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!
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked