Custom action url doesn't seem to accept macro's
Custom action url doesn't seem to accept macro's
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
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
You do not have the required permissions to view the files attached to this post.
Nagios XI 5.8.1
https://outsideit.net
https://outsideit.net
Re: Custom action url doesn't seem to accept macro's
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
http://old.nagios.org/developerinfo/ext ... and_id=115
http://old.nagios.org/developerinfo/ext ... and_id=114
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Re: Custom action url doesn't seem to accept macro's
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.
<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.
You do not have the required permissions to view the files attached to this post.
Nagios XI 5.8.1
https://outsideit.net
https://outsideit.net
Re: Custom action url doesn't seem to accept macro's
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...
)
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...
Nagios XI 5.8.1
https://outsideit.net
https://outsideit.net
Re: Custom action url doesn't seem to accept macro's
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:
Make it executable:
Then put the following code into it:
Now configure the action in the actions component:
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.shCode: Select all
chmod +x /usr/local/nagios/libexec/passive_reset_ok.shCode: 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.cmdCode: 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 OKFormer Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Re: Custom action url doesn't seem to accept macro's
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
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:
And it doens't seem to work
What could I do to prevent the popup webpage?
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
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]Nagios XI 5.8.1
https://outsideit.net
https://outsideit.net
Re: Custom action url doesn't seem to accept macro's
Ok, I'm getting closer.... I think I'm just having an issue with my parameters not getting through correctly.
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:
In the meantime I tried the command without ", but there is still something wrong somewhere:
What I don't get in your example is :
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 :
But still nothing...
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
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%"Code: Select all
/usr/local/nagios/libexec/dig_ext_cmd_svc_submit_ok.sh %host% %service%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.cmdCode: 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
Nagios XI 5.8.1
https://outsideit.net
https://outsideit.net
Re: Custom action url doesn't seem to accept macro's
That was due to lack of proofreading when I scratched out that script. You original version is correct: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 :
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 > $commandfileCode: Select all
/usr/local/nagios/libexec/dig_ext_cmd_svc_submit_ok.sh "<hostname>" "<service name>"Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Re: Custom action url doesn't seem to accept macro's
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
[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
Nagios XI 5.8.1
https://outsideit.net
https://outsideit.net
Re: Custom action url doesn't seem to accept macro's
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
./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
Nagios XI 5.8.1
https://outsideit.net
https://outsideit.net