diff options
Diffstat (limited to 'web/attachments/131931-check_jabber.pl')
| -rw-r--r-- | web/attachments/131931-check_jabber.pl | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/web/attachments/131931-check_jabber.pl b/web/attachments/131931-check_jabber.pl new file mode 100644 index 0000000..1176441 --- /dev/null +++ b/web/attachments/131931-check_jabber.pl | |||
| @@ -0,0 +1,97 @@ | |||
| 1 | #!/usr/bin/perl -w | ||
| 2 | ################################################################## | ||
| 3 | # CHECK_JABBER.PL | ||
| 4 | # | ||
| 5 | # Jabber Plugin for Nagios | ||
| 6 | # License: GPL | ||
| 7 | # C.Doblado (cdoblado@pulsartec.com) | ||
| 8 | # check_jabber.pl, v1.0 2005/04/27 | ||
| 9 | # | ||
| 10 | ################################################################# | ||
| 11 | |||
| 12 | use strict; | ||
| 13 | use Getopt::Std; | ||
| 14 | use Net::Jabber qw(Client); | ||
| 15 | |||
| 16 | use lib "/usr/lib/nagios/plugins/"; | ||
| 17 | use utils qw($TIMEOUT %ERRORS &print_revision); | ||
| 18 | |||
| 19 | sub CheckJabber; | ||
| 20 | sub Help; | ||
| 21 | |||
| 22 | my $PROGNAME = "check_jabber"; | ||
| 23 | |||
| 24 | |||
| 25 | sub CheckJabber | ||
| 26 | { | ||
| 27 | my $host=shift; | ||
| 28 | my $port=shift; | ||
| 29 | my $result; | ||
| 30 | my $con= new Net::Jabber::Client(); | ||
| 31 | $con->Connect(hostname=>$host,port=>$port); | ||
| 32 | if ($con->Connected()){ | ||
| 33 | $result->{NUM}=1; | ||
| 34 | $result->{MSG}="Jabber server OK at port $port \n"; | ||
| 35 | $con->Disconnect(); | ||
| 36 | } | ||
| 37 | else { | ||
| 38 | $result->{NUM}=0; | ||
| 39 | $result->{MSG}="Jabber server Error at port $port \n"; | ||
| 40 | } | ||
| 41 | return $result; | ||
| 42 | } | ||
| 43 | |||
| 44 | |||
| 45 | sub Help | ||
| 46 | { | ||
| 47 | print_revision($PROGNAME, '$Revision: 1.0 $'); | ||
| 48 | print "\nCheckjabber checks the Jabber server status\n"; | ||
| 49 | print "Usage: checkjabber.pl -s server [-p port -v version -h help] \n"; | ||
| 50 | print " (default port is 5222) \n\n"; | ||
| 51 | } | ||
| 52 | |||
| 53 | |||
| 54 | ##### Main ##### | ||
| 55 | |||
| 56 | # TIMEOUT alarm | ||
| 57 | $SIG{'ALRM'} = sub { | ||
| 58 | print ("ERROR: No response from server (alarm timeout)\n"); | ||
| 59 | exit $ERRORS{"UNKNOWN"}; | ||
| 60 | }; | ||
| 61 | alarm($TIMEOUT); | ||
| 62 | |||
| 63 | |||
| 64 | # Arguments | ||
| 65 | my %options=(); | ||
| 66 | getopts("s:p:h:v",\%options); | ||
| 67 | |||
| 68 | |||
| 69 | # Options | ||
| 70 | if (defined $options{s}){ | ||
| 71 | if (not defined $options{p}){ | ||
| 72 | $options{p}='5222'; # default Jabber port | ||
| 73 | } | ||
| 74 | my $status=CheckJabber($options{s},$options{p}); | ||
| 75 | print "$status->{MSG}\n"; | ||
| 76 | if ($status->{NUM}==1) { | ||
| 77 | exit $ERRORS{"OK"}; | ||
| 78 | } | ||
| 79 | elsif ($status->{NUM}==0) { | ||
| 80 | exit $ERRORS{"CRITICAL"}; | ||
| 81 | } | ||
| 82 | else { | ||
| 83 | exit $ERRORS{"UNKNOWN"}; | ||
| 84 | } | ||
| 85 | } | ||
| 86 | elsif ($options{v}) { | ||
| 87 | print_revision($PROGNAME, '$Revision: 1.0 $'); | ||
| 88 | exit $ERRORS{"UNKNOWN"}; | ||
| 89 | } | ||
| 90 | else { | ||
| 91 | Help; | ||
| 92 | exit $ERRORS{"UNKNOWN"}; | ||
| 93 | } | ||
| 94 | |||
| 95 | |||
| 96 | |||
| 97 | |||
