Last active
September 25, 2016 15:49
-
-
Save seidler2547/077eca8b0ce13335d1b6e4258a845896 to your computer and use it in GitHub Desktop.
Hangouts notifications for Zabbix and Icinga
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Net::Jabber; | |
use POSIX qw(strftime); | |
my %vars = map { s/^ICINGA//; $_=>$ENV{"ICINGA$_"} } grep /^ICINGA.+/, keys %ENV; | |
my $recip = $ENV{'JABBERADDRESS'}; | |
my $message = ""; | |
if ($vars{SERVICESTATE}) { | |
$message .= "$vars{NOTIFICATIONTYPE} - $vars{HOSTDISPLAYNAME} - $vars{SERVICEDISPLAYNAME} is $vars{SERVICESTATE}\n"; | |
$message .= "$vars{SERVICEDESC} on $vars{HOSTALIAS} said: $vars{SERVICEOUTPUT}\n"; | |
} else { | |
$message .= "$vars{NOTIFICATIONTYPE} - $vars{HOSTDISPLAYNAME} is $vars{HOSTSTATE}\n"; | |
$message .= "$vars{HOSTALIAS} at $vars{HOSTADDRESS} said: $vars{HOSTOUTPUT}\n"; | |
} | |
if ($vars{NOTIFICATIONCOMMENT}) { | |
$message .= "$vars{NOTIFICATIONAUTHORNAME} wrote: $vars{NOTIFICATIONCOMMENT}\n"; | |
} | |
$message .= "at $vars{LONGDATETIME}"; | |
my $room = ""; | |
if ($recip=~m/\@conference/) { | |
($room)=$recip=~m/(.*)\@conference/; | |
} | |
my $jserver="talk.google.com"; | |
my $jport="5222"; | |
my $domain='gmail.com'; | |
my $user="google_email_before_at"; # gtalk user authentication | |
my $pass='google_password'; | |
my $nick="Icinga Alert"; | |
my $con = new Net::Jabber::Client(); | |
my $status = $con->Connect( | |
hostname => $jserver, | |
port => $jport, | |
connectiontype => 'tcpip', | |
tls => '1', | |
componentname => $domain, | |
ssl_ca_path => '/etc/ssl/certs'); | |
defined $status or die "can't connect ($!)"; | |
$con->{STREAM}{SIDS}{$con->{SESSION}{id}}{hostname} = 'gmail.com'; | |
my @result = $con->AuthSend(username => $user, password => $pass, resource => 'NotificationBot'); | |
$result[0] eq "ok" or Stop("$result[0] $result[1]"); | |
$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)); | |
$con->MessageSend(to => $recip, type => 'groupchat', body => $message); | |
} else { | |
print $con->MessageSend(to => $recip, type => 'chat', body => $message); | |
print join("\t", @result)."\n"; | |
} | |
sleep 2; | |
$con->Disconnect(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# Put in /etc/zabbix/alertscripts/zgtalk.pl and configure | |
# as media in Zabbix. Use your Google Talk ID (......@public.talk.google.com). | |
use strict; | |
use warnings; | |
use Net::Jabber; | |
use POSIX qw(strftime); | |
my $recip = shift @ARGV; | |
my $message = 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="google_email_before_at"; # gtalk user authentication | |
my $pass='google_password'; | |
my $nick="Zabbix Alert"; | |
my $con = new Net::Jabber::Client(); | |
my $status = $con->Connect( | |
hostname => $jserver, | |
port => $jport, | |
connectiontype => 'tcpip', | |
tls => '1', | |
componentname => 'gmail.com', | |
ssl_ca_path => '/etc/ssl/certs'); | |
defined $status or die "can't connect ($!)"; | |
$con->{STREAM}{SIDS}{$con->{SESSION}{id}}{hostname} = 'gmail.com'; | |
my @result = $con->AuthSend(username => $user, password => $pass, resource => 'ZabbixBot'); | |
$result[0] eq "ok" or Stop("$result[0] $result[1]"); | |
my %roster = $con->RosterGet(); # tell server to send presence info | |
# to find out your Google Talk ID, start a chat on the web and | |
# uncomment this statement: | |
# print join("\n", keys %roster); | |
$con->PresenceSend(); # tell world that we are logged in | |
if ($room) { | |
$con->MUCJoin(room => $room, server => "conference.$jserver", nick => ($nick||$user)); | |
$con->MessageSend(to => $recip, type => 'groupchat', body => $message); | |
} else { | |
$con->MessageSend(to => $recip, type => 'chat', body => $message); | |
} | |
sleep 2; | |
$con->Disconnect(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment