jabber notification script

Emilio Casbas ecasbas at unav.es
Thu Jun 22 08:51:04 CEST 2006


Hi,

I set up nagios-notifications via jabber.
I used the notify_via_jabber script from David Cox found. It's a little 
perl script to transforms your message to a valid jabber message and 
sends it to the jabber-server.

Now, I made some enhancements to the script, so that you can add the 
subject as an argument from a nagios macro.
I think it could be interesting.

-------------------------------------
#!/usr/bin/perl
#
# Author David Cox
# Created from various code examples found on the web
# Last Modified 08/06/2002
# Added the subject as parameter from nagios
# Modified by Emilio Casbas on 21/06/2006
# Feel free to use or modify as needed to suit your needs
#######################################################
# MAXWAIT is used because the send message function didn't seem to
# like being called to fast. The message would be sent unless I waited a 
second
# or so. You can experiment with it but I just went with 2 seconds.
#######################################################

use strict;
use Net::Jabber qw(Client) ;
use Net::Jabber qw(Message) ;
use Net::Jabber qw(Protocol) ;
use Net::Jabber qw(Presence) ;

my $len = scalar @ARGV;

if ($len ne 3) {
   die "Usage...\n notify [jabberid] [message] [subject]\n";
}

my @field=split(/,/,$ARGV[0]);

use constant RECIPIENT => $ARGV[0];
use constant SERVER    => 'icaro.cti.unav.es';
use constant PORT      => 5222;
use constant USER      => 'nagios';
use constant PASSWORD  => 'ShJRRUQg';
use constant RESOURCE  => 'resource';
use constant MESSAGE   => $ARGV[1];
use constant MYSUBJECT   => $ARGV[2];
use constant MAXWAIT   => 2 ;

my $connection = Net::Jabber::Client->new();
$connection->Connect( "hostname" => SERVER,"port" => PORT )  or die
"Cannot connect ($!)\n";

my @result = $connection->AuthSend( "username" => USER,"password" =>
PASSWORD,"resource" => RESOURCE );
if ($result[0] ne "ok") {
 die "Ident/Auth with server failed: $result[0] - $result[1]\n";
}

foreach ( @field ) {
   my $message = Net::Jabber::Message->new();
   $message->SetMessage( "to"           => $_,
                         "subject"      => MYSUBJECT,
                         "type"         => "chat",
                         "body"         => MESSAGE);

   $connection->Send($message);
   sleep(MAXWAIT);
}
$connection->Disconnect();
exit;

-------------------------------------


Thanks
Emilio C.

All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
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