]> git.uio.no Git - uio-zabbix.git/commitdiff
Add jabber_send
authorRafael Martinez Guerrero <rafael@postgresql.org.es>
Wed, 25 Mar 2015 09:50:27 +0000 (10:50 +0100)
committerRafael Martinez Guerrero <rafael@postgresql.org.es>
Wed, 25 Mar 2015 09:50:27 +0000 (10:50 +0100)
jabber_send [new file with mode: 0755]

diff --git a/jabber_send b/jabber_send
new file mode 100755 (executable)
index 0000000..22d0e38
--- /dev/null
@@ -0,0 +1,59 @@
+#!/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="chat.uio.no";
+my $jport="5222";
+my $domain="chat.uio.no.";
+my $user="zabbix-prod"; # gtalk user authentication
+my $pass="x/bVBC*A";
+
+my $nick="Zabbix-prod";
+my $component="chat.uio.no";
+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();