Skip to content

Commit

Permalink
Merge pull request #31 from honzatlusty/master
Browse files Browse the repository at this point in the history
add check_zmstatus.pl
  • Loading branch information
honzatlusty committed Aug 18, 2016
2 parents 0cb9c19 + bc6dac1 commit 72b84c5
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -279,6 +279,12 @@ An example Vagrant project has been included to get you started right away.
<td><a href="https://github.com/honzatlusty">Jan Tlusty</a></td>
<td><a href="https://github.com/honzatlusty/nagios-rabbitmq-sync">upstream</a></td>
</tr>
<tr>
<td>check_zmstatus</td>
<td><a href="https://github.com/gmykhailiuta">gmykhailiuta</a></td>
<td><a href="https://raw.githubusercontent.com/gmykhailiuta/check_zmstatus/master/check_zmstatus.pl">upstream</a></td>
</tr>




Expand Down
1 change: 1 addition & 0 deletions build.txt
Expand Up @@ -60,5 +60,6 @@ check_topology 1.0
check_zookeeper 1.0
check_fileage.py 1.0
check_rabbitmq-sync.rb 1.0
check_zmstatus.pl 1.0

# vim: set ts=2 sw=2 et : #
78 changes: 78 additions & 0 deletions check_zmstatus.pl
@@ -0,0 +1,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";
}

0 comments on commit 72b84c5

Please sign in to comment.