Page 1 of 1

Nagios XI rest API for adding services

Posted: Thu Dec 31, 2015 5:09 am
by parthiv39731
Is there any Rest API to add multiple services to a host in one call.

I could get the following API which adds services one by one -
https://192.168.18.151/nagios/nagiosxi/ ... iption=CPU Usage&use=xiwizard_linuxserver_nsclient_service&check_command=check_nrpe!!CPULOAD!-l 5,80,90

the above API if called one by one without any delay in between two register multiple services causes the last service to be removed from the host. Seems after the rest API is called, there is some delay in adding the services to the host and if before this some one tries to add one more service to it, the last service is removed.

currently to handle this I am putting a thread.sleep in my code in between multiple calls. This is not fail safe hence want to know a proper solution to this.

Re: Nagios XI rest API for adding services

Posted: Mon Jan 04, 2016 1:58 pm
by lmiltchev
Currently this functionality is not available in XI, but it is on our developers' TODO list. The only way to add multiple services to the same host via the REST API would be to "chain" all of the commands together with a semicolon (";"), i.e.

Code: Select all

curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/config/service?apikey=pcfe5o3u&pretty=1" -d "host_name=TESTAPI&service_description=service1&check_command=check_ping\!3000,80%\!5000,100%&check_interval=5&retry_interval=5&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7";curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/config/service?apikey=pcfe5o3u&pretty=1" -d "host_name=TESTAPI&service_description=service2&check_command=check_ping\!3000,80%\!5000,100%&check_interval=5&retry_interval=5&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7";curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/config/service?apikey=pcfe5o3u&pretty=1" -d "host_name=TESTAPI&service_description=service3&check_command=check_ping\!3000,80%\!5000,100%&check_interval=5&retry_interval=5&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&applyconfig=1"
As you can see, I am adding three services (service1, service2, and service3) to one host (TESTAPI). All curl commands are separated by a ";". I added the "&applyconfig=1" to the last command only. This worked for me well. I tried adding 10 services at a time and I didn't have any issues. However, it is possible that on a very busy system, there are going to be issues. So, putting the commands in a bash script with some delay in between the commands should be the only "workaround" for the time being.

Re: Nagios XI rest API for adding services

Posted: Mon Jan 04, 2016 2:34 pm
by jomann
Also please make sure that you're running the latest version of Nagios XI since there was, a while ago, an issue with adding multiple services one after another.

Re: Nagios XI rest API for adding services

Posted: Tue Jan 05, 2016 1:28 am
by parthiv39731
thanks Jonam. I would try the suggestion. To be absolutely sure that all the services have been subscribed at the end do we have any API which would return all the services for a host? This way we can raise an exception if the services are not subscribed and take necessary action on it in our program.

Re: Nagios XI rest API for adding services

Posted: Tue Jan 05, 2016 11:25 am
by rkennedy
What version of XI are you currently using?

You should be able to navigate to Admin -> Manage Components -> Look for the Backend API URL section and click the icon that represents 'Edit Settings' -> Select the user to generate the links for.

From there, you'll see links to XML that has the raw data for your hosts / services.

Re: Nagios XI rest API for adding services

Posted: Wed Jan 06, 2016 6:45 am
by parthiv39731
we are using Nagios XI 5.2.1.

got the URLs!! thanks :D

Re: Nagios XI rest API for adding services

Posted: Wed Jan 06, 2016 10:01 am
by rkennedy
You're welcome. As this is resolved, I'll go ahead and close this thread out.

Feel free to open a new thread if you ever need assistance in the future.