User Tools

Site Tools


check_raid_mdstat.pl

check_raid_mdstat.pl

<toc></toc> Description:

Nagios plugin (current 1.x) that will return the status of a software raid device. <p><tt>check_raid_mdstat.pl md3</tt></p><p><em>Jan 5, 2005</em> Corrected bug where the status returned would be the status of the last device in the /proc/mdstat file instead of the device asked for.</p>

#!/usr/bin/perl -w

# Copyright (c) 2002 ISOMEDIA, Inc.
# Written by Steve Milton
# Modified by Ian Samuel, 2005
# Released under the GNU Public License
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# Usage:   check_raid &lt;raid-name&gt;
# Example: check_raid md0
#          WARNING md0 status=[UUU_U], recovery=46.4%, finish=123.0min

use strict;

my %ERRORS=('DEPENDENT'=&gt;4,'UNKNOWN'=&gt;3,'OK'=&gt;0,'WARNING'=&gt;1,'CRITICAL'=&gt;2);

open (MDSTAT, &quot;&lt;/proc/mdstat&quot;) or die &quot;Failed to open /proc/mdstat&quot;;
my $found = 0;
my $status = &quot;&quot;;
my $recovery = &quot;&quot;;
my $finish = &quot;&quot;;
my $active = &quot;&quot;;
while(&lt;MDSTAT&gt;) {
    if (/$ARGV[0]/) {
        $found = 1;
        if (/active/) {
            $active = 1;
        }
        $_ = &lt;MDSTAT&gt;;
        if (/(\[[_U]+\])/) {
            $status = $1;
        }
        $_ = &lt;MDSTAT&gt;;
        if (/recovery = +(.*?)\s/) {
        $recovery = $1;
            ($finish) = /finish=(.*?min)/;
        }
        last;
    }
}

my $msg = &quot;FAILURE&quot;;
my $code = &quot;UNKNOWN&quot;;
if ($status =~ /_/) {
    if ($recovery) {
        $msg = sprintf &quot;%s status=%s, recovery=%s, finish=%s\n&quot;,
        $ARGV[0], $status, $recovery, $finish;
        $code = &quot;WARNING&quot;;
    } else {
        $msg = sprintf &quot;%s status=%s\n&quot;, $ARGV[0], $status;
        $code = &quot;CRITICAL&quot;;
    }
} elsif ($status =~ /U+/) {
    $msg = sprintf &quot;%s status=%s\n&quot;, $ARGV[0], $status;
    $code = &quot;OK&quot;;
} else {
    if ($active) {
        $msg = sprintf &quot;%s active with no status information.\n&quot;,
        $ARGV[0];
        $code = &quot;OK&quot;;
    } else {
        $msg = sprintf &quot;%s does not exist.\n&quot;, $ARGV[0];
        $code = &quot;CRITICAL&quot;;
    }
}

print $code, &quot; &quot;, $msg;
exit ($ERRORS{$code});
check_raid_mdstat.pl.txt · Last modified: 2020/02/13 22:55 (external edit)

free spam filter