среда, 30 ноября 2011 г.

Zabbix XMPP(типа Jabber) Скрипт для отправки в Openfire

  • убедимся, что переменная не закомментированна и пройдем в этот каталог
# Location for custom alert scripts
AlertScriptsPath=/etc/zabbix/alert.d/

  • создадим скрипт jabber в папке alert.d и назначим права на выполнение
  • поставим все необходимые модули perl(perl -MCPAN -e shell и install Net::XMPP).
  • также надо закомментить sasl в perl если будет выдавать ошибки.

#! /usr/bin/perl
use Net::XMPP;
use utf8;

my $to = $ARGV[0];
my $subj = $ARGV[1];
my $body = $ARGV[2];
my $type = $ARGV[3];

if (!defined($type)) {
$type = 'headline';
}

my $s = utf8::decode($subj);
my $b = utf8::decode($body);

my $hostName = 'server';
my $portNumber = 5222;
my $componentName = '';
my $userName = 'zabbix';
my $passWord = 'pass';
my $resource = 'Kbkv6';
my $tls = 0;
my $connectionType = 'tcpip';

my $debugLevel = 0;
my $bot = new Net::XMPP::Client(
debuglevel => $debugLevel
);

$bot->SetCallBacks(
onconnect => \&connectedCB,
onauth => \&authedCB,
ondisconnect => \&disconnectedCB
);

$bot->Execute(
hostname => $hostName,
port => $portNumber,
tls => $tls,
username => $userName,
password => $passWord,
resource => $resource,
register => 0,
connectiontype => $connectionType
);

sub connectedCB {
print "Connected\n";
}

sub authedCB {
print "Authed\n";
$bot->PresenceSend;

$bot->MessageSend(
to => $to,
subject => $subj,
body => $body,
type => 1
);

print "Sended\n";
$bot->Disconnect();
}

sub disconnectedCB {
print "Disconnected\n";
}

0 коммент.:

Отправить комментарий