Portál AbcLinuxu, 10. listopadu 2025 02:19
Ma niekto z Vas rozbehane notifikacie v nagiose cez jabber?
Vdaka
#!/usr/bin/perl
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 => 'jabberserver.domain.tld';
use constant PORT => 5222;
use constant USER => 'username';
use constant PASSWORD => 'password';
use constant RESOURCE => 'libovolny';
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;
Potom si pridas ke kontaktu:
service_notification_commands notify-service-by-jabber host_notification_commands notify-host-by-jabber pager jabberuid@jabber.wtfA vytvoris novy command (format dle libosti):
define command{
command_name notify-service-by-jabber
command_line notify_via_jabber.pl $CONTACTPAGER$ " \
\**** JABBER Nagios *****
\ervice: $SERVICEDESC$
\ervicestate: $SERVICESTATE$
\ost: $HOSTNAME$
Date/Time: $LONGDATETIME$"
}
Pouzivam to dlouho a spolehlive.
Vdaka. Este som sa chcel spytat co tam treba do toho skriptu doplnit, len meno, heslo a jabber server? Ci aj nieco ine? Vdaka
use constant SERVER => 'jabberserver.domain.tld'; use constant USER => 'username'; use constant PASSWORD => 'password'; use constant RESOURCE => 'libovolny';Napr:
use constant SERVER => 'njs.netlab.cz'; use constant USER => 'franta'; use constant PASSWORD => 'tajne_heslo'; use constant RESOURCE => 'nagios_na_serveru';Pak uz jen staci skript spustit:
./notify_via_jabber.pl prijemce@jabbim.cz ahoj
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.