Set Acknowledgement via API

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Envera IT
Posts: 159
Joined: Wed Jun 19, 2013 10:21 am

Set Acknowledgement via API

Post by Envera IT »

Is it possible to use the REST API to set acknowledgements on a host or service?
Last edited by dwhitfield on Thu Jul 27, 2017 9:13 am, edited 1 time in total.
Reason: marking with green check mark
I like graphs...
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: Set Acknowledgement via API

Post by dwhitfield »

Not right now, but the developers have said it is in the roadmap for the future. It can be done via cmd.cgi. This is ***not*** for acknowledgements, but the syntax would be something like the following:
curl -d "cmd_typ=23&cmd_mod=2&host=[THE-HOST]&service=[THE-SERVICE]&btnSubmit=Commit" "http://[NAGIOS-SERVER]/nagios/cgi-bin/cmd.cgi"
Envera IT
Posts: 159
Joined: Wed Jun 19, 2013 10:21 am

Re: Set Acknowledgement via API

Post by Envera IT »

dwhitfield wrote:Not right now, but the developers have said it is in the roadmap for the future. It can be done via cmd.cgi. This is ***not*** for acknowledgements, but the syntax would be something like the following:
curl -d "cmd_typ=23&cmd_mod=2&host=[THE-HOST]&service=[THE-SERVICE]&btnSubmit=Commit" "http://[NAGIOS-SERVER]/nagios/cgi-bin/cmd.cgi"
It appears we're able to authenticate via that method, but all we get is this.

Code: Select all

External Command Interface
Last Updated: Tue Jul 25 16:21:26 EDT 2017
Nagios® Core™ 4.2.4 - www.nagios.org
Logged in as ?
Sorry, but you are not authorized to commit the specified command.
Read the section of the documentation that deals with authentication and authorization in the CGIs for more information.
We've been digging through the external command documentation but we're not making much headway. The user does have permissions from what I can tell. Does this look ok?

Code: Select all

curl -u user:pass -d "cmd_typ=33&cmd_mod=2&host=AAA-TEST-HOST&service=host&btnSubmit=Commit" "http://nagios/nagios/cgi-bin/cmd.cgi"
I like graphs...
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: Set Acknowledgement via API

Post by dwhitfield »

Here's the documentation (in case you were looking at something else): https://assets.nagios.com/downloads/nag ... t_commands

Can you PM me your Profile so we can take a look to see if there is something else that could be getting in the way? You can download it by going to Admin > System Config > System Profile and click the ***Download Profile*** button towards the top. If for whatever reason you *cannot* download the profile, please put the output of View System Info (5.3.4+, Show Profile if older) in the thread (that will at least get us some info). This will give us access to many of the logs we would otherwise ask for individually. If security is a concern, you can unzip the profile take out what you like, and then zip it up again. We may end up needing something you remove, but we can ask for that specifically.

After you PM the profile, please update this thread. Updating this thread is the only way for it to show back up on our dashboard.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Set Acknowledgement via API

Post by lmiltchev »

I got the same error as you. I haven't played a lot with the curl command, but why don't you just use the Nagios external commands to ack issues?

Example:

Code: Select all

#!/bin/sh

now=`date +%s`
commandfile='/usr/local/nagios/var/rw/nagios.cmd'

/bin/printf "[%lu] ACKNOWLEDGE_SVC_PROBLEM;localhost;Total Processes;2;1;1;test;Oh boy\n" $now > $commandfile
example01.PNG
Here's the external commands for acknowledging host and service problems:

https://old.nagios.org/developerinfo/ex ... mand_id=39

Note: Host name and service description are "hard-coded" in this example, but you could pass them as arguments to the bash script if you wish.

Hope this helps.
https://old.nagios.org/developerinfo/ex ... mand_id=40
You do not have the required permissions to view the files attached to this post.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Envera IT
Posts: 159
Joined: Wed Jun 19, 2013 10:21 am

Re: Set Acknowledgement via API

Post by Envera IT »

dwhitfield wrote:Here's the documentation (in case you were looking at something else): https://assets.nagios.com/downloads/nag ... t_commands

Can you PM me your Profile so we can take a look to see if there is something else that could be getting in the way? You can download it by going to Admin > System Config > System Profile and click the ***Download Profile*** button towards the top. If for whatever reason you *cannot* download the profile, please put the output of View System Info (5.3.4+, Show Profile if older) in the thread (that will at least get us some info). This will give us access to many of the logs we would otherwise ask for individually. If security is a concern, you can unzip the profile take out what you like, and then zip it up again. We may end up needing something you remove, but we can ask for that specifically.

After you PM the profile, please update this thread. Updating this thread is the only way for it to show back up on our dashboard.
PM sent, the documentation you linked is what we were looking at.
I like graphs...
Envera IT
Posts: 159
Joined: Wed Jun 19, 2013 10:21 am

Re: Set Acknowledgement via API

Post by Envera IT »

lmiltchev wrote:I got the same error as you. I haven't played a lot with the curl command, but why don't you just use the Nagios external commands to ack issues?

Example:

Code: Select all

#!/bin/sh

now=`date +%s`
commandfile='/usr/local/nagios/var/rw/nagios.cmd'

/bin/printf "[%lu] ACKNOWLEDGE_SVC_PROBLEM;localhost;Total Processes;2;1;1;test;Oh boy\n" $now > $commandfile
example01.PNG
Here's the external commands for acknowledging host and service problems:

https://old.nagios.org/developerinfo/ex ... mand_id=39

Note: Host name and service description are "hard-coded" in this example, but you could pass them as arguments to the bash script if you wish.

Hope this helps.
https://old.nagios.org/developerinfo/ex ... mand_id=40
We're trying to integrate our OTRS ticketing system with Nagios using their SystemMonitoring module. We've got everything working but the acknowledgment of issues in Nagios via the ticketing system. So we're trying to acknowledge issues from a remote server at this point. Would your example work for this?
I like graphs...
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: Set Acknowledgement via API

Post by dwhitfield »

You'd need to build in the logic for OTRS to kick off the script @lmiltchev provided, but yes, it should work.
Envera IT
Posts: 159
Joined: Wed Jun 19, 2013 10:21 am

Re: Set Acknowledgement via API

Post by Envera IT »

dwhitfield wrote:You'd need to build in the logic for OTRS to kick off the script @lmiltchev provided, but yes, it should work.
Yea we have the logic, what I'm confused about is how OTRS is supposed to trigger it on the XI side.

That script seems local to XI, how is OTRS supposed to send the command to XI?
I like graphs...
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: Set Acknowledgement via API

Post by dwhitfield »

Ehamby wrote: That script seems local to XI, how is OTRS supposed to send the command to XI?
There are a number of ways to get things to XI, but my thought is running the script via ssh from the OTRS server: https://www.cyberciti.biz/faq/unix-linu ... using-ssh/
Locked