summaryrefslogtreecommitdiffstats
path: root/web/attachments/154512-check_linux_raid.pl
diff options
context:
space:
mode:
Diffstat (limited to 'web/attachments/154512-check_linux_raid.pl')
-rw-r--r--web/attachments/154512-check_linux_raid.pl111
1 files changed, 111 insertions, 0 deletions
diff --git a/web/attachments/154512-check_linux_raid.pl b/web/attachments/154512-check_linux_raid.pl
new file mode 100644
index 0000000..a7a948a
--- /dev/null
+++ b/web/attachments/154512-check_linux_raid.pl
@@ -0,0 +1,111 @@
1#!/usr/bin/perl -w
2
3# Copyright (c) 2002 ISOMEDIA, Inc.
4# Written by Steve Milton
5# Released under the GNU Public License
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
25use strict;
26use Getopt::Long qw(:config no_ignore_case);
27
28my %ERRORS=('DEPENDENT'=>4,'UNKNOWN'=>3,'OK'=>0,'WARNING'=>1,'CRITICAL'=>2);
29
30my $mdstat = "/proc/mdstat";
31my $verbose = 0;
32
33GetOptions('mdstat=s' => \$mdstat,
34 'v|verbose+' => \$verbose,
35 'h|help' => sub { usage(); exit $ERRORS{'UNKNOWN'}; },
36 'V|version' => sub { version(); exit $ERRORS{'UNKNOWN'}; });
37
38# die with an error if we're not on Linux
39if ($^O ne 'linux') {
40 print "This plugin only applicable on Linux.\n";
41 exit $ERRORS{'UNKNOWN'};
42}
43
44my $mddev = shift;
45
46open (MDSTAT, "<$mdstat") or die "Failed to open $mdstat";
47my $found = 0;
48my $status = "";
49my $recovery = "";
50my $finish = "";
51my $speed = "";
52my $active = "";
53while(<MDSTAT>) {
54 chomp;
55 if ($found) {
56 if (/(\[[_U]+\])/) {
57 $status = $1;
58 } elsif (/recovery *= *([^ ]+)/) {
59 $recovery = $1;
60 ($finish) = /finish= *([^ ]+)/;
61 ($speed) = /speed= *([^ ]+)/;
62 } elsif (/^[^ \t]/) {
63 last;
64 }
65 } else {
66 if (/^$mddev\s*:/) {
67 $found = 1;
68 if (/active/) {
69 $active = 1;
70 }
71 }
72 }
73}
74
75my $msg = "FAILURE";
76my $code = "UNKNOWN";
77if ($status =~ /_/) {
78 if ($recovery) {
79 $msg = "$mddev status=$status, recovery=$recovery, finish=$finish, speed=$speed",
80 $code = "WARNING";
81 } else {
82 $msg = "$mddev status=$status";
83 $code = "CRITICAL";
84 }
85} elsif ($status =~ /U+/) {
86 $msg = "$mddev status=$status";
87 $code = "OK";
88} else {
89 if ($active) {
90 $msg = "$mddev active with no status information";
91 $code = "OK";
92 } else {
93 $msg = "$mddev does not exist";
94 $code = "CRITICAL";
95 }
96}
97
98print "RAID $code: $msg\n";
99exit ($ERRORS{$code});
100
101sub usage {
102 print qq{usage:
103 check_linux_raid.pl [--mdstat=</proc/mdstat>] <md-device>
104e.g.
105 check_linux_raid.pl md0
106};
107}
108
109sub version {
110 print "check_linux_raid.pl 1.1\n";
111}