Page 1 of 1

Nagios XI REST API questions

Posted: Mon Mar 14, 2016 11:32 am
by highness
Got a couple of questions that I'm sure someone has solved before (so I don't have to re-invent).

We currently have an AWS account where we spin up and burn down tens of VMs every day. Most of the new hosts need to be added to Nagios and most of the VMs burned down need to be removed from Nagios. Currently, the way we've been adding the hosts is to bulk host clone and import and removing them is a pain in the a$$ (delete the services, then delete the hosts).

I see in the new version of Nagios, and we've successfully added hosts with the REST API (adding services is just as easy, but adding each service individually sucks too), but is there an EASY way to have all the services removed from the host without having to call the REST API for each and every service on that host?

Re: Nagios XI REST API questions

Posted: Mon Mar 14, 2016 12:51 pm
by lmiltchev
Removing all services from a host in "one go" is not possible via the REST API yet. According to our developers, this functionality could be added later on.
if you had stored the host/service names of items when you added them via the api you could just loop through and delete them all
with a single api command each
For the time being, maybe you can try something like this:

Code: Select all

cat /dev/null > /usr/local/nagios/etc/services/<your config>.cfg
cd /usr/local/nagiosxi/scripts
./reconfigure_nagios.sh
Then you will be left with a host with no services. Did this help?

Re: Nagios XI REST API questions

Posted: Mon Mar 14, 2016 2:07 pm
by highness
Doing it that way may be much faster. I'll have to try that.

Wondering if I could do that in conjunction with removing the server (and setting applyconfig=1) without having to reconfigure nagios first.

Re: Nagios XI REST API questions

Posted: Tue Mar 15, 2016 8:31 am
by krobertson71
We just started wrapping all the api curl call in a bash script. Of course this is just for our baseline setup. Any other added checks would have to be removed separately.

Re: Nagios XI REST API questions

Posted: Tue Mar 15, 2016 9:16 am
by lmiltchev
I have to take my previous post back. I forgot to include a command to move the config from "services" to the "import" directory. In any case, this wouldn't work... I played with this a bit, and results were discouraging. :(
I suppose you will need to delete one service at a time or create some kind of custom script that will loop through all of the services.

Re: Nagios XI REST API questions

Posted: Tue Mar 15, 2016 9:21 am
by highness
lmiltchev wrote:I have to take my previous post back. I forgot to include a command to move the config from "services" to the "import" directory. In any case, this wouldn't work... I played with this a bit, and results were discouraging. :(
I suppose you will need to delete one service at a time or create some kind of custom script that will loop through all of the services.
Ergh... It just shouldn't be this painful.

Do you know if anyone is working to add this to the REST API stack?

Re: Nagios XI REST API questions

Posted: Tue Mar 15, 2016 10:39 am
by lmiltchev
I filed an internal feature request (TASK ID 8020) for adding this functionality. Thank you!

Re: Nagios XI REST API questions

Posted: Tue Mar 15, 2016 2:39 pm
by highness
lmiltchev wrote:I filed an internal feature request (TASK ID 8020) for adding this functionality. Thank you!
Thank you VERY much!

Re: Nagios XI REST API questions

Posted: Tue Mar 15, 2016 3:13 pm
by lmiltchev
You are welcome!

highness, I will be locking this topic now. I you want me to unlock it in the future, just PM me. Thanks!