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