Notifications via jabber

Fred Jordan fjordan at hcssun01.hcs.net
Fri May 9 17:25:02 CEST 2003


Have found the following two perl scripts, notify-by-jabber.pl
and notify-via-jabber.pl. Have notify-by-jabber.pl working
just fine; it sends a motd message which all can see. However
notify-via-jabber.pl doesn't seem to work. The user never gets
the message. Have others had to modify this script 2nd script
in order to get it to work?

Even better, how about a notification script that could send
to all perticipants of a conference on the jabber server? I
just do not know enough about jabber to fix this problem or
to modify eithor script to be able to send to all participants
of a conference on the jabber server.

					Thanks Much,
						Fred Jordan
notify-by-jabber.pl
#!/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;

use constant RECIPIENT => 'my.jabber.server/announce/motd';
use constant SERVER    => 'my.jabber.server';
use constant PORT      => 5222;
use constant USER      => 'nagios-id';
use constant PASSWORD  => 'nagios-pw';
use constant RESOURCE  => 'telnet';
use constant MESSAGE   => <STDIN>;
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";
}

           my $message = Net::Jabber::Message->new();
           $message->SetMessage( "to"           =>
"stats.hcs.net/announce/
motd",
                                 "body"         => MESSAGE);

           $connection->Send($message);
           sleep(MAXWAIT);

$connection->Disconnect();
exit;



notify-via-jabber.pl
#!/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    => 'my.jabber.server';
use constant PORT      => 5222;
use constant USER      => 'nagios-id';
use constant PASSWORD  => 'nagios-pw';
use constant RESOURCE  => 'telnet';
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 );
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"      => "Notification",
                        "type"         => "chat",
                        "body"         => MESSAGE);

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




-------------------------------------------------------
Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara
The only event dedicated to issues related to Linux enterprise solutions
www.enterpriselinuxforum.com

_______________________________________________
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