Pass arguments from service to event handler

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
cellact
Posts: 69
Joined: Mon May 14, 2012 7:00 am

Pass arguments from service to event handler

Post 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
User avatar
CGraham
Posts: 115
Joined: Tue Aug 16, 2011 2:43 pm

Re: Pass arguments from service to event handler

Post by CGraham »

I believe you can achieve this by using the free variables in the host or service definition.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Pass arguments from service to event handler

Post 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
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
User avatar
CGraham
Posts: 115
Joined: Tue Aug 16, 2011 2:43 pm

Re: Pass arguments from service to event handler

Post 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
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Pass arguments from service to event handler

Post 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
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
cellact
Posts: 69
Joined: Mon May 14, 2012 7:00 am

Re: Pass arguments from service to event handler

Post 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!
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Pass arguments from service to event handler

Post 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
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked