Page 1 of 4
Custom action url doesn't seem to accept macro's
Posted: Tue Oct 22, 2013 9:06 am
by WillemDH
hello,
As we are receiving rather much events from servers, I made some time ago a feature request to submit a passive OK result to a service:
http://tracker.nagios.com/view.php?id=427
We really need something like this to be able to fastly reset a service to healthy state.
Today I've been reading about custom actions:
http://assets.nagios.com/downloads/nagi ... ponent.pdf and I was thinking why not give it a try and try configure a custom action myself.
Now I didn't found any external command in
http://old.nagios.org/developerinfo/ext ... ndlist.php to submit a state, so I copied the url from the Advanced => Submit Passive Check Result:
http://nagiosserver/nagiosxi/includes/c ... EVT_System and tried to use a macro $host$, $hostname$, <hostname> but the result stays the same, I can' get the name of the server to appear in the hostname textbox.
<input type="TEXT" value="$host$" name="host"></input>
After I manage to get the hostname in the host textbox, I would stil want to get OK by default in the plugn_output checkbox:
<input type="TEXT" value="" name="plugin_output"></input>
Any tips / ideas? Maybe it is better to submit a passive OK result with some bash script, but I have no idea where to start. I Can't be the only person who would want a way to just reset the health of a service through a quick action?
Grtz
Re: Custom action url doesn't seem to accept macro's
Posted: Tue Oct 22, 2013 10:26 am
by abrist
You will not be able to to use macros through the passive check forms as you have already discovered. You can create an action (with teh actions component) that would run a bash script to submit a passive result. See:
http://old.nagios.org/developerinfo/ext ... and_id=115
http://old.nagios.org/developerinfo/ext ... and_id=114
Re: Custom action url doesn't seem to accept macro's
Posted: Tue Oct 22, 2013 10:29 am
by WillemDH
Ok, I should read the manual better (or the examples). When I use %host% it works fine. Is there anyone who knows how I could get OK by default in the plugn_output checkbox:
<input type="TEXT" value="" name="plugin_output"></input>
When I try to make an url with &plugin_output=OK&, it doesn't seem to work.. I just do not want to get an error "Plugin output cannot be blank" because the plugin_output textbox is not filled in. SO a default value or some way to submit the value in the url would be fantastic.
Re: Custom action url doesn't seem to accept macro's
Posted: Tue Oct 22, 2013 10:42 am
by WillemDH
Hi Andy,
Thanks for redirecting me to the external command I needed! Now I did try it with macro's and it does seem to work with macro's using an url.
http://nagiosserver/nrdp/?cmd=submitcmd ... ystem;0;OK
The only disadvantage now is that when I click it, it also opens a new webpage with some xml code in it. is there some way to prevent the new webpage with the xml from popping up, maybe through the php code? Or should I really use a bash script to execute the external command (problem is my bash knowledge is zero...

)
Re: Custom action url doesn't seem to accept macro's
Posted: Tue Oct 22, 2013 11:07 am
by abrist
Have you looked over the actions component document? There are a few starter bash scripts in there:
http://assets.nagios.com/downloads/nagi ... ponent.pdf
You could make a bash script that either writes to the command pipe or wgets the url (I never thought of using nrdp for this). You will have to pass the host macro to the script as well.
Create the following bash script at:
Code: Select all
touch /usr/local/nagios/libexec/passive_reset_ok.sh
Make it executable:
Code: Select all
chmod +x /usr/local/nagios/libexec/passive_reset_ok.sh
Then put the following code into it:
Code: Select all
#!/bin/bash
HOSTNAME=$1
/usr/bin/printf "[%lu]PROCESS_SERVICE_CHECK_RESULT;$HOST;0;Passive reset - OK\n"
`date +%s` > /usr/local/nagios/var/rw/nagios.cmd
Now configure the action in the actions component:
Code: Select all
Object Type: Host
Host: /.*/
...
Action Type: Command
Command: /usr/local/nagios/libexec/passive_reset_ok.sh "%host%"
Action Text: Reset Host to state OK
Re: Custom action url doesn't seem to accept macro's
Posted: Tue Oct 22, 2013 11:10 am
by WillemDH
Andy,
Ok, I thought I'd give it a try and made a bash script following your procedure in
http://assets.nagios.com/downloads/nagi ... ponent.pdf
So I made a script named dig_ext_cmd_svc_submit_ok.sh, made it executable with chmod +x dig_ext_cmd_svc_submit_ok.sh
Code: Select all
#!/bin/sh
# This is a sample shell script showing how you can submit the PROCESS_SERVICE_CHECK_RESULT command
# to Nagios. Adjust variables to fit your environment as necessary.
now=`date +%s`
commandfile='/usr/local/nagios/var/rw/nagios.cmd'
/bin/printf "[%lu] PROCESS_SERVICE_CHECK_RESULT;$HOST;$SERVICE;0;OK" $now > $commandfile
I created the action following your procedure:
Action type command
/usr/local/nagios/libexec/dig_ext_cmd_svc_submit_ok.sh
But when I try executing it, it also gives me a popup webpage telling me it is running the command:
Code: Select all
Running: /usr/local/nagios/libexec/dig_ext_cmd_svc_submit_ok.sh
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Run Command Again [Close]
And it doens't seem to work

What could I do to prevent the popup webpage?
Re: Custom action url doesn't seem to accept macro's
Posted: Tue Oct 22, 2013 11:23 am
by WillemDH
Ok, I'm getting closer.... I think I'm just having an issue with my parameters not getting through correctly.
Code: Select all
#!/bin/sh
# This is a sample shell script showing how you can submit the PROCESS_SERVICE_CHECK_RESULT command
# to Nagios. Adjust variables to fit your environment as necessary.
HOSTNAME=$1
SERVICENAME=$2
now=`date +%s`
commandfile='/usr/local/nagios/var/rw/nagios.cmd'
/bin/printf "[%lu] PROCESS_SERVICE_CHECK_RESULT;$HOSTNAME;$SERVICENAME;0;OK\n"
$now > $commandfile
Als tried with /bin/printf "[%lu] PROCESS_SERVICE_CHECK_RESULT;HOSTNAME;SERVICENAME;0;OK\n" (without the dollars)
But it's still not working. The command in actions component looks like this now:
Code: Select all
/usr/local/nagios/libexec/dig_ext_cmd_svc_submit_ok.sh "%host%" "%service%"
In the meantime I tried the command without ", but there is still something wrong somewhere:
Code: Select all
/usr/local/nagios/libexec/dig_ext_cmd_svc_submit_ok.sh %host% %service%
What I don't get in your example is :
Code: Select all
Then put the following code into it:
Code: Select all#!/bin/bash
HOSTNAME=$1
/usr/bin/printf "[%lu]PROCESS_SERVICE_CHECK_RESULT;$HOST;0;Passive reset - OK\n"
`date +%s` > /usr/local/nagios/var/rw/nagios.cmd
First you define HOSTNAME=$1, so I guess this means HOSTNAME = parameter 1, but hen you print the command and use $HOST instead of HOSTNAME. i tried doing it this way :
Code: Select all
HOSTNAME=$1
SERVICENAME=$2
now=`date +%s`
commandfile='/usr/local/nagios/var/rw/nagios.cmd'
/bin/printf "[%lu] PROCESS_SERVICE_CHECK_RESULT;$HOST;$SERVICE;0;OK - Manual Reset\n"
$now > $commandfile
But still nothing...
Re: Custom action url doesn't seem to accept macro's
Posted: Tue Oct 22, 2013 12:30 pm
by abrist
WillemDH wrote:First you define HOSTNAME=$1, so I guess this means HOSTNAME = parameter 1, but hen you print the command and use $HOST instead of HOSTNAME. i tried doing it this way :
That was due to lack of proofreading when I scratched out that script. You original version is correct:
Code: Select all
#!/bin/bash
HOSTNAME=$1
SERVICENAME=$2
now=`date +%s`
commandfile='/usr/local/nagios/var/rw/nagios.cmd'
/bin/printf "[%lu] PROCESS_SERVICE_CHECK_RESULT;$HOSTNAME;$SERVICENAME;0;OK - Manual Reset\n"
$now > $commandfile
Could you try running it from the cli?
Code: Select all
/usr/local/nagios/libexec/dig_ext_cmd_svc_submit_ok.sh "<hostname>" "<service name>"
Re: Custom action url doesn't seem to accept macro's
Posted: Tue Oct 22, 2013 1:51 pm
by WillemDH
WHen I try running it at cli I get:
[root@nagios01 libexec]# ./dig_ext_cmd_svc_submit_ok.sh "genparnt.gentgrp.gent.be" "SRV_Uptime"
./dig_ext_cmd_svc_submit_ok.sh: line 10: /bin/printf: No such file or directory
./dig_ext_cmd_svc_submit_ok.sh: line 11: 1382467757: command not found
Re: Custom action url doesn't seem to accept macro's
Posted: Tue Oct 22, 2013 1:54 pm
by WillemDH
I changed /bin/printf to /usr/bin/printf and now I get
./dig_ext_cmd_svc_submit_ok.sh: line 11: 1382467925: command not found
Line 11 would be:
$now > $commandfile
Code: Select all
#!/bin/bash
# This is a sample shell script showing how you can submit the PROCESS_SERVICE_CHECK_RESULT command
# to Nagios. Adjust variables to fit your environment as necessary.
HOSTNAME=$1
SERVICENAME=$2
now=`date +%s`
commandfile='/usr/local/nagios/var/rw/nagios.cmd'
/usr/bin/printf "[%lu] PROCESS_SERVICE_CHECK_RESULT;$HOSTNAME;$SERVICENAME;0;OK - Manual Reset\n"
$now > $commandfile