Page 1 of 1

Nagios API

Posted: Wed Jun 02, 2021 11:22 am
by deek
Hi ,

I was trying to use the API to remove the services for a host . But is there a way to remove all the services associated with the host in one API command using wildcard ( * ) .
I tried in so many ways but looks like wildcard is not working in the API .

Example :
1. curl -XDELETE "https://Nagiosserver.com/nagiosxi/api/v ... lyconfig=1"

2. curl -XDELETE "https://Nagiosserver.com/nagiosxi/api/v ... lyconfig=1"

3. curl -XDELETE "https://Nagiosserver.com/nagiosxi/api/v ... lyconfig=1"

Please let us know what other alternative can be used .

Re: Nagios API

Posted: Wed Jun 02, 2021 3:56 pm
by lmiltchev
Unfortunately, you can't use "*" to delete all of the services attached to a host with one go via the REST API. The only way to do it would be to list them all in your command.

Example:

Code: Select all

curl -XDELETE "https://x.x.x.x/nagiosxi/api/v1/config/service?apikey=xxx&pretty=1&host_name=xxx&service_description[]=service1&service_description[]=service2&service_description[]=service3&applyconfig=1"

Re: Nagios API

Posted: Thu Jun 03, 2021 12:34 am
by deek
Thanks for that .

And just a curious question . Is there a way to remove a service using the object id ?

Re: Nagios API

Posted: Thu Jun 03, 2021 9:18 am
by lmiltchev
I don't see an option to do that in the REST API documentation. However, you could use the "ccm_delete_object.php" script in the "/usr/local/nagiosxi/scripts" directory in order to achieve this.

Example:

Code: Select all

[root@TEST-XI-CentOS-7 scripts]# pwd
/usr/local/nagiosxi/scripts
[root@TEST-XI-CentOS-7 scripts]# ./ccm_delete_object.php -t service -i 1
Successfully removed service from CCM database.
Here's the script's usage (help menu):

Code: Select all

[root@TEST-XI-CentOS-7 scripts]# ./ccm_delete_object.php --help

Deletes an object (or list of objects) from the CCM database.

Usage: ./ccm_delete_host.php [option] ..

Example: Remove all services from service with config name localhost
         ./ccm_delete_host.php -t service -c localhost

Usage Options:
    -t|--type <type>             Object type (host, service, contact, timeperiod)
    -i|--id <object id>          (OPTIONAL) Object ID
\Host Type Options:
    -n|--name <host name>        (OPTIONAL) Host name (host type only)

Service Type Options:
    -c|--config <config name>    (OPTIONAL) Config name to remove all services from (service type only)

Help and Logging:
    -h|--help                    Print out help output
This removes the objects from the database (CCM). Don't forget that you would need to apply configuration, so that changes can be written to flat files. You can just run the "reconfigure_nagios.sh" script from the CLI, located in the scripts directory.

Hope this helps.

Thanks!

Re: Nagios API

Posted: Mon Jul 05, 2021 3:26 am
by deek
Thanks for the help :)
You can close the ticket .

Re: Nagios API

Posted: Tue Jul 06, 2021 1:09 pm
by lmiltchev
I am glad I could help!