Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility fix for gluster Version 3.x #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ Nagios health check for GlusterFS 3.3. It checks a volumes status, and if all t

#CLI Usage#
```
nagios@monitor:~/> ./check_gluster.pl -v data -n 2
nagios@monitor:~/> ./check_gluster.pl -v data -n 2 [-s|--sudo]
GLUSTER OK - Volume data is Stable
```
Where -v is the volume name, and -n is the expected number of bricks.
If you want your privileges escalated, use -s or --sudo respectively.

#Called via NRPE#
```
Expand Down
84 changes: 61 additions & 23 deletions check_gluster.pl
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
#!/usr/bin/perl
#!/usr/bin/perl

use warnings;
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
# John C. Bertrand <[email protected]>
# Florian Panzer <[email protected]>
# Sebastian Gumprich <[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
# Checked against gluster 3.2.7 and 3.6.2 and 3.8.1
# Rev 4 2016.07.27

#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",
usage => "Usage: %s -v --volume Volume_Name -n --numbricks -s --sudo -b --split-brain",
version => Nagios::Plugin::->VERSION,
blurb => 'checks the volume state and brick count in gluster fs'
blurb => 'checks the volume state, brick count and split-brain state of GlusterFS.'
);

$opts->arg(
Expand All @@ -35,45 +38,80 @@
required => 1,
);

$opts->arg(
spec => 'sudo|s',
help => 'use sudo',
required => 0,
default => 0,
);

$opts->arg(
spec => 'split-brain|b',
help => 'check for split-brain',
required => 0,
default => 0,
);

$opts->getopts;

my $volume=$opts->get("volume");
my $bricktarget=$opts->get("numberofbricks");

my $use_sudo=$opts->get("sudo");
my $check_sb=$opts->get("split-brain");

my $returnCode=UNKNOWN;
my $returnMessage="~";

my $result=`$SUDO $GLUSTER volume info $volume`;
# Check for cluster state
my $result= undef;
my $heal = undef;

if ($use_sudo == 1) {
$result=`$SUDO $GLUSTER volume info $volume`;
}else {
$result=`$GLUSTER volume info $volume`;
}

if ($result =~ m/Status: Started/){
if ($result =~ m/Number of Bricks: (\d+)/){
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";
}
$returnCode=CRITICAL;
$returnMessage="Brick count is $bricks, should be $bricktarget";
}
elsif ($check_sb == 1){
# Check for split-brain
if ($use_sudo == 1) {
$heal=`$SUDO $GLUSTER volume heal $volume info`;
}
else {
$heal=`$GLUSTER volume heal $volume info`;
}
if ($heal !~ m/Number of entries: 0/){
$returnCode=CRITICAL;
$returnMessage="Failed replication between cluster members. Possible split-brain!";
} else {
$returnCode=OK;
$returnMessage="Volume $volume is stable";
}
} else {
$returnCode=OK;
$returnMessage="Volume $volume is stable";
}
}else{
$returnCode=CRITICAL;
$returnMessage="Could not grep bricks";
$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
);