├── README └── nagios └── notify_via_jabber /README: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /nagios/notify_via_jabber: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | # 3 | # script for nagios notify via Jabber / Google Talk Instant Messaging 4 | # using XMPP protocol and SASL PLAIN authentication. 5 | # 6 | # author: Andrew Elwell 7 | # based on work by Thus0 and David Cox 8 | # 9 | # released under the terms of the GNU General Public License v2 10 | # Copyright 2007 Andrew Elwell. 11 | 12 | # Can only send msgs to users in the same domain 13 | 14 | use strict; 15 | use Net::XMPP; 16 | 17 | ## Configuration 18 | my $username = 'xxx'; 19 | my $password = "xxx"; 20 | my $resource = "nagios"; 21 | ## End of configuration 22 | 23 | 24 | my $len = scalar @ARGV; 25 | if ($len ne 2) { 26 | die "Usage...\n $0 [jabberid] [message]\n"; 27 | } 28 | my @field=split(/,/,$ARGV[0]); 29 | #------------------------------------ 30 | 31 | # Google Talk & Jabber parameters : 32 | 33 | my $hostname = 'talk.google.com'; 34 | my $port = 5222; 35 | my $componentname = 'napierala.org'; 36 | my $connectiontype = 'tcpip'; 37 | my $tls = 1; 38 | 39 | #------------------------------------ 40 | 41 | my $Connection = new Net::XMPP::Client(); 42 | 43 | # Connect to talk.google.com 44 | my $status = $Connection->Connect( 45 | hostname => $hostname, port => $port, 46 | componentname => $componentname, 47 | connectiontype => $connectiontype, tls => $tls); 48 | 49 | if (!(defined($status))) { 50 | print "ERROR: XMPP connection failed.\n"; 51 | print " ($!)\n"; 52 | exit(0); 53 | } 54 | 55 | # Change hostname 56 | my $sid = $Connection->{SESSION}->{id}; 57 | $Connection->{STREAM}->{SIDS}->{$sid}->{hostname} = $componentname; 58 | 59 | # Authenticate 60 | my @result = $Connection->AuthSend( 61 | username => $username, password => $password, 62 | resource => $resource); 63 | 64 | if ($result[0] ne "ok") { 65 | print "ERROR: Authorization failed: $result[0] - $result[1]\n"; 66 | exit(0); 67 | } 68 | 69 | # Send messages 70 | foreach ( @field ) { 71 | $Connection->MessageSend( 72 | to => "$_\@$componentname", 73 | resource => $resource, 74 | subject => "Notification", 75 | type => "chat", 76 | body => $ARGV[1]); 77 | } 78 | 79 | --------------------------------------------------------------------------------