zabbix jabber message sending

Posted by Evil Uncle Edd
In Uncategorized
8Jul 07

well, today seems like write the friggin manual day.

I needed to get zabbix, a monitoring system, to send me a jabber message when there is an issue
the built in jabber doesnt work

I found a perl script to send messages from the command line here :
http://mailman.jabber.org/pipermail/jadmin/2002-October/081380.html

I modified it abit to take in arguments as they come from the zabbix server.
and also to make it send messages in chat form

here fillows the script(well, at the end)
save it as jab.pl
put it in the directory defined by AlertScriptsPath

run the following commands on the file
You probably need to be root to do this

chown zabbix jab.pl
chgrp zabbix jab.pl
chmod 777 jab.pl
and change the values of
<server>
<user>
and
<password>

then you go to the zabbix webinterface, and go to media types
change the existing jabber media type, to a script
and where it says script name type jab.pl

thats it.
then you can configure your users contact info.
and tell zabbis what you want it to send to that user
and bob is your aunt.

anyhow here follows the script
(everything below the hashes

Ifyou find it usefull, please post a message below
if you have an issue, post a message below and ill see if i can help
Cheers

Edd
######################3

#!/usr/bin/perl
use strict;
use Net::Jabber qw( Client );
use constant SERVER => ‘<server>’;
use constant PORT => 5222; # Port to connect to
use constant USER => ‘<user>’;
use constant PASSWORD => ‘<password>’;
use constant RESOURCE => ‘perlscript’;

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 $date = dtg(time);
my $bbmessage = $ARGV[2];
my $bbsubject = $ARGV[1];
my $bbrecipient = $ARGV[0];
my $msg = Net::Jabber::Message->new();
$msg->SetMessage( “to” => $bbrecipient,
“body” => join(”\n”,”$bbsubject”,”$bbmessage”) );
$msg->SetType(”chat”);

$connection->Send($msg);
$connection->Disconnect();
exit;

sub dtg {
my ($string) = @_;
my ($time_str);
$time_str = localtime($string);
return substr($time_str,4,15);
}


Subscribe to RSS

Syndicate