REST API is not having command end point.

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
pmishra
Posts: 6
Joined: Wed Oct 21, 2015 5:39 am

REST API is not having command end point.

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

Re: REST API is not having command end point.

Post 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&notification_interval=5&notification_period=24x7&notifications_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&notification_interval=5&notification_period=24x7&notifications_enabled=1&applyconfig=1"
Be sure to check out our Knowledgebase for helpful articles and solutions!
pmishra
Posts: 6
Joined: Wed Oct 21, 2015 5:39 am

Re: REST API is not having command end point.

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

Re: REST API is not having command end point.

Post 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&notification_interval=5&notification_period=24x7&notifications_enabled=0&applyconfig=1"
Hope this helps.
Be sure to check out our Knowledgebase for helpful articles and solutions!
pmishra
Posts: 6
Joined: Wed Oct 21, 2015 5:39 am

Re: REST API is not having command end point.

Post 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&notification_interval=5&notification_period=24x7&notifications_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,
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: REST API is not having command end point.

Post 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.
Be sure to check out our Knowledgebase for helpful articles and solutions!
pmishra
Posts: 6
Joined: Wed Oct 21, 2015 5:39 am

Re: REST API is not having command end point.

Post 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 ?
You do not have the required permissions to view the files attached to this post.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: REST API is not having command end point.

Post by lmiltchev »

Thanks, pmishra! I forwarded your patch to our developers. We really appreciate your input!
Be sure to check out our Knowledgebase for helpful articles and solutions!
pmishra
Posts: 6
Joined: Wed Oct 21, 2015 5:39 am

Re: REST API is not having command end point.

Post 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
User avatar
hsmith
Agent Smith
Posts: 3539
Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:

Re: REST API is not having command end point.

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