From a010e0f9b8134529188ebc771104fdfdb137692a Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Mon, 31 Mar 2008 09:32:09 +0000 Subject: Return warn on running rsync git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@325 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede --- nagios-check-raid.pl | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'nagios-check-raid.pl') diff --git a/nagios-check-raid.pl b/nagios-check-raid.pl index 504d622..7919e26 100755 --- a/nagios-check-raid.pl +++ b/nagios-check-raid.pl @@ -15,6 +15,7 @@ # ------------------------------------------------------------------------------ # Date Author Reason # ---- ------ ------ +# 2008-03-31 Peter Palfrader Return warning on running resync # 2007-11-07 Peter Palfrader Return unknown if /proc/mdstat does not exist # 05/10/2004 Peter Palfrader Make it work without that 'use util (vars)' # 14/06/2003 TN Initial Release @@ -39,7 +40,7 @@ sub print_usage (); $ENV{'PATH'}=''; $ENV{'BASH_ENV'}=''; $ENV{'ENV'}=''; -my ( $line, $prevline, $stat, $state ,@device, $msg, $status, $timeout); +my ( $line, $stat, $state ,@device, $msg, $status, $timeout); $stat="/proc/mdstat"; @@ -86,20 +87,33 @@ open (FH, $stat) or print("UNKNOWN: Cannot open $stat: $!\n"), exit $ERRORS{'UNK $state = $ERRORS{'OK'}; $msg =""; +my @resyncing = (); +my $device = ''; + # Now check the mdstat file.. while () { - $line= $_; - if( $line =~ / \[_|_\]|U_|_U /) { + $line = $_; + if ($line =~ /^(md.*) /) { + $device = $0; + } elsif( $line =~ / \[_|_\]|U_|_U /) { $state = $ERRORS{'CRITICAL'}; - @device = split(/ /,$prevline); - $msg = $msg . $device[0] . ": - "; - } - $prevline = $line; + $msg = $msg . $device . ": - "; + } + elsif ( $line =~ / resync /) { + # [==>..................] resync = 10.3% (15216320/146994624) finish=2153.2min speed=1018K/sec + my ($percent) = ($line =~ m# resync = ([0-9.]+%)#); + my ($finish) = ($line =~ m# finish=([0-9.]+min)#); + my ($speed) = ($line =~ m# speed=([0-9.]+K/sec)#); + push @resyncing, "$device ($percent done, finish in $finish at $speed)"; + } } close (FH); if ( $state == $ERRORS{'CRITICAL'} ) { print "CRITICAL - Device(s) $msg have failed\n"; +} elsif ( scalar @resyncing > 0 ) { + print "WARNING: Resyncing: ".(join "; ", @resyncing)."\n"; + $state = $ERRORS{'WARNING'}; } elsif ( $state == $ERRORS{'OK'} ) { print "OK - All devices are online\n"; } exit $state; -- cgit v1.2.3