From c03c1024655e36b50ba9bc1d91b3c0157ef9658e Mon Sep 17 00:00:00 2001 From: Florian Panzer Date: Mon, 16 Mar 2015 12:00:43 +0100 Subject: [PATCH 1/5] Compatibility fix for gluster Version 3.x improved regex for getting the brick count --- check_gluster.pl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/check_gluster.pl b/check_gluster.pl index 48e9bf6..2d4e336 100755 --- a/check_gluster.pl +++ b/check_gluster.pl @@ -7,11 +7,12 @@ #Check_GLuster.pl #John C. Bertrand +#Florian Panzer # 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 +# Rev 2 2015.03.16 #SET THESE my $SUDO="/usr/bin/sudo"; @@ -47,7 +48,7 @@ my $result=`$SUDO $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){ From 474bd8e1bca69cdd6fea304b1f232f73d5721307 Mon Sep 17 00:00:00 2001 From: Sebastian Gumprich Date: Thu, 4 Feb 2016 14:52:05 +0100 Subject: [PATCH 2/5] add option to toggle sudo --- check_gluster.pl | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/check_gluster.pl b/check_gluster.pl index 2d4e336..141be35 100755 --- a/check_gluster.pl +++ b/check_gluster.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/perl use strict; use Nagios::Plugin; @@ -8,7 +8,7 @@ #Check_GLuster.pl #John C. Bertrand #Florian Panzer -# This nagios plugins checks the status +# 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 and 3.6.2 @@ -19,9 +19,9 @@ 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", version => Nagios::Plugin::->VERSION, - blurb => 'checks the volume state and brick count in gluster fs' + blurb => 'checks the volume state and brick count in gluster fs' ); $opts->arg( @@ -36,31 +36,44 @@ required => 1, ); +$opts->arg( + spec => 'sudo|s', + help => 'Use sudo', + required => 0, + default => 0, +); + $opts->getopts; my $volume=$opts->get("volume"); my $bricktarget=$opts->get("numberofbricks"); - +my $use_sudo=$opts->get("sudo"); my $returnCode=UNKNOWN; my $returnMessage="~"; -my $result=`$SUDO $GLUSTER volume info $volume`; +my $result= 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+)/){ 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"; + }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; @@ -75,6 +88,3 @@ Nagios::Plugin->new->nagios_exit(return_code => $returnCode, message => $returnMessage ); - - - From ed02bd79a91ba4061e31eee2b727316bf2c40cd0 Mon Sep 17 00:00:00 2001 From: Florian Panzer Date: Thu, 4 Feb 2016 15:35:02 +0100 Subject: [PATCH 3/5] Added mention of sudo-switch to the readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 188984b..08b9765 100644 --- a/README.md +++ b/README.md @@ -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# ``` From 14ca5d4fc37a6bacaead46de8071112050036c42 Mon Sep 17 00:00:00 2001 From: Sebastian Gumprich Date: Tue, 22 Mar 2016 12:50:41 +0100 Subject: [PATCH 4/5] add split-brain check --- check_gluster.pl | 61 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/check_gluster.pl b/check_gluster.pl index 141be35..dd33252 100755 --- a/check_gluster.pl +++ b/check_gluster.pl @@ -1,27 +1,29 @@ #!/usr/bin/perl +use warnings; use strict; use Nagios::Plugin; use Nagios::Plugin::Functions; use Nagios::Plugin::Getopt; #Check_GLuster.pl -#John C. Bertrand -#Florian Panzer +# John C. Bertrand +# Florian Panzer +# Sebastian Gumprich # 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 and 3.6.2 -# Rev 2 2015.03.16 +# Rev 3 2016.03.22 #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 -s --sudo", + 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( @@ -38,7 +40,14 @@ $opts->arg( spec => 'sudo|s', - help => 'Use sudo', + help => 'use sudo', + required => 0, + default => 0, +); + +$opts->arg( + spec => 'split-brain|b', + help => 'check for split-brain', required => 0, default => 0, ); @@ -48,16 +57,19 @@ 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="~"; +# Check for cluster state my $result= undef; +my $heal = undef; if ($use_sudo == 1) { - $result=`$SUDO $GLUSTER volume info $volume`; + $result=`$SUDO $GLUSTER volume info $volume`; }else { - $result=`$GLUSTER volume info $volume`; + $result=`$GLUSTER volume info $volume`; } if ($result =~ m/Status: Started/){ @@ -65,26 +77,41 @@ 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 ); From 30b22612606d1159ee5faf9763136020462ddcd4 Mon Sep 17 00:00:00 2001 From: Florian Panzer Date: Wed, 27 Jul 2016 15:25:06 +0200 Subject: [PATCH 5/5] Now also checked against glusterfs 3.8.1 Now also checked against glusterfs 3.8.1 --- check_gluster.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/check_gluster.pl b/check_gluster.pl index dd33252..6ffd0a7 100755 --- a/check_gluster.pl +++ b/check_gluster.pl @@ -13,8 +13,8 @@ # 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 and 3.6.2 -# Rev 3 2016.03.22 +# 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";