Nagios Xi API create Service Reference

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
thisara
Posts: 5
Joined: Tue Sep 27, 2016 8:03 am

Nagios Xi API create Service Reference

Post by thisara »

I'm currently trying to create few services through Nagios Xi API. Although I'm able to get create check ping service as explained in the help Is there a guide which I can refer when creating services. I'm struggling to find the way to pass arguments to check command. For example
check_command=check_ping\!3000,80%\!5000,100% - Create ping service

I need to create following services. Please help..
check_load
check_swap
check_disk
check_mem
check_init_service
check_cpu_stats
Last edited by dwhitfield on Fri Feb 03, 2017 12:06 pm, edited 1 time in total.
Reason: marking with green check mark
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Nagios Xi API create Service Reference

Post by rkennedy »

See the attached document which helps explain the API a bit towards the end. The main focus is on templates / grouping which is really beneficial.

Should you have further questions, refer to the XI home page, and click the 'Help' link - this has examples on how to use the API a lot more thoroughly.
You do not have the required permissions to view the files attached to this post.
Former Nagios Employee
thisara
Posts: 5
Joined: Tue Sep 27, 2016 8:03 am

Re: Nagios Xi API create Service Reference

Post by thisara »

Thank you very much for the response.
I have used the guide in Nagios Xi "Help". That allowed to create me ping service. But I cannot create any other services. Just want to know how can i send parameters to
check_load
check_swap
check_disk
check_mem
check_init_service
check_cpu_stat
Command from an API call.

Thanks..
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Nagios Xi API create Service Reference

Post by rkennedy »

It should be pretty similar, by simply replacing the service name and command name. Please post the current API call you're using to create ping. From there, it's just substituting out what the service name / check command / arguments are equal to.
Former Nagios Employee
thisara
Posts: 5
Joined: Tue Sep 27, 2016 8:03 am

Re: Nagios Xi API create Service Reference

Post by thisara »

I have tried it as you explained. But it didn't work. That's why I decided to take help from you experts.
This is what I have used to create ping service
curl -XPOST "http://myhostname/nagiosxi/api/v1/confi ... v&pretty=1" -d "host_name=testapihostapply&service_description=PING&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"

For Load I have tried:
curl -XPOST "http://myhostname/nagiosxi/api/v1/confi ... c&pretty=1" -d "host_name=testapihostapply&service_description=CPU_Load&check_command=check_load\!15,10,5\!30,20,10&check_interval=5&retry_interval=5&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&applyconfig=1"

Though it says server successfully created, In CCM Apply configuration Fails. I think the problem is how I provide parameters to check command. Please help me if you know a proper way to do this.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Nagios Xi API create Service Reference

Post by rkennedy »

When you attempt to apply, what error is shown?

I'm noticing two things in your API calls. A different API key each time, and you're using check_load. On my stock XI system, I don't have a command defined for check_load. I do however, have one defined for check_local_load which would use the same parameters you're after. Does it work if you use check_local_load?

Code: Select all

check_local_load	$USER1$/check_load -w $ARG1$ -c $ARG2$
Former Nagios Employee
thisara
Posts: 5
Joined: Tue Sep 27, 2016 8:03 am

Re: Nagios Xi API create Service Reference

Post by thisara »

Thank you very much @rkennedy,
Your suggestion allowed me to find the correct solution for my issue.
Yes, as you suggest check_local_load did worked. But It allowed me to find others as well. Since this would help of for the some other people in the future I will post the solution.

To create check_load service via Nagios Xi API use the bellow parameters for argument check_command=
check_nrpe\!check_load\!-a '-w 1,0.5,0.2 -c 30,20,10'

Full example:

Code: Select all

curl -XPOST "http://myhostname/nagiosxi/api/v1/config/service?apikey=myapiKey&pretty=1" -d "host_name=mytesthostname&service_description=API_CPU_Load&check_command=check_nrpe\!check_load\!-a '-w 1,0.5,0.2 -c 30,20,10'&check_interval=5&retry_interval=5&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&applyconfig=1"
This way I was able to create the service. I will post arguments for check_command to create few other services:

Code: Select all

Memory Usage:- check_nrpe\!check_mem\!-a '-w 20 -c 10'
SwapUsage:- check_nrpe\!check_swap\!-a '-w 50 -c 20'
Init Service:- check_nrpe\!check_init_service\!-a 'sshd'
I hope this will help some other who uses Nagios API.

Again thank you very much rkennedy for the suggestion you gave. I really appreciate it.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Nagios Xi API create Service Reference

Post by rkennedy »

No problem - glad to hear you got it working and ran with it! :D

Are we good to mark this thread resolved, or do you have further questions?
Former Nagios Employee
thisara
Posts: 5
Joined: Tue Sep 27, 2016 8:03 am

Re: Nagios Xi API create Service Reference

Post by thisara »

I looked to mark this as resolved. But I couldn't Please mark it resolved if you can..
Locked