-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_zmstatus.pl
executable file
·78 lines (63 loc) · 2 KB
/
check_zmstatus.pl
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
#!/usr/bin/perl -w
use strict;
use English;
use Getopt::Long;
#use File::stat;
sub print_help ();
sub print_usage ();
sub check_username ();
my ($opt_z, $opt_h, $opt_b, $opt_u);
my ($result, $message, @failed_services);
my $PROGNAME="check_zmstatus";
#default values
$opt_z='/opt/zimbra/bin/zmcontrol';
$opt_u='zimbra';
Getopt::Long::Configure('bundling');
GetOptions(
"h" => \$opt_h, "help" => \$opt_h,
"u=s" => \$opt_u, "username" => \$opt_u,
"b=s" => \$opt_z, "binary" => \$opt_z);
if ($opt_h) {
print_help();
exit;
}
$opt_z = shift unless ($opt_z);
# Check that binary exists
unless (-e $opt_z) {
print "CRITICAL: ZMStatus not found - $opt_z\n";
exit 2;
}
# open "zmcontrol status" command
open(ZMCONTROL, "sudo -u ".$opt_u." $opt_z status |") || die('zmcontrol not found');
my @zmcontent = <ZMCONTROL>;
close(ZMCONTROL);
my $i;
# parse every line exept the first
for ($i=1; $i<@zmcontent;$i++) {
if ($zmcontent[$i] =~ m/\s([a-zA-Z ]+)\s{2,}(\w+)/g) {
if ($2 ne "Running") {
push @failed_services, $1;
}
}
}
# $i tells if services where checked
if (( @failed_services == 0 ) && ($i > 5)) {
print "OK: every service is running fine\n";
exit 0; # OK
} else {
print "Critical: " . join(',', @failed_services) . " not running";
exit 2; # Error
}
sub print_usage () {
print "Usage:\n";
print " $PROGNAME [-u username] [-b zmstatuspath]\n";
print " $PROGNAME [-h | --help]\n";
}
sub print_help () {
print "Copyright (c) 2008 Andreas Roth\n\n";
print_usage();
print "\n";
print " <username> username for zimbrauser - be aware of setting up sudo before (default: zimbra)\n";
print " <zmstatuspath> Path where zmcontrol command is found (default: /opt/zimbra/bin/zmcontrol)\n";
print "\n";
}