Nagios XI rest API for adding services

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
parthiv39731
Posts: 8
Joined: Mon Dec 28, 2015 1:14 pm

Nagios XI rest API for adding services

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

Re: Nagios XI rest API for adding services

Post 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.
Be sure to check out our Knowledgebase for helpful articles and solutions!
jomann
Development Lead
Posts: 611
Joined: Mon Apr 22, 2013 10:06 am
Location: Nagios Enterprises

Re: Nagios XI rest API for adding services

Post 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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
parthiv39731
Posts: 8
Joined: Mon Dec 28, 2015 1:14 pm

Re: Nagios XI rest API for adding services

Post 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.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Nagios XI rest API for adding services

Post 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.
Former Nagios Employee
parthiv39731
Posts: 8
Joined: Mon Dec 28, 2015 1:14 pm

Re: Nagios XI rest API for adding services

Post by parthiv39731 »

we are using Nagios XI 5.2.1.

got the URLs!! thanks :D
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Nagios XI rest API for adding services

Post 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.
Former Nagios Employee
Locked