[wellylug] Jaber.pl script plus how it worked! :)

Chris Hodgetts chris at archnetnz.com
Mon May 3 14:32:50 NZST 2004


Have yet to try in side the nagios misc command line, but from the
command line the $'Testing \n does this work thinggie worked like a
charm.

Anyway, here is the jabber.pl script, it's also available from the
nagios website 

##Start of Script##

#!/usr/bin/perl
#
# Author David Cox
# Created from various code examples found on the web
# Last Modified 08/06/2002
# 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 2) {
   die "Usage...\n notify [jabberid] [message]\n";
}
                                                                                                                                                  
my @field=split(/,/,$ARGV[0]);
                                                                                                                                                  
use constant RECIPIENT => $ARGV[0];
use constant SERVER    => 'jabber server ';
use constant PORT      => 5222;
use constant USER      => 'username';
use constant PASSWORD  => 'password';
use constant RESOURCE  => 'resource';
use constant MESSAGE   => $ARGV[1];
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 );foreach ( @field ) {
   my $message = Net::Jabber::Message->new();
   $message->SetMessage( "to"           => $_,
                         "subject"      => "Nagios Notification",
                         "type"         => "chat",
                         "body"         => MESSAGE);
                                                                                                                                                  
   $connection->Send($message);
   sleep(MAXWAIT);
}
$connection->Disconnect();
exit;

if ($result[0] ne "ok") {
 die "Ident/Auth with server failed: $result[0] - $result[1]\n";
}

## End of Script##









-- 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.wellylug.org.nz/pipermail/wellylug/attachments/20040503/773ab5b8/attachment.pgp 


More information about the wellylug mailing list