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 .
Nagios API
Re: Nagios API
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:
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!
Re: Nagios API
Thanks for that .
And just a curious question . Is there a way to remove a service using the object id ?
And just a curious question . Is there a way to remove a service using the object id ?
Re: Nagios API
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:
Here's the script's usage (help menu):
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!
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.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 outputHope this helps.
Thanks!
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: Nagios API
Thanks for the help 
You can close the ticket .
You can close the ticket .
Re: Nagios API
I am glad I could help!
Be sure to check out our Knowledgebase for helpful articles and solutions!