Page 1 of 1

Global Event Handler Command Won't Run

Posted: Wed Oct 30, 2013 2:40 pm
by bmac423
Thanks for taking a look at my post; I looked everywhere and couldn't find anyone with the same problem.

It appears that the global event handler command is not triggering in my setup. This problem has been driving me crazy for the last few days. It shows up in the log at the appropriate time, but nothing happens. To me it feels like a permissions issue, but from everything I can see, it looks fine. The script is set as 777 owned by nagios:nagios. It runs fine manually when run by the nagios user. I've tried to just have the command echo into a temporary log file (i.e. command_line echo "test123" >> test.log) and that doesn't work either, although, again it shows in the log with no errors. I have all alerts on, with verbosity maxed out and the below is all I get in the log relating to the event handler.

Anyone have any ideas? Thanks in advance.

nagios.cfg

Code: Select all

log_event_handlers=1
global_host_event_handler=hpov_host_eventhandler
global_service_event_handler=hpov_service_eventhandler
enable_event_handlers=1
debug_level=-1
debug_verbosity=2
Command Definitions:

Code: Select all

define command {
	command_name                   hpov_service_eventhandler
	command_line                      /usr/share/nagios3/plugins/eventhandlers/hpov_eventhandler.rb service $LASTSERVICECHECK$ $HOSTNAME$ "$SERVICESTATE$" "$SERVICEOUTPUT$" "$SERVICEDESC$"
}

define command {
	command_name                   hpov_host_eventhandler
	command_line                      /usr/share/nagios3/plugins/eventhandlers/hpov_eventhandler.rb host $LASTHOSTCHECK$ "$HOSTNAME$" "$HOSTSTATE$" "$HOSTOUTPUT$"
}
Script:

Code: Select all

#!/usr/bin/env ruby 

type       = ARGV[0]
lastcheck  = ARGV[1]
host       = ARGV[2]
status     = ARGV[3]
statustext = ARGV[4]
service    = ARGV[5]

logfile = "/usr/share/nagios3/plugins/eventhandlers/hpov_eventhandler.log"
debug = true
hpovstatus = nil
hpovobject = nil
time1 = Time.new

puts "I was passed: "
ARGV.each do |value|
  puts value
end

debug = true
hpovstatus = nil
hpovobject = nil
time1 = Time.new

logfile = "/usr/share/nagios3/plugins/eventhandlers/hpov_eventhandler.log"

if type == "service"
  hpovobject = service
  if status == 'CRITICAL'
    hpovstatus = 'warning'
  elsif status == 'WARNING'
    hpovstatus = 'warning'
  elsif status == 'UNKNOWN'
    hpovstatus = 'minor'
  elsif status =="OK"
    hpovstatus = 'normal'
  else
    hpovstatus = 'minor'
  end
elsif type == "host"
  hpovobject = "redacted"
  if status == 'DOWN'
    hpovstatus = 'warning'
  elsif status == 'UNREACHABLE'
    hpovstatus = 'warning'
  elsif status == 'UNKNOWN'
    hpovstatus = 'minor'
  elsif status =="UP"
    hpovstatus = 'normal'
  else
    hpovstatus = 'minor'
  end
else
  hpovstatus = 'error'
end

open(logfile, 'a') { |f|
  f << "Time: " + time1.inspect + "\n"
  f << "I was passed: \n"
  ARGV.each do |value|
    f << value + "\n"
  end
  f << "Command Line: /opt/OV/bin/OpC/opcmsg severity=\"#{hpovstatus}\" application=redacted object=#{hpovobject} msg_text=\"Host: #{host}, Message: #{statustext}\"\n"
  f << "___________________________________________________________\n\n"
}

exec "/opt/OV/bin/OpC/opcmsg severity=\"#{hpovstatus}\" application=redacted object=#{hpovobject} msg_text=\"Host: #{host}, Message: #{statustext}\""
syslog Output:

Code: Select all

Oct 30 11:48:46 redacted nagios3: GLOBAL SERVICE EVENT HANDLER: redacted;Check Puppet Agent;CRITICAL;SOFT;1;hpov_service_eventhandler
Oct 30 11:49:46 redacted nagios3: GLOBAL SERVICE EVENT HANDLER: redacted;Check Puppet Agent;CRITICAL;HARD;2;hpov_service_eventhandler
Oct 30 13:47:49 redacted nagios3: GLOBAL SERVICE EVENT HANDLER: redacted;Check Puppet Agent;OK;HARD;2;hpov_service_eventhandler

Re: Global Event Handler Command Won't Run

Posted: Wed Oct 30, 2013 5:02 pm
by abrist
Do the host event handlers ever get logged?
One thing I noticed about your service handler is that $HOSTNAME$ is lacking quotes and can be an issue if you have hosts with odd characters or spaces in the name.
What version of core are you running?

Re: Global Event Handler Command Won't Run

Posted: Wed Oct 30, 2013 8:18 pm
by bmac423
Thanks for the reply abrist. I can add the quotes in there, but I don't think that's the issue. We don't have any strange characters in our hostnames. We're running Nagios 3.2.3. I was finally able to print to the log file with this command_line:

Code: Select all

command_line => 'echo \'test\' >> /usr/share/nagios3/plugins/eventhandlers/hpov_eventhandler.log',

Re: Global Event Handler Command Won't Run

Posted: Wed Oct 30, 2013 8:28 pm
by bmac423
Oh, haven't had a host event trigger yet. I've just been testing services first.

Re: Global Event Handler Command Won't Run

Posted: Thu Oct 31, 2013 10:41 am
by abrist
bmac423 wrote: I was finally able to print to the log file with this command_line:
That is from the rb script I presume? If so then we can assume the script is running or at least starting. Can you move the echo near the end of your script? I would be interested to see If the issue is that the script is failing deeper into its logic.