Last active
April 9, 2016 11:40
-
-
Save smitmartijn/5e2e68fa69c56db3466b009ce39e9efd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# Check Gluster volume status and number of present bricks | |
# | |
# Requires edits to /etc/sudoers: | |
# Defaults:epops !requiretty | |
# epops ALL=NOPASSWD: /usr/sbin/gluster volume info* | |
use strict; | |
use Getopt::Long qw(GetOptions); | |
sub usage { | |
print "Usage: $0 --volume VolumeName --numberofbricks ExpectedBricks\n"; | |
exit; | |
} | |
# Options check! | |
my $gluster_volume; | |
my $gluster_nobricks; | |
GetOptions( | |
'volume=s' => \$gluster_volume, | |
'numberofbricks=i' => \$gluster_nobricks, | |
) or die usage(); | |
if(!$gluster_volume || !$gluster_nobricks) { | |
usage(); | |
} | |
my $returnError = 1; | |
my $returnOK = 0; | |
# Grab volume info | |
my $result = `/usr/bin/sudo /usr/sbin/gluster volume info $gluster_volume`; | |
if ($result =~ m/Status: Started/) | |
{ | |
if ($result =~ m/Number of Bricks: (\d+) x (\d+) \= (\d+)/) | |
{ | |
my $bricks = $3; | |
if ($bricks != $gluster_nobricks) | |
{ | |
# Unexpected number of bricks | |
exit $returnError; | |
} | |
else { | |
# Healthy number of bricks | |
exit $returnOK; | |
} | |
} | |
else { | |
# Could not find any bricks | |
exit $returnError; | |
} | |
} | |
elseif ($result =~ m/Status: (\S+)/) | |
{ | |
# Volume status not 'Started' | |
exit $returnError; | |
} | |
else { | |
# No information?! | |
exit $returnError; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment