diff options
| author | M. Sean Finney <seanius@users.sourceforge.net> | 2006-06-01 22:30:51 +0000 |
|---|---|---|
| committer | M. Sean Finney <seanius@users.sourceforge.net> | 2006-06-01 22:30:51 +0000 |
| commit | 4522ae336de629b405572c83f5bb59a68f979cc0 (patch) | |
| tree | 53e0a603b665cc9281cb15d111a8d5211063228a /contrib | |
| parent | 25d253bf3fd59360e2d4f710b70a583311f7f243 (diff) | |
| download | monitoring-plugins-4522ae336de629b405572c83f5bb59a68f979cc0.tar.gz | |
gave some TLC to check_linux_raid
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1412 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'contrib')
| -rw-r--r-- | contrib/check_linux_raid.pl | 126 |
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 | ||
| 25 | use strict; | 25 | use strict; |
| 26 | 26 | use lib utils.pm; | |
| 27 | my %ERRORS=('DEPENDENT'=>4,'UNKNOWN'=>3,'OK'=>0,'WARNING'=>1,'CRITICAL'=>2); | 27 | use 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 |
| 30 | if ($^O ne 'linux') { | 30 | if ($^O ne 'linux') { |
| @@ -32,57 +32,79 @@ if ($^O ne 'linux') { | |||
| 32 | exit $ERRORS{'UNKNOWN'}; | 32 | exit $ERRORS{'UNKNOWN'}; |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | open (MDSTAT, "</proc/mdstat") or die "Failed to open /proc/mdstat"; | 35 | sub max_state($$){ |
| 36 | my $found = 0; | 36 | my ($a, $b) = @_; |
| 37 | my $status = ""; | 37 | if ($a eq "CRITICAL" || $b eq "CRITICAL") { return "CRITICAL"; } |
| 38 | my $recovery = ""; | 38 | elsif ($a eq "WARNING" || $b eq "WARNING") { return "WARNING"; } |
| 39 | my $finish = ""; | 39 | elsif ($a eq "OK" || $b eq "OK") { return "OK"; } |
| 40 | my $active = ""; | 40 | elsif ($a eq "UNKNOWN" || $b eq "UNKNOWN") { return "UNKNOWN"; } |
| 41 | while(<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 | ||
| 61 | my $msg = "FAILURE"; | 45 | my $nextdev; |
| 46 | if(defined $ARGV[0]) { $nextdev = shift; } | ||
| 47 | else { $nextdev = "md[0-9]"; } | ||
| 48 | |||
| 62 | my $code = "UNKNOWN"; | 49 | my $code = "UNKNOWN"; |
| 63 | if ($status =~ /_/) { | 50 | my $msg = ""; |
| 64 | if ($recovery) { | 51 | my %status; |
| 65 | $msg = sprintf "%s status=%s, recovery=%s, finish=%s\n", | 52 | my %recovery; |
| 66 | $ARGV[0], $status, $recovery, $finish; | 53 | my %finish; |
| 67 | $code = "WARNING"; | 54 | my %active; |
| 68 | } else { | 55 | my %devices; |
| 69 | $msg = sprintf "%s status=%s\n", $ARGV[0], $status; | 56 | |
| 70 | $code = "CRITICAL"; | 57 | while(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 | |||
| 83 | foreach 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 | ||
| 86 | print $code, " ", $msg; | 108 | print $code, $msg, "\n"; |
| 87 | exit ($ERRORS{$code}); | 109 | exit ($ERRORS{$code}); |
| 88 | 110 | ||
