Automatically update website with --help output. Cosmetic
[monitoring-plugins.git] / contrib / nagios_sendim.pl
blob02870a6d9440f4dd644bf5862610759ba6abc6b1
1 #!/usr/bin/perl -w
3 # SENDIM 1.0 by Sergio Freire (sergio-s-freire@ptinovacao.pt)
4 # Nagios plugin to send notifications using instant messages through a jabber server
5 #
6 # Note: a) you can send messages to several different IM systems like ICQ,AIM,MSN,etc...
7 # b) to test this plugin you can execute it with the arguments needed and write the message followed by a CTRL+D
9 # Please check http://www.jabber.org and http://www.jabberstudio.org for more information on Jabber Instant Messaging
12 use Net::Jabber qw(Client);
13 use Getopt::Std;
15 my $tmp;
16 my $mensagem="";
17 getopts("u:p:t:");
18 if ( (!defined($opt_u)) || (!defined($opt_p)) || (!defined($opt_t)))
20 print "USE: sendim -u user_JID -p password -t destination_JID\n";
21 print 'EXAMPLE: sendim -u nagios@jabber.org -p nagios -t bitcoder@nagios.org'."\n";
22 print " (send an instant message as user nagios\@jabber.org to bitcoder\@jabber.org)\n";
23 exit;
26 my @buf=split('@',$opt_u);
27 my $login=$buf[0];
28 @buf=split('/',$buf[1]);
29 my $server=$buf[0];
30 my $resource=$buf[1] || "nagios";
31 my $password=$opt_p;
32 my $jid_dest=$opt_t;
33 my $debug=0; # Set debug=1 to enable output of debug information
35 while ($tmp=<STDIN>)
37 $mensagem.=$tmp;
40 print "LOGIN: $login\nSERVER: $server\nRESOURCE: $resource\n" if $debug;
41 print "TO: $jid_dest\n" if $debug;
43 $Con1 = new Net::Jabber::Client();
44 $Con1->Connect(hostname=>$server);
46 if ($Con1->Connected()) {
47 print "CON1: We are connected to the server...\n" if $debug;
50 @result1 = $Con1->AuthSend(username=>$login,
51 password=>$password,
52 resource=>$resource);
55 $Con1->PresenceSend();
56 $Con1->Process(1);
58 @result1=$Con1->MessageSend( to=>$jid_dest,
59 subject=>"nagios",
60 body=>$mensagem,
61 type=>"chat",
62 priority=>1);
64 $Con1->Process(1);
65 $Con1->Disconnect();
66 exit;