Nagios API

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
deek
Posts: 194
Joined: Fri Apr 26, 2019 2:01 am

Nagios API

Post 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 .
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Nagios API

Post 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"
Be sure to check out our Knowledgebase for helpful articles and solutions!
deek
Posts: 194
Joined: Fri Apr 26, 2019 2:01 am

Re: Nagios API

Post by deek »

Thanks for that .

And just a curious question . Is there a way to remove a service using the object id ?
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Nagios API

Post 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!
Be sure to check out our Knowledgebase for helpful articles and solutions!
deek
Posts: 194
Joined: Fri Apr 26, 2019 2:01 am

Re: Nagios API

Post by deek »

Thanks for the help :)
You can close the ticket .
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Nagios API

Post by lmiltchev »

I am glad I could help!
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked