Page 2 of 4
Re: Global Event Handlers
Posted: Thu May 15, 2014 6:11 am
by klee
Good Morning Abrist,
As you know by now, we are trying to use Event Handlers to filter snmptraps sent to another network monitoring system. I'm currently trying to figure out how to use Global Event Handlers to accomplish this task (instead of individual event handlers). I fully understand that you guys cannot write the Event Handlers for us. However, any guidance you can offer would be greatly appreciated.
I'd imagine the process is similar for anyone who has successfully deployed Global Event Handlers:
1) Create a separate handler for hosts events and service events
2) Set up logic in the event handler scripts that will only take action (send snmptrap) based on the type of host or service event
3) Utilize the proper macros to supply pertinent information about host and services
However, all of this seems much simpler in theory than application. It would be really helpful to see some sample Global Event Handlers (even if they aren't configured to send snmptraps). Plus, the "Introduction to Event Handlers" PDF only includes an example for host events; it would be really helpful to see some examples for service events, as well.
Thank you very much for your assistance.
-klee
Re: Global Event Handlers
Posted: Thu May 15, 2014 5:05 pm
by slansing
Actually, if you take a look at the notification commands, those are effectively global handlers, they are triggered on hard state changes for each host/service.
http://nagios.sourceforge.net/docs/3_0/ ... tions.html
I think abrist will be commenting on this and your other thread here in the future and he has quite a bit of time invested in event handlers.
Re: Global Event Handlers
Posted: Thu May 15, 2014 5:07 pm
by abrist
The global event handler doc should provide you with a few examples:
http://assets.nagios.com/downloads/nagi ... ndlers.pdf
This of course requires returning the command and nagios.cfg global event handlers to their original values.
Re: Global Event Handlers
Posted: Fri May 16, 2014 1:11 pm
by klee
Thanks, I'll look through these documents and get back to you with some specific questions.
-klee
Re: Global Event Handlers
Posted: Fri May 16, 2014 1:16 pm
by abrist
No problem, talk to you Monday!
Re: Global Event Handlers
Posted: Wed May 21, 2014 10:15 pm
by klee
Finally got the Global Event Handler working w/ Variables
I could use some help with the snmptrap portion though (please see below)
------------------------------------------------------------------------------------------------------------------------------------------------------
/usr/local/nagios/libexec/nms_global_host_event_handler.sh "%host%" "%hostaddress%" %hoststate% %hoststateid%
[root@Nagios libexec]# cat nms_global_host_event_handler.sh
#!/bin/bash
HOST=$1
HOSTADDRESS=$2
HOSTSTATE=$3
HOSTSTATEID=$4
echo "The host: $HOST with address: $HOSTADDRESS is in state: $HOSTSTATE with ID: $HOSTSTATEID" >> /tmp/nagios-test
[root@Nagios tmp]# tail -f nagios-test
The host: MY-PC-HOSTNAME with address: 192.168.0.1 is in state: DOWN with ID: 1
------------------------------------------------------------------------------------------------------------------------------------------------------
I got SNMP traps partially working but couldn’t find corresponding values for HOSTADDRESS or HOSTSTATE in NAGIOS-NOTIFY-MIB, so I’m only using HOST and HOSTSTATEID right now.
/usr/local/nagios/libexec/nms_global_host_event_handler.sh "%host%" %hoststateid%
#!/bin/bash
HOST=$1
HOSTSTATEID=$2
/usr/bin/snmptrap -v 2c -c public 192.168.x.x '' NAGIOS-NOTIFY-MIB::nHostEvent nHostname s $HOST nHostStateID i $HOSTSTATEID
May 21 22:33:53 localhost snmptrapd[1049]: 2014-05-21 22:33:51 <UNKNOWN> [UDP: [192.168.x.x]:49429->[192.168.x.x]]:#012DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (708261) 1:58:02.61#011SNMPv2-MIB::snmpTrapOID.0 = OID: SNMPv2-SMI::enterprises.20006.1.5#011SNMPv2-SMI::enterprises.20006.1.1.1.2 = STRING: "MY-PC-HOSTNAME"#011SNMPv2-SMI::enterprises.20006.1.1.1.4 = INTEGER: 0
------------------------------------------------------------------------------------------------------------------------------------------------------
How would I reference variables that don't have corresponding values in NAGIOS-NOTIFY-MIB?
Also, why is the example presented as --host="%host%" ??
How would we use --host to reference %host% within the shell script?
Thanks Again,
-klee
Re: Global Event Handlers
Posted: Thu May 22, 2014 9:47 am
by abrist
klee wrote:I got SNMP traps partially working but couldn’t find corresponding values for HOSTADDRESS or HOSTSTATE in NAGIOS-NOTIFY-MIB, so I’m only using HOST and HOSTSTATEID right now.
The MIB does not include the macros HOSTADDRESS and HOSTSTATE.
klee wrote:Also, why is the example presented as --host="%host%" ??
Which example?
klee wrote:How would we use --host to reference %host% within the shell script?
Could you clarify? As far as I see, you reference %host% in the shell script by using the shell variable that was assigned from the passed arguments:
klee wrote:HOST=$1
Re: Global Event Handlers
Posted: Thu May 22, 2014 10:18 am
by klee
Hi Abrist,
OK, if NAGIOS-NOTIFY-MIB does not include the macros HOSTADDRESS and HOSTSTATE, then is there still a way we can still reference them in an snmptrap?
Yes, I'm now able to reference the variables (by using HOST=$1 HOSTSTATE=$2) thanks to your example. The example I'm referring to is the one presented in Global Event Handlers Config UI (see below) before I modified it.
/tmp/host_change_handler.sh --host="%host%" --hoststate=%hoststate% --hoststateid=%hoststateid% --lasthoststate=%lasthoststate% --lasthoststateid=%lasthoststateid% --hoststatetype=%hoststatetype% --currentattempt=%currentattempt% --maxattempts=%maxattempts% --hosteventid=%hosteventid% --hostproblemid=%hostproblemid% --hostoutput="%hostoutput%" --hostdowntime=%hostdowntime%
/tmp/service_change_handler.sh --host="%host%" --service="%service%" --hoststate=%hoststate% --servicestate=%servicestate% --servicestateid=%servicestateid% --lastservicestate=%lastservicestate% --lastservicestateid=%lastservicestateid% --servicestatetype=%servicestatetype% --currentattempt=%currentattempt% --maxattempts=%maxattempts% --serviceeventid=%serviceeventid% --serviceproblemid=%serviceproblemid% --serviceoutput="%serviceoutput%" --servicedowntime=%servicedowntime%
Thanks Much,
-klee
Re: Global Event Handlers
Posted: Fri May 23, 2014 9:59 am
by slansing
Hello Klee,
I believe Abrist is the most qualified to answer this post, but I will dig into it and see what I come up with, thank you for your patience.
Re: Global Event Handlers
Posted: Fri May 23, 2014 10:14 am
by klee
Thank you Slasing.
I'd gladly wait for Abrist's response as well.
Best,
-klee