Page 1 of 2
REST API is not having command end point.
Posted: Wed Oct 21, 2015 2:18 pm
by pmishra
Am looking into the REST API implementation and it seems endpoint for running nagios command was not present or missing for e.g. disable/enable service or host notification, adding comment etc.
is it something planed for future release or the endpoints are not exposed due to some reason ?
Thanks,
Pradeep
Re: REST API is not having command end point.
Posted: Thu Oct 22, 2015 1:31 pm
by lmiltchev
You should be able to enable/disable notifications via a REST API command, for example:
Code: Select all
curl -XPOST "http://192.168.x.x/nagiosxi/api/v1/config/host?apikey=lfhpn9vu&pretty=1" -d "host_name=localhost&address=127.0.0.1&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin¬ification_interval=5¬ification_period=24x7¬ifications_enabled=0&applyconfig=1"
The command above should disable notifications on localhost. You can re-enable them by running:
Code: Select all
curl -XPOST "http://192.168.x.x/nagiosxi/api/v1/config/host?apikey=lfhpn9vu&pretty=1" -d "host_name=localhost&address=127.0.0.1&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin¬ification_interval=5¬ification_period=24x7¬ifications_enabled=1&applyconfig=1"
Re: REST API is not having command end point.
Posted: Thu Oct 22, 2015 3:43 pm
by pmishra
Hi,
Thanks for the response, but the POST request you have mention will disable and enable notification of all service under host. Sometime we need to disable notification of single service under particular host e.g. http or ntp etc.
So is there any plan to support the above ? am looking something like below
Enable:-
curl -XPOST "
http://192.168.x.x/nagiosxi/api/v1/obje ... u&pretty=1" -d "host_name=node01&service_name=http&action=enable&comment=Site Update"
Disable:-
curl -XPOST "
http://192.168.x.x/nagiosxi/api/v1/obje ... u&pretty=1" -d "host_name=node01&service_name=http&action=disable&comment=Site Update"
Thanks,
-Pradeep
Re: REST API is not having command end point.
Posted: Thu Oct 22, 2015 4:07 pm
by lmiltchev
Thanks for the response, but the POST request you have mention will disable and enable notification of all service under host.
This is not true. The example command I showed you will disable notifications on localhost only. This will not affect any of the services.
Sometime we need to disable notification of single service under particular host e.g. http or ntp etc.
Here's another example, showing how to disable notifications on the HTTP service on localhost:
Code: Select all
curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/config/service?apikey=lfhpn9vu&pretty=1" -d "host_name=localhost&service_description=HTTP&check_command=check_http&check_interval=5&retry_interval=1&max_check_attempts=4&check_period=24x7&contacts=nagiosadmin¬ification_interval=5¬ification_period=24x7¬ifications_enabled=0&applyconfig=1"
Hope this helps.
Re: REST API is not having command end point.
Posted: Thu Oct 22, 2015 6:00 pm
by pmishra
Thanks for the response, but the POST request you have mention will disable and enable notification of all service under host.
Sorry am not clear enough in my pervious response, what i meant was it will disable all notification of localhost.
Code: Select all
curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/config/service?apikey=lfhpn9vu&pretty=1" -d "host_name=localhost&service_description=HTTP&check_command=check_http&check_interval=5&retry_interval=1&max_check_attempts=4&check_period=24x7&contacts=nagiosadmin¬ification_interval=5¬ification_period=24x7¬ifications_enabled=0&applyconfig=1"
I think we are trying recreate the particular e.g HTTP service every time we want to disable or enable with only one value change
notifications_enabled=0 | 1
. Please correct me if am wrong.
Thanks,
Re: REST API is not having command end point.
Posted: Fri Oct 23, 2015 11:26 am
by lmiltchev
I think we are trying recreate the particular e.g HTTP service every time we want to disable or enable with only one value change
You are correct. The "curl -XPOST" is used for adding objects. The "curl -XDELETE" is used for deleting objects.
Backend API - Config Reference
With the new API in Nagios XI 5 we linked it up directly with the Core Config Manager. This allows creation and deletion of items directly from the API. This API section is admin only.
So in order to "modify" an object, you basically will need to "recreate" it. Simply modifying objects via the REST API is not available at this time as far as I know but it may be added in the future.
Re: REST API is not having command end point.
Posted: Fri Oct 23, 2015 11:50 am
by pmishra
Thanks for the response. I have applied a patch on "utils-api.inc.php" to expose only disable and enable service notification with comment support.
Example:-
Code: Select all
curl -XPOST "http://192.168.x.x/nagiosxi/api/v1/objects/alert?apikey=evk5jn6r6ehmgf" -d "host_name=node01&service_name=HTTP&action=enable&comment=Enable\ service\ notification"
Code: Select all
curl -XPOST "http://192.168.x.x/nagiosxi/api/v1/objects/alert?apikey=evk5jn6r6ehmgf" -d "host_name=node01&service_name=HTTP&action=disable&comment=Disable\ service\ notification"
Please review the patch attached and let me know if you can make it officially release ?
Re: REST API is not having command end point.
Posted: Fri Oct 23, 2015 12:29 pm
by lmiltchev
Thanks, pmishra! I forwarded your patch to our developers. We really appreciate your input!
Re: REST API is not having command end point.
Posted: Fri Oct 23, 2015 1:19 pm
by pmishra
You welcome, am looking forward to hear from you and developer team.
Do let me know if you or the team need any fix or found any issue on the current patch.
Thanks,
Pradeep
Re: REST API is not having command end point.
Posted: Fri Oct 23, 2015 1:58 pm
by hsmith
I'll leave the thread open for discussion, but I do have to ask that it not gets bumped unless an issue is found. We use a dashboard system here to make sure SLA is being met, and when things that are "resolved" get bumped up, it make it look like there is still an issue.
Thank you again for your contribution! We appreciate our community more than I can express.
