RE: Passing Parameters to Event Handlers

Mike Dean <[email protected]>
Newsgroups gmane.network.netsaint.user
Message-ID <F622FE8186D60B4087A71DAD42ABE5E20B38F1@fljaxeml02>
Stanley, 

Thank you for your suggestions.  To answer your questions:

1)  I am using Nagios
2)  My event handler does echo the options to a file; however, I don't get
to this point (see below).
3)  I need to be able to pass parameters to the event handler as I am
passing an SNMP community string and different devices use different
community strings
4)  I may end up creating different event handlers for each "class" of
device (different "classes" use different SNMP strings).

On the debug options, I don't believe those will help as I cannot even start
Nagios when I try to use passed parameters to the event handler.  Following
is a stripped down config that may better explain what I am trying to do:

-- Create an event handler in my commands.cfg file:

define command{
        command_name    router-host
        command_line    $USER5$/router-host.sh $HOSTNAME$ $HOSTSTATE$
$STATETYPE$ $HOSTATTEMPT$ $TIMET$ $ARG1$
        }

Note that the last parameter is one that I want to pass

Now, define a host entry that will use this event handler:

define host {
	 (other options removed for sake of brevity)
	 .
        .
        name                            router-1
        event_handler_enabled           1
        event_handler                   router-host public
	}

Here, public is the SNMP string I want to pass to the event handler.  I have
also tried using the following:

router-host;public
router-host!public

Now, if I run '<path to nagios>/bin/nagios -v <path to
nagios>/etc/nagios.cfg' to verify the configuration, I get an error that
states that the event handler "router-host public" does not exist.

In other words, it seems that unlike check commands where you can pass
parameters (i.e., check_command check_ssh!Arg1!Arg2), event handlers do not
allow passed parameters in the host/service configuration (I also tried
enclosing the entire command in quotes and that produced an error also).  

If I change the event handler config and supply the community string in the
definition:

define command{
        command_name    router-host
        command_line    $USER5$/router-host.sh $HOSTNAME$ $HOSTSTATE$
$STATETYPE$ $HOSTATTEMPT$ $TIMET$ public
        }

then in the host config simply have this:
define host {
	event_handler		router-host
}

That will work.  Of course, that would mean that I would have to create an
event handler for each class of machine that used a different SNMP community
string -- something that I was trying to avoid.

Mike
-----Original Message-----
From: Stanley Hopcroft [mailto:[email protected]]
Sent: Thursday, November 21, 2002 5:49 AM
To: Mike Dean
Cc: [email protected]
Subject: Re: [netsaint] Passing Parameters to Event Handlers


Dear Sir,

I am writing to say that I am sorry that progress to helping you is
slow.

Are you using Nagios ?

(The resource definitions don't look like Netsaint).

The only suggestions I have are

. setting the debug compile variable as mentioned before and 
seeing at the command line that Netsaint uses for the handler

(create a new copy of the Netsaint source tree, build in that using a
non-production --prefix to configure, install into the non production
path, and then create in that path a stripped down set of resource files
that send notifications to /dev/bit_bucket - so you don't have too much
to look at and so that your contact groups don't get annoyed, start it
up in the forground and watch for the debug messages.

Another useful technique may be to replace your event handler by one
that echoes its arguments

Then, you can send a bug report/request for enhancement with the debug
output.

. try an event handler like so :-

'/usr/yada/handler -opt1 -opt2 argv1 argv2'

(ie quote the handler path and arguments).

Why is it that you need different arguments for each handler ?

Could you do like so in command.cfg

handler1...arguments for handler1
handler2...arguments for handler2

eg

tsitc> grep _ssh /usr/local/netsaint/etc/commands.cfg
command[check_by_ssh]=$USER1$/check_by_ssh -t 30 -H $ARG1$ -l $ARG2$ -C
'$ARG3$ $ARG4$'
command[check_by_ssh2]=$USER1$/check_by_ssh -t 30 -H $ARG1$ -l $ARG2$ -C
'$ARG3$ $ARG4$ $ARG5$'
command[check_by_ssh3]=$USER1$/check_by_ssh -t 30 -H $ARG1$ -l $ARG2$ -C
'$ARG3$ $ARG4$ $ARG5$ $ARG6$ $ARG7$ $ARG8$ $ARG9$'
command[check_wl_ssh]=$USER1$/check_by_ssh -t 30 -H $ARG1$ -l $ARG2$ -i
/home/netsaint/.ssh/smon_identity -C '$ARG3$ $ARG4$'
command[check_dhcp_ssh]=$USER1$/check_by_ssh -t 45 -H $HOSTNAME$ -l
netsaint -i /home/netsaint/.ssh/id_dsa -C 'check_dhcp -l'
tsitc> 

Crude but effective.

HTH.

Yours sincerely.



-- 
------------------------------------------------------------------------
Stanley Hopcroft
------------------------------------------------------------------------

'...No man is an island, entire of itself; every man is a piece of the
continent, a part of the main. If a clod be washed away by the sea,
Europe is the less, as well as if a promontory were, as well as if a
manor of thy friend's or of thine own were. Any man's death diminishes
me, because I am involved in mankind; and therefore never send to know
for whom the bell tolls; it tolls for thee...'

from Meditation 17, J Donne.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.