1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
--- contrib/check_linux_raid.pl 2007-08-28 04:19:45.000000000 +0100
+++ contrib/check_linux_raid.pl.new 2008-01-21 17:28:18.000000000 +0000
@@ -3,6 +3,7 @@
# Copyright (c) 2002 ISOMEDIA, Inc.
# originally written by Steve Milton
# later updates by sean finney <seanius@seanius.net>
+# bux fixing & usage message by Alain Williams <addw@phcomp.co.uk>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -26,6 +27,8 @@
use lib "/usr/local/nagios/libexec";
use utils qw(%ERRORS);
+my ($progname) = $0 =~ m|([^/]+)$|;
+
# die with an error if we're not on Linux
if ($^O ne 'linux') {
print "This plugin only applicable on Linux.\n";
@@ -42,9 +45,22 @@
return "UNKNOWN";
}
+sub usage {
+ print "Inspect Linux software raid devices and return a status for nagios\n";
+ print "Usage:\n";
+ print "$progname [--help | -h] [md-device ...]\n";
+ print "A md-device might be: md0\n";
+ print "If md-device is not given, all mds will be inspected\n";
+ exit 0;
+}
+
my $nextdev;
-if(defined $ARGV[0]) { $nextdev = shift; }
-else { $nextdev = "md[0-9]"; }
+if(defined $ARGV[0]) {
+ $nextdev = shift;
+ usage() if($nextdev eq '--help' or $nextdev eq '-h');
+} else {
+ $nextdev = "md[0-9]+"; # All MD devices
+}
my $code = "UNKNOWN";
my $msg = "";
@@ -53,6 +69,7 @@
my %finish;
my %active;
my %devices;
+my $debug;
while(defined $nextdev){
open (MDSTAT, "< /proc/mdstat") or die "Failed to open /proc/mdstat";
@@ -60,14 +77,22 @@
while(<MDSTAT>) {
if (defined $device) {
if (/(\[[_U]+\])/) {
+ print "status='$1' device '$device'\n" if($debug);
$status{$device} = $1;
} elsif (/recovery = (.*?)\s/) {
$recovery{$device} = $1;
($finish{$device}) = /finish=(.*?min)/;
- } elsif (/^\s*$/) {
+ } elsif (/^\s*$/) { # Start of another device - blank line. NB: may not be present
+ print "undef '$device' _='$_'\n" if($debug);
$device=undef;
+ } elsif(/^md[0-9]+\s*:/) { # Start of another device - another way
+ print "undef '$device' _='$_'\n" if($debug);
+ undef $device;
}
- } elsif (/^($nextdev)\s*:/) {
+ }
+
+ # No current device and this line matches the device pattern ?
+ if ( ! defined($device) and /^($nextdev)\s*:/) {
$device=$1;
$devices{$device}=$device;
if (/active/) {
|