diff options
Diffstat (limited to 'contrib/check_linux_raid.pl')
-rw-r--r-- | contrib/check_linux_raid.pl | 125 |
1 files changed, 0 insertions, 125 deletions
diff --git a/contrib/check_linux_raid.pl b/contrib/check_linux_raid.pl deleted file mode 100644 index 6650a42b..00000000 --- a/contrib/check_linux_raid.pl +++ /dev/null | |||
@@ -1,125 +0,0 @@ | |||
1 | #!/usr/bin/perl -w | ||
2 | |||
3 | # Copyright (c) 2002 ISOMEDIA, Inc. | ||
4 | # originally written by Steve Milton | ||
5 | # later updates by sean finney <seanius@seanius.net> | ||
6 | # | ||
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. | ||
11 | # | ||
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. | ||
16 | # | ||
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 | ||
20 | # | ||
21 | # Usage: check_raid [raid-name] | ||
22 | # Example: check_raid md0 | ||
23 | # WARNING md0 status=[UUU_U], recovery=46.4%, finish=123.0min | ||
24 | |||
25 | use strict; | ||
26 | use lib "/usr/local/nagios/libexec"; | ||
27 | use utils qw(%ERRORS); | ||
28 | |||
29 | # die with an error if we're not on Linux | ||
30 | if ($^O ne 'linux') { | ||
31 | print "This plugin only applicable on Linux.\n"; | ||
32 | exit $ERRORS{'UNKNOWN'}; | ||
33 | } | ||
34 | |||
35 | sub max_state($$){ | ||
36 | my ($a, $b) = @_; | ||
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"; } | ||
42 | return "UNKNOWN"; | ||
43 | } | ||
44 | |||
45 | my $nextdev; | ||
46 | if(defined $ARGV[0]) { $nextdev = shift; } | ||
47 | else { $nextdev = "md[0-9]+"; } | ||
48 | |||
49 | my $code = "UNKNOWN"; | ||
50 | my $msg = ""; | ||
51 | my %status; | ||
52 | my %recovery; | ||
53 | my %resyncing; | ||
54 | my %finish; | ||
55 | my %active; | ||
56 | my %devices; | ||
57 | |||
58 | while(defined $nextdev){ | ||
59 | open (MDSTAT, "< /proc/mdstat") or die "Failed to open /proc/mdstat"; | ||
60 | my $device = undef; | ||
61 | while(<MDSTAT>) { | ||
62 | if (defined $device) { | ||
63 | if (/(\[[_U]+\])/) { | ||
64 | $status{$device} = $1; | ||
65 | } elsif (/recovery =\s+(.*?)\s/) { | ||
66 | $recovery{$device} = $1; | ||
67 | ($finish{$device}) = /finish=(.*?min)/; | ||
68 | $device=undef; | ||
69 | } elsif (/resync =\s+(.*?)\s/) { | ||
70 | $resyncing{$device} = $1; | ||
71 | ($finish{$device}) = /finish=(.*?min)/; | ||
72 | $device=undef; | ||
73 | } elsif (/^\s*$/) { | ||
74 | $device=undef; | ||
75 | } | ||
76 | } elsif (/^($nextdev)\s*:/) { | ||
77 | $device=$1; | ||
78 | $devices{$device}=$device; | ||
79 | if (/\sactive/) { | ||
80 | $status{$device} = ''; # Shall be filled later if available | ||
81 | $active{$device} = 1; | ||
82 | } | ||
83 | } | ||
84 | } | ||
85 | $nextdev = shift; | ||
86 | } | ||
87 | |||
88 | foreach my $k (sort keys %devices){ | ||
89 | if (!exists($status{$k})) { | ||
90 | $msg .= sprintf " %s inactive with no status information.", | ||
91 | $devices{$k}; | ||
92 | $code = max_state($code, "CRITICAL"); | ||
93 | } elsif ($status{$k} =~ /_/) { | ||
94 | if (defined $recovery{$k}) { | ||
95 | $msg .= sprintf " %s status=%s, recovery=%s, finish=%s.", | ||
96 | $devices{$k}, $status{$k}, $recovery{$k}, $finish{$k}; | ||
97 | $code = max_state($code, "WARNING"); | ||
98 | } else { | ||
99 | $msg .= sprintf " %s status=%s.", $devices{$k}, $status{$k}; | ||
100 | $code = max_state($code, "CRITICAL"); | ||
101 | } | ||
102 | } elsif ($status{$k} =~ /U+/) { | ||
103 | if (defined $resyncing{$k}) { | ||
104 | $msg .= sprintf " %s status=%s, resync=%s, finish=%s.", | ||
105 | $devices{$k}, $status{$k}, $resyncing{$k}, $finish{$k}; | ||
106 | $code = max_state($code, "WARNING"); | ||
107 | } else { | ||
108 | $msg .= sprintf " %s status=%s.", $devices{$k}, $status{$k}; | ||
109 | $code = max_state($code, "OK"); | ||
110 | } | ||
111 | } else { | ||
112 | if ($active{$k}) { | ||
113 | $msg .= sprintf " %s active with no status information.", | ||
114 | $devices{$k}; | ||
115 | $code = max_state($code, "OK"); | ||
116 | } else { | ||
117 | # This should't run anymore, but is left as a catch-all | ||
118 | $msg .= sprintf " %s does not exist.\n", $devices{$k}; | ||
119 | $code = max_state($code, "CRITICAL"); | ||
120 | } | ||
121 | } | ||
122 | } | ||
123 | |||
124 | print $code, $msg, "\n"; | ||
125 | exit ($ERRORS{$code}); | ||