Page 1 of 2

Set Acknowledgement via API

Posted: Tue Jul 25, 2017 11:33 am
by Envera IT
Is it possible to use the REST API to set acknowledgements on a host or service?

Re: Set Acknowledgement via API

Posted: Tue Jul 25, 2017 12:07 pm
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"

Re: Set Acknowledgement via API

Posted: Wed Jul 26, 2017 7:58 am
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"

Re: Set Acknowledgement via API

Posted: Wed Jul 26, 2017 9:50 am
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.

Re: Set Acknowledgement via API

Posted: Wed Jul 26, 2017 10:00 am
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

Re: Set Acknowledgement via API

Posted: Wed Jul 26, 2017 10:16 am
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.

Re: Set Acknowledgement via API

Posted: Wed Jul 26, 2017 10:20 am
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?

Re: Set Acknowledgement via API

Posted: Wed Jul 26, 2017 10:30 am
by dwhitfield
You'd need to build in the logic for OTRS to kick off the script @lmiltchev provided, but yes, it should work.

Re: Set Acknowledgement via API

Posted: Wed Jul 26, 2017 10:44 am
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?

Re: Set Acknowledgement via API

Posted: Wed Jul 26, 2017 10:56 am
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/