Local EventHandler versus Global EventHandler

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
onegative
Posts: 173
Joined: Tue Feb 17, 2015 12:06 pm

Local EventHandler versus Global EventHandler

Post by onegative »

G'day Support,

Question:
I am attempting to utilize %ENV variables in both a local event handler which appears to work just fine but not so in my global event handler, is that by design or is there some further magic required to get it to function the same?

I am calling the exact same script in both instances but only the local event handler actually sees the NAGIOS_ environmental variables.

In my nagios.cfg
enable_environment_macros=1
enable_event_handlers=1
global_host_event_handler=xi_host_event_handler
global_service_event_handler=xi_service_event_handler


global event handler output
HOME is /home/nagios
LANG is en_US.UTF-8
LOGNAME is nagios
PATH is /usr/bin:/bin
PWD is /home/nagios
SHELL is /bin/sh
SHLVL is 2
USER is nagios
XDG_RUNTIME_DIR is /run/user/1001
XDG_SESSION_ID is 2174555
_ is /usr/local/nagios/libexec/test.pl


local event handler output
G_BROKEN_FILENAMES is 1
LANG is en_US.UTF-8
NAGIOS_ADMINEMAIL is root@localhost
NAGIOS_ADMINPAGER is root@localhost
NAGIOS_COMMANDFILE is /usr/local/nagios/var/rw/nagios.cmd
NAGIOS_DATE is 08-28-2015
NAGIOS_EVENTSTARTTIME is 1440770626
NAGIOS_HOSTADDRESS is 127.0.0.1
NAGIOS_HOSTALIAS is event_handler_test
NAGIOS_HOSTATTEMPT is 1
NAGIOS_HOSTCHECKCOMMAND is check_dummy!0!1!!!!!!
NAGIOS_HOSTCHECKTYPE is PASSIVE
NAGIOS_HOSTDISPLAYNAME is event_handler_test
NAGIOS_HOSTDURATION is 0d 0h 0m 0s
NAGIOS_HOSTEVENTID is 96650
NAGIOS_HOSTEXECUTIONTIME is 0.000
NAGIOS_HOSTLATENCY is 0.672
NAGIOS_HOSTNAME is event_handler_test
NAGIOS_HOSTNOTIFICATIONID is 113066
NAGIOS_HOSTOUTPUT is HOST APPEARS TO BE GONE!
NAGIOS_HOSTPERCENTCHANGE is 34.47
NAGIOS_HOSTPERFDATAFILE is /usr/local/nagios/var/host-perfdata
NAGIOS_HOSTPROBLEMID is 40669
NAGIOS_HOSTSTATE is DOWN
NAGIOS_HOSTSTATEID is 1
NAGIOS_HOSTSTATETYPE is HARD
NAGIOS_LASTHOSTCHECK is 1440770667
NAGIOS_LASTHOSTDOWN is 1440770614
NAGIOS_LASTHOSTEVENTID is 96649
NAGIOS_LASTHOSTPROBLEMID is 40668
NAGIOS_LASTHOSTSTATE is UP
NAGIOS_LASTHOSTSTATECHANGE is 1440770667
NAGIOS_LASTHOSTUP is 1440770667
NAGIOS_LOGFILE is /usr/local/nagios/var/nagios.log
NAGIOS_LONGDATETIME is Fri Aug 28 07:04:27 PDT 2015
NAGIOS_MAINCONFIGFILE is /usr/local/nagios/etc/nagios.cfg
NAGIOS_MAXHOSTATTEMPTS is 5
NAGIOS_OBJECTCACHEFILE is /usr/local/nagios/var/objects.cache
NAGIOS_PROCESSSTARTTIME is 1440770626
NAGIOS_RESOURCEFILE is /usr/local/nagios/etc/resource.cfg
NAGIOS_RETENTIONDATAFILE is /usr/local/nagios/var/retention.dat
NAGIOS_SERVICEPERFDATAFILE is /usr/local/nagios/var/service-perfdata
NAGIOS_SHORTDATETIME is 08-28-2015 07:04:27
NAGIOS_STATUSDATAFILE is /usr/local/nagios/var/status.dat
NAGIOS_TEMPFILE is /usr/local/nagios/var/nagios.tmp
NAGIOS_TEMPPATH is /tmp
NAGIOS_TIME is 07:04:27
NAGIOS_TIMET is 1440770667
PATH is /sbin:/usr/sbin:/bin:/usr/bin
PWD is /
SHLVL is 1
SSH_TTY is /dev/pts/0
USER is nagios
_ is /usr/local/nagios/bin/nagios



I really would like the global event handler to simply extract the variables from the %ENV hash and not be required to pass arguments into the script...that just adds additional steps when new and exciting things are added.

Please let me know what you think and thanks in advance,
Danny
onegative
Posts: 173
Joined: Tue Feb 17, 2015 12:06 pm

Re: Local EventHandler versus Global EventHandler

Post by onegative »

RESOLVED!

OK I finally figured it out...seems I have to specify the script I am calling via a command I create...so I changed reference from xi_host_event_handler (not sure what/where/how that is) but provided the short name to the command I created which points to my script.

define command {
command_name event_handler_test
command_line $USER1$/test.pl
}

i.e.

# GLOBAL EVENT HANDLERS
#global_host_event_handler=xi_host_event_handler
#global_service_event_handler=xi_service_event_handler
global_host_event_handler=event_handler_test
global_service_event_handler=event_handler_test


Apparently the %ENV is not available from the Host State Change Handler GUI page if you specify the script directly such as

/usr/local/nagios/libexec/test.pl or even the short-name of a defined command event_handler_test

Thanks anyway,
Danny
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

Re: Local EventHandler versus Global EventHandler

Post by lmiltchev »

I am glad your issue has been resolved! I am locking this topic.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked