forked from mludvig/nagios-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-hp-smartarray.pl
executable file
·135 lines (120 loc) · 2.64 KB
/
check-hp-smartarray.pl
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
#!/usr/bin/perl
#
# check-hp-smartarray.pl
#
# Nagios script for checking HP SmartArray status.
# Keywords: HP SmartArray, CCISS, hpacucli, RAID
#
# Michal Ludvig <michal@logix.cz> (c) 2013
# http://www.logix.cz/michal/nagios
# for Enterprise IT -- http://enterpriseit.co.nz
#
# The "hpacucli" package must be installed (free to
# download from HP).
#
use strict;
my %ERRORS=("OK"=>0, "WARNING"=>1, "CRITICAL"=>2, "UNKNOWN"=>3, "DEPENDENT"=>4);
my $debug = 0;
my $displays_cnt = 0;
my $result = "OK";
my @output;
my $slots_cnt = 0;
my $arrays_cnt = 0;
my $lds_cnt = 0;
my $pds_cnt = 0;
sub debug($) {
my $message = shift;
if ($debug) {
print($message . "\n");
}
}
sub nagios_exit($$) {
my $result = shift;
my $message = shift;
print("$result - $message\n");
exit($ERRORS{$result});
}
sub hpacucli($) {
my $command = shift;
my @lines;
debug(">> hpacucli $command <<");
if ($#ARGV > -1) {
open(HP, $ARGV[0]) or die("${ARGV[0]}: $!");
} else {
open(HP, "hpacucli $command |") or nagios_exit("UNKNOWN", "hpacucli: $!");
}
while (<HP>) {
# trim whitespace
$_ =~ s/^\s*(.*?)\s*$/$1/;
debug("hpacucli: $_");
push(@lines, $_);
}
return @lines;
}
sub update_result($)
{
my $new_result = shift;
if ($ERRORS{$result} < $ERRORS{$new_result}) {
debug("Updating result $result -> $new_result");
$result = $new_result;
}
}
sub check_arrays() {
my ($slot, $array, $ld, $pd_cnt);
my $ok = 1;
my @ld_show = hpacucli("controller all show config");
foreach (@ld_show) {
if (/^(.*) in Slot (\d+).*/) {
$slots_cnt++;
$slot = "slot=$2";
debug("$slot ($1)");
$array = undef;
$ld = undef;
next;
}
if (/^array ([A-Z]+)/) {
$arrays_cnt++;
$array = "array=$1";
next;
}
if (/^unassigned/) {
$array = "unassigned";
next;
}
if (/^logicaldrive (\d+) \((.+)\)/) {
$lds_cnt++;
$ld = $1;
my $ld_output = "$slot $array $_";
if ($2 =~ /OK/) {
debug("OK: $ld_output");
push(@output, $ld_output) if ($displays_cnt);
} elsif ($2 =~ /Fail/) {
push(@output, $ld_output);
debug("CRITICAL: $ld_output");
update_result("CRITICAL");
} else {
push(@output, $ld_output);
debug("WARNING: $ld_output");
update_result("WARNING");
}
next;
}
if (/^physicaldrive/) {
$pds_cnt++;
if (/OK/) {
debug("OK: $_");
} elsif (/Fail/) {
push(@output, $_);
debug("CRITICAL: $_");
update_result("CRITICAL");
} else {
push(@output, $_);
debug("WARNING: $_");
update_result("WARNING");
}
}
}
}
check_arrays();
push(@output, "Checked: $slots_cnt slots, $arrays_cnt arrays, $lds_cnt LDs, $pds_cnt PDs");
nagios_exit($result, join(" / ", @output));