Skip to content

Instantly share code, notes, and snippets.

@ramunasd
Created December 10, 2012 11:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramunasd/4250103 to your computer and use it in GitHub Desktop.
Save ramunasd/4250103 to your computer and use it in GitHub Desktop.
Zabbix GTalk alert script
#!/usr/bin/perl
use strict;
use warnings;
use Net::Jabber;
use POSIX qw(strftime);
my $recip = shift @ARGV;
my $mensaje = join ("\n",@ARGV);
my $room = "";
if ($recip=~m/\@conference/)
{
($room)=$recip=~m/(.*)\@conference/;
}
my $jserver="talk.google.com";
my $jport="5222";
my $domain="gmail.com.";
my $user="user.name"; # gtalk user authentication
my $pass="my.password";
my $nick="Zabbix";
my $component="my.domain";
my $con = new Net::Jabber::Client();
sub Msg($) {
chomp($_[0]);
if ($room)
{
$con->MessageSend(to=>$recip, type=>"groupchat", body=>$_[0]);
} else {
$con->MessageSend(to=>$recip, type=>"chat", body=>$_[0]);
}
}
$con->Connect(hostname=>$jserver,port=>$jport,connectiontype=>'tcpip', tls=>'1',componentname=>$component) or die "can't connect ($!)";
my @result = $con->AuthSend(username=>$user, password=>$pass, domain=>$domain, resource=>"$0-$$");
if ($result[0] ne "ok") {
die "Ident/Auth with server failed: $result[0] - $result[1]\n";
}
$con->RosterGet(); # tell server to send presence info
$con->PresenceSend(); # tell world that we are logged in
if ($room)
{
$con->MUCJoin(room=>$room, server=>"conference.$jserver", nick=>($nick||$user));
}
Msg($mensaje);
sleep 1;
$con->Disconnect();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment