-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_mfi
162 lines (133 loc) · 5.3 KB
/
check_mfi
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/perl -w
# check_mfi Nagios plugin
# Copyright (C) 2011 Jonathan Delgado, [email protected]
#
# 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 the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
#
# Nagios plugin to monitor the status of volumes attached to an LSI Megaraid SAS
# controller utilizing the mfi driver under FreeBSD. You need to be running a
# version of FreeBSD that includes mfiutil (FreeBSD 7.3+ or 8.0+)
#
#
# $Author: delgado $
# $Revision: #2 $ $Date: 2011/08/08 $
use strict;
use Getopt::Std;
use lib qw(/usr/local/libexec/nagios); # path to Nagios plugin and utils.pm on fbsd
use utils qw(%ERRORS);
our($opt_h, $opt_u, $opt_s);
getopts('hu:s:');
if ( $opt_h ) {
print "Usage: $0 [-u #] [-s #]\n";
print " -u is the number of RAID controllers installed\n";
print " -s is how many hotspares are attached to the controller\n";
exit;
}
my $mfiutilbin = '/usr/sbin/mfiutil'; # the default path to the mfiutil binary
my $mfiutil = "sudo $mfiutilbin"; # how we actually call mfiutil
my $adapters = 1;
my $hotspares = 0;
my $hotsparecount = 0;
my $pdgood = 0;
my $pdbad = 0;
my $pdugly = 0;
my $pdcount = 0;
my $result = '';
my $status = 'OK';
if ( $opt_s ) {
$hotspares = $opt_s;
}
if ( $opt_u ) {
$adapters = $opt_u;
}
sub max_state ($$);
sub exitreport($$);
unless ( -e $mfiutilbin ) {
exitreport('UNKNOWN', "error: Could not execute $mfiutil ");
}
ADAPTER: for ( my $adp = 0; $adp < $adapters; $adp++ ) {
open(VINFO, "$mfiutil -u $adp show volumes |")
|| exitreport('UNKNOWN', "error: Could not execute $mfiutil -u $adp show volumes ");
my ($id, $size, $level, $stripe, $state, $cache, $name);
while (<VINFO>) {
if ( m/^\s+mfid(\d+)\s+\(\s+(\d+\w+)\)\s+([A-Z0-9\-]+)\s+(\w+)\s+(OFFLINE|OPTIMAL|PARTIALLY DEGRADED|DEGRADED)\s+.*$/ ) {
($id, $size, $level, $state) = ($1, $2, $3, $5);
if ( ( $state eq 'PARTIALLY DEGRADED' ) || ( $state eq 'OFFLINE' ) ) {
$status = max_state($status, 'WARNING');
} elsif ( $state eq 'DEGRADED' ) {
$status = 'CRITICAL';
}
$result .= "mfid$id:$size:$level:$state ";
}
}
close VINFO;
open (DINFO, "$mfiutil -u $adp show drives |")
|| exitreport('UNKNOWN', "error: Could not execute $mfiutil -u $adp show drives ");
my ($dstate, $enclosure, $slot);
while (<DINFO>) {
if ( m/^\(\s+(\d+\w+)\)\s+(.+)\s+<.+>\s+\w+\s+enclosure\s+(\d+),\s+slot\s+(\d+).*$/ ) {
($dstate, $enclosure, $slot) = ($2, $3, $4);
$pdcount++;
if ( ($dstate eq 'UNCONFIGURED BAD') || ($dstate eq 'REBUILD') || ($dstate eq 'OFFLINE')) {
$status = max_state($status, 'WARNING');
$pdugly++;
print "Ugly $dstate Enc $enclosure Slot $slot\n";
} elsif ($dstate eq 'FAILED') {
$status = 'CRITICAL';
$pdbad++;
} elsif ($dstate eq 'HOT SPARE') {
$hotsparecount++;
$pdgood++;
} elsif (($dstate eq 'ONLINE') || ($dstate eq 'UNCONFIGURED GOOD')) {
$pdgood++;
}
}
}
close DINFO;
}
$result .= "Drives:$pdcount ";
if ( ($pdbad > 0) || ($pdugly > 0) ) {
$result .= "($pdgood Good, $pdbad Bad, $pdugly Ugly) ";
}
# Do we have as many hotspares as expected (if any)
if ( $hotspares ) {
if ( $hotsparecount < $hotspares ) {
$status = max_state($status, 'WARNING');
$result .= "Hotspare(s):$hotsparecount (of $hotspares)";
} else {
$result .= "Hotspare(s):$hotsparecount";
}
}
exitreport($status, $result);
sub max_state ($$) {
my ($current, $compare) = @_;
if (($compare eq 'CRITICAL') || ($current eq 'CRITICAL')) {
return 'CRITICAL';
} elsif ($compare eq 'OK') {
return $current;
} elsif ($compare eq 'WARNING') {
return 'WARNING';
} elsif (($compare eq 'UNKNOWN') && ($current eq 'OK')) {
return 'UNKNOWN';
} else {
return $current;
}
}
sub exitreport ($$) {
my ($status, $message) = @_;
print STDOUT "$status: $message\n";
exit $ERRORS{$status};
}