Page 1 of 1
Pass arguments from service to event handler
Posted: Mon Oct 22, 2012 6:45 am
by cellact
Hi,
I'm trying to pass the $ARG4$ argument from a service check to the event handler it is triggering.
I tried adding $ARG4$ to the event handler command but it seems to not pass the original service's $ARG4$
How can I achieve this?
Thanks,
Tal
Re: Pass arguments from service to event handler
Posted: Mon Oct 22, 2012 1:01 pm
by CGraham
I believe you can achieve this by using the free variables in the host or service definition.
Re: Pass arguments from service to event handler
Posted: Mon Oct 22, 2012 2:12 pm
by scottwilkerson
CGraham is correct, we have some documentation for something similar to this used for restarting services
http://library.nagios.com/library/produ ... -nagios-xi
Re: Pass arguments from service to event handler
Posted: Mon Oct 22, 2012 2:27 pm
by CGraham
One important thing to note, which might be confusing is that in the NSClient++ config file (nsc.ini) they use the $ARG1$ and $ARG2$ nomenclature. This represents the first, second, etc argument that you pass to the nrpe command (using the -a switch) and are not related to the $ARG1$, $ARG2$ that you configure in your original check command.
If you post the details of what you're doing, we can suggest a possible setup. Helpful info:
What the check and eventhandler is trying to do
Service check config
event handler config
Re: Pass arguments from service to event handler
Posted: Mon Oct 22, 2012 2:43 pm
by scottwilkerson
Yes, the event_handler also uses them in Core under the hood, so if you had a command for your event handler like
Code: Select all
define command {
command_name a_test
command_line $USER1$/myevent.sh -a $ARG1$
}
And a config like this
Code: Select all
define host {
host_name 10.0.0.1
use linux-server
check_command check-host-alive!!!!!!!!
event_handler test_arg!XXXXXXXXX
event_handler_enabled 1
register 1
}
It would execute the following
Code: Select all
/usr/local/nagios/libexec/myevent.sh -a XXXXXXXXX
Re: Pass arguments from service to event handler
Posted: Thu Oct 25, 2012 7:25 am
by cellact
The free variable method worked great.
FYI, I couldn't find a way to edit the service config file and add an argument to be sent to the event handler like you stated:
Code: Select all
define host {
host_name 10.0.0.1
use linux-server
check_command check-host-alive!!!!!!!!
event_handler test_arg!XXXXXXXXX
event_handler_enabled 1
register 1
}
Thanks for your help!
Re: Pass arguments from service to event handler
Posted: Thu Oct 25, 2012 10:59 am
by scottwilkerson
cellact wrote:FYI, I couldn't find a way to edit the service config file and add an argument to be sent to the event handler like you stated:
I should have been clearer, there isn't a way to do this in XI