3 # Copyright (c) 2002 ISOMEDIA, Inc.
4 # originally written by Steve Milton
5 # later updates by sean finney <seanius@seanius.net>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # Usage: check_raid [raid-name]
22 # Example: check_raid md0
23 # WARNING md0 status=[UUU_U], recovery=46.4%, finish=123.0min
26 use lib
"/usr/local/nagios/libexec";
27 use utils
qw(%ERRORS);
29 # die with an error if we're not on Linux
31 print "This plugin only applicable on Linux.\n";
32 exit $ERRORS{'UNKNOWN'};
37 if ($a eq "CRITICAL" || $b eq "CRITICAL") { return "CRITICAL"; }
38 elsif ($a eq "WARNING" || $b eq "WARNING") { return "WARNING"; }
39 elsif ($a eq "OK" || $b eq "OK") { return "OK"; }
40 elsif ($a eq "UNKNOWN" || $b eq "UNKNOWN") { return "UNKNOWN"; }
41 elsif ($a eq "DEPENDENT" || $b eq "DEPENDENT") { return "DEPENDENT"; }
46 if(defined $ARGV[0]) { $nextdev = shift; }
47 else { $nextdev = "md[0-9]+"; }
57 while(defined $nextdev){
58 open (MDSTAT, "< /proc/mdstat") or die "Failed to open /proc/mdstat";
61 if (defined $device) {
63 $status{$device} = $1;
64 } elsif (/recovery = (.*?)\s/) {
65 $recovery{$device} = $1;
66 ($finish{$device}) = /finish=(.*?min)/;
70 } elsif (/^($nextdev)\s*:/) {
72 $devices{$device}=$device;
81 foreach my $k (sort keys %devices){
82 if ($status{$k} =~ /_/) {
83 if (defined $recovery{$k}) {
84 $msg .= sprintf " %s status=%s, recovery=%s, finish=%s.",
85 $devices{$k}, $status{$k}, $recovery{$k}, $finish{$k};
86 $code = max_state($code, "WARNING");
88 $msg .= sprintf " %s status=%s.", $devices{$k}, $status{$k};
89 $code = max_state($code, "CRITICAL");
91 } elsif ($status{$k} =~ /U+/) {
92 $msg .= sprintf " %s status=%s.", $devices{$k}, $status{$k};
93 $code = max_state($code, "OK");
96 $msg .= sprintf " %s active with no status information.\n",
98 $code = max_state($code, "OK");
100 $msg .= sprintf " %s does not exist.\n", $devices{$k};
101 $code = max_state($code, "CRITICAL");
106 print $code, $msg, "\n";
107 exit ($ERRORS{$code});