forked from johnbertrand/Check_Gluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_gluster.pl
executable file
·79 lines (60 loc) · 1.67 KB
/
check_gluster.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
#!/usr/bin/perl
use strict;
use Nagios::Plugin;
use Nagios::Plugin::Functions;
use Nagios::Plugin::Getopt;
#Check_GLuster.pl
#John C. Bertrand <[email protected]>
# This nagios plugins checks the status
# and checks to see if the volume has the correct
# number of bricks
# Checked against gluster 3.2.7
# Rev 1 2012.09.12
#SET THESE
my $SUDO="/usr/bin/sudo";
my $GLUSTER="/usr/sbin/gluster";
my $opts = Nagios::Plugin::Getopt->new(
usage => "Usage: %s -v --volume Volume_Name -n --numbricks",
version => Nagios::Plugin::->VERSION,
blurb => 'checks the volume state and brick count in gluster fs'
);
$opts->arg(
spec => 'volume|v=s',
help => 'Volume name',
required => 1,
);
$opts->arg(
spec => 'numberofbricks|n=i',
help => 'Target number of bricks',
required => 1,
);
$opts->getopts;
my $volume=$opts->get("volume");
my $bricktarget=$opts->get("numberofbricks");
my $returnCode=UNKNOWN;
my $returnMessage="~";
my $result=`$SUDO $GLUSTER volume info $volume`;
if ($result =~ m/Status: Started/){
if ($result =~ m/Number of Bricks: (\d+)/){
my $bricks=$1;
if ($bricks != $bricktarget){
$returnCode=CRITICAL;
$returnMessage="Brick count is $bricks, should be $bricktarget";
}else{
$returnCode=OK;
$returnMessage="Volume $volume is Stable";
}
}else{
$returnCode=CRITICAL;
$returnMessage="Could not grep bricks";
}
}elsif($result =~ m/Status: (\S+)/){
$returnCode=CRITICAL;
$returnMessage="Volume Status is $1";
}else{
$returnCode=CRITICAL;
$returnMessage="Could not grep Status $result for $volume";
}
Nagios::Plugin->new->nagios_exit(return_code => $returnCode,
message => $returnMessage
);