summaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'contrib')
-rw-r--r--contrib/check_linux_raid.pl126
1 files changed, 74 insertions, 52 deletions
diff --git a/contrib/check_linux_raid.pl b/contrib/check_linux_raid.pl
index 2a58dbe0..85d5dc4a 100644
--- a/contrib/check_linux_raid.pl
+++ b/contrib/check_linux_raid.pl
@@ -1,8 +1,8 @@
1#!/usr/bin/perl -w 1#!/usr/bin/perl -w
2 2
3# Copyright (c) 2002 ISOMEDIA, Inc. 3# Copyright (c) 2002 ISOMEDIA, Inc.
4# Written by Steve Milton 4# originally written by Steve Milton
5# Released under the GNU Public License 5# later updates by sean finney <seanius@seanius.net>
6# 6#
7# This program is free software; you can redistribute it and/or modify 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 8# it under the terms of the GNU General Public License as published by
@@ -18,13 +18,13 @@
18# along with this program; if not, write to the Free Software 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 19# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20# 20#
21# Usage: check_raid <raid-name> 21# Usage: check_raid [raid-name]
22# Example: check_raid md0 22# Example: check_raid md0
23# WARNING md0 status=[UUU_U], recovery=46.4%, finish=123.0min 23# WARNING md0 status=[UUU_U], recovery=46.4%, finish=123.0min
24 24
25use strict; 25use strict;
26 26use lib utils.pm;
27my %ERRORS=('DEPENDENT'=>4,'UNKNOWN'=>3,'OK'=>0,'WARNING'=>1,'CRITICAL'=>2); 27use utils qw(%ERRORS);
28 28
29# die with an error if we're not on Linux 29# die with an error if we're not on Linux
30if ($^O ne 'linux') { 30if ($^O ne 'linux') {
@@ -32,57 +32,79 @@ if ($^O ne 'linux') {
32 exit $ERRORS{'UNKNOWN'}; 32 exit $ERRORS{'UNKNOWN'};
33} 33}
34 34
35open (MDSTAT, "</proc/mdstat") or die "Failed to open /proc/mdstat"; 35sub max_state($$){
36my $found = 0; 36 my ($a, $b) = @_;
37my $status = ""; 37 if ($a eq "CRITICAL" || $b eq "CRITICAL") { return "CRITICAL"; }
38my $recovery = ""; 38 elsif ($a eq "WARNING" || $b eq "WARNING") { return "WARNING"; }
39my $finish = ""; 39 elsif ($a eq "OK" || $b eq "OK") { return "OK"; }
40my $active = ""; 40 elsif ($a eq "UNKNOWN" || $b eq "UNKNOWN") { return "UNKNOWN"; }
41while(<MDSTAT>) { 41 elsif ($a eq "DEPENDENT" || $b eq "DEPENDENT") { return "DEPENDENT"; }
42 if ($found) { 42 return "UNKNOWN";
43 if (/(\[[_U]+\])/) {
44 $status = $1;
45 last;
46 } elsif (/recovery = (.*?)\s/) {
47 $recovery = $1;
48 ($finish) = /finish=(.*?min)/;
49 last;
50 }
51 } else {
52 if (/^$ARGV[0]\s*:/) {
53 $found = 1;
54 if (/active/) {
55 $active = 1;
56 }
57 }
58 }
59} 43}
60 44
61my $msg = "FAILURE"; 45my $nextdev;
46if(defined $ARGV[0]) { $nextdev = shift; }
47else { $nextdev = "md[0-9]"; }
48
62my $code = "UNKNOWN"; 49my $code = "UNKNOWN";
63if ($status =~ /_/) { 50my $msg = "";
64 if ($recovery) { 51my %status;
65 $msg = sprintf "%s status=%s, recovery=%s, finish=%s\n", 52my %recovery;
66 $ARGV[0], $status, $recovery, $finish; 53my %finish;
67 $code = "WARNING"; 54my %active;
68 } else { 55my %devices;
69 $msg = sprintf "%s status=%s\n", $ARGV[0], $status; 56
70 $code = "CRITICAL"; 57while(defined $nextdev){
71 } 58 open (MDSTAT, "< /proc/mdstat") or die "Failed to open /proc/mdstat";
72} elsif ($status =~ /U+/) { 59 my $device = undef;
73 $msg = sprintf "%s status=%s\n", $ARGV[0], $status; 60 while(<MDSTAT>) {
74 $code = "OK"; 61 if (defined $device) {
75} else { 62 if (/(\[[_U]+\])/) {
76 if ($active) { 63 $status{$device} = $1;
77 $msg = sprintf "%s active with no status information.\n", 64 $device = undef;
78 $ARGV[0]; 65 } elsif (/recovery = (.*?)\s/) {
79 $code = "OK"; 66 $recovery{$device} = $1;
80 } else { 67 ($finish{$device}) = /finish=(.*?min)/;
81 $msg = sprintf "%s does not exist.\n", $ARGV[0]; 68 $device = undef;
82 $code = "CRITICAL"; 69 }
83 } 70 } else {
71 if (/^($nextdev)\s*:/) {
72 $device=$1;
73 $devices{$device}=$device;
74 if (/active/) {
75 $active{$device} = 1;
76 }
77 }
78 }
79 }
80 $nextdev = shift;
81}
82
83foreach my $k (sort keys %devices){
84 if ($status{$k} =~ /_/) {
85 if ($recovery{$k}) {
86 $msg .= sprintf " %s status=%s, recovery=%s, finish=%s.",
87 $devices{$k}, $status{$k}, $recovery{$k}, $finish{$k};
88 $code = max_state($code, "WARNING");
89 } else {
90 $msg .= sprintf " %s status=%s.", $devices{$k}, $status{$k};
91 $code = max_state($code, "CRITICAL");
92 }
93 } elsif ($status{$k} =~ /U+/) {
94 $msg .= sprintf " %s status=%s.", $devices{$k}, $status{$k};
95 $code = max_state($code, "OK");
96 } else {
97 if ($active{$k}) {
98 $msg .= sprintf " %s active with no status information.\n",
99 $devices{$k};
100 $code = max_state($code, "OK");
101 } else {
102 $msg .= sprintf " %s does not exist.\n", $devices{$k};
103 $code = max_state($code, "CRITICAL");
104 }
105 }
84} 106}
85 107
86print $code, " ", $msg; 108print $code, $msg, "\n";
87exit ($ERRORS{$code}); 109exit ($ERRORS{$code});
88 110