Global event handlers appear not to work

Shane Allen shane at emphasys.net
Fri Sep 26 04:17:54 CEST 2003


Below should be everything necessary to diagnose my problem, I hope.

I have written two perl scripts, both of which are installed in /usr/local/bin.

jabber-send.pl establishes a connection to our jabber server and sends $ARGV[0] to $ARGV[1].
for example: jabber-send.pl "jabber.test.com/announce/online" "This is a test"

nagios-jabber-event-handler formats a message based on stuff it gets from nagios, and sends in the event of a HARD state:
for example: nagios-jabber-event-handler "CRITICAL" "HARD" "5" "host" "svc" "blah" "foobar"
it sends the message by calling jabber-send.pl.

everything looks okay. The pre-flight check finds no problems. I never receive jabbers,
unless I change the config below to point directly at jabber-send.pl. The problem with this
is that I then get a jabber for every soft state as well as the hard states, which can be
annoying to say the least.

Also notice the debug file I generate (/var/log/nagios/blah) in my event handler script.
In theory it is supposed to dump the ARGV array into that file when the script is called.
If I run the script by hand, it works. Nagios' invocation of the script, however, never
results in the creation of that file, in addition to the fact that I never get a jabber.

Thoughts?

jabber-send.pl:
------------------------------------------------------------------------------------------
#!/usr/bin/perl -w

use strict;
use Net::Jabber qw(Client);

my $username = "foobar";
my $password = "baz";
my $server = "jabber.test.com";

my $to = $ARGV[0];
my $message = $ARGV[1];
my $resource = `hostname`;#.substr(rand(), 3, 6);

#my $Con = new Net::Jabber::Client( debuglevel => 2, debugfile => "stdout" );
my $Con = new Net::Jabber::Client();

my $status = $Con->Connect(hostname => $server);
if(!$Con->Connected())
{
        die "Error connecting to Jabber server\n";
}

my @result = $Con->AuthSend(username => $username,
                password => $password,
                resource => $resource,
                );
if($result[0] ne "ok")
{
        die "Error authenticating: $result[0], $result[1]\n";
}

$Con->MessageSend(
                to => $to,
                body => $message,
                type => "chat",
                priority => 1000,
                );

$Con->Disconnect() if $Con->Connected();
------------------------------------------------------------------------------------------


nagios-jabber-event-handler:
------------------------------------------------------------------------------------------
#!/usr/bin/perl -w

use strict;
use Data::Dumper;

open(FILE, '>/var/log/nagios/blah')||die('wtf');
print FILE Dumper(\@ARGV);
close FILE;

my $state = $ARGV[0];
my $type = $ARGV[1];
my $attempt = $ARGV[2];

my $user = $ARGV[3];
my $host = $ARGV[4];
my $svc = $ARGV[5];
my $msg = $ARGV[8];

if($svc eq "none")
{
        $msg = "$host is $state $msg";
}
else
{
        $msg = "$host/$svc is $state $msg";
}

#send message
if($type eq "HARD")
{
        `/usr/local/bin/jabber-send.pl "$user" '$msg'`;
}
else
{
        `/usr/local/bin/jabber-send.pl "$user" 'Not a hard error state: $msg'`;
}
------------------------------------------------------------------------------------------


relevant lines from nagios.cfg:
------------------------------------------------------------------------------------------
global_host_event_handler=jabber-host-event-handler
global_service_event_handler=jabber-service-event-handler
------------------------------------------------------------------------------------------


relevant lines from command.cfg:
------------------------------------------------------------------------------------------
define command{
        command_name    jabber-host-event-handler
        command_line    /usr/local/bin/nagios-jabber-event-handler "$SERVICESTATE$" "$STATETYPE$" "$SERVICEATTEMPT$" "jabber.sell.com/announce/online" "$HOSTALIAS$" "$SERVICEDESC$" "at $DATETIME$: $HOSTADDRESS$; $OUTPUT$"
        }


define command{
        command_name    jabber-service-event-handler
        command_line    /usr/local/bin/nagios-jabber-event-handler "$HOSTSTATE$" "$STATETYPE$" "$HOSTATTEMPT$" "jabber.sell.com/announce/online" "$HOSTALIAS$" "none" "at $DATETIME$: $HOSTADDRESS$; $OUTPUT$"
        }
------------------------------------------------------------------------------------------


-- 
Shane Allen <shane at emphasys.net>
http://www.emphasys.net


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list