Page 1 of 1

Nagios Xi API create Service Reference

Posted: Mon Jan 30, 2017 4:29 am
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

Re: Nagios Xi API create Service Reference

Posted: Mon Jan 30, 2017 11:44 am
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.

Re: Nagios Xi API create Service Reference

Posted: Wed Feb 01, 2017 12:09 am
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..

Re: Nagios Xi API create Service Reference

Posted: Wed Feb 01, 2017 10:46 am
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.

Re: Nagios Xi API create Service Reference

Posted: Wed Feb 01, 2017 11:44 pm
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.

Re: Nagios Xi API create Service Reference

Posted: Thu Feb 02, 2017 10:40 am
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$

Re: Nagios Xi API create Service Reference

Posted: Thu Feb 02, 2017 10:42 pm
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.

Re: Nagios Xi API create Service Reference

Posted: Fri Feb 03, 2017 10:40 am
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?

Re: Nagios Xi API create Service Reference

Posted: Fri Feb 03, 2017 12:00 pm
by thisara
I looked to mark this as resolved. But I couldn't Please mark it resolved if you can..