-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_lsi.pl
executable file
·180 lines (171 loc) · 5.71 KB
/
check_lsi.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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/perl -w
## ======================================================================================
## check_lsi
## --------------------------------------------------------------------------------------
use strict;
use warnings;
use Getopt::Long qw(:config no_ignore_case);
#
our $NOENCLOSURES = 0;
our $CONTROLLER = 0;
# Header maps to parse logical and physical devices
our $LDMAP;
our @map_a = ('DG/VD', 'TYPE', 'State', 'Access', 'Consist', 'Cache', 'sCC', 'Size');
our @map_cc_a = ('DG/VD', 'TYPE', 'State', 'Access', 'Consist', 'Cache', 'Cac', 'sCC', 'Size');
our @pdmap_a =
('EID:Slt', 'DID', 'State', 'DG', 'Size', 'Intf', 'Med', 'SED', 'PI', 'SeSz', 'Model', 'Sp');
# Prints the name anmd the version of check_lsi_raid. If storcli is available,
# the version if it is printed also.
# @param storcli The path to storcli command utility
sub displayVersion {
my $storcli = shift;
if (defined($storcli)) {
my @storcliVersion = `$storcli -v`;
foreach my $line (@storcliVersion) {
if ($line =~ /^\s+StorCli.*/) {
$line =~ s/^\s+|\s+$//g;
print $line;
}
}
print "\n";
}
exit(STATE_OK);
}
# Checks if a storcli call was successfull, i.e. if the line 'Status = Sucess'
# is present in the command output.
# @param output The output of the storcli command as array
# @return 1 on success, 0 if not
sub checkCommandStatus {
my @output = @{(shift)};
foreach my $line (@output) {
if ($line =~ /^Status/) {
if ($line eq "Status = Success\n") {
return 1;
}
else {
return 0;
}
}
}
}
# Shows the time the controller is using. Can be used to check if the
# controller number is a correct one.
# @param storcli The path to storcli command utility, followed by the controller
# number, e.g. 'storcli64 /c0'.
# @return 1 on success, 0 if not
sub getControllerTime {
my $storcli = shift;
my @output = `$storcli show time`;
return (checkCommandStatus(\@output));
}
# Get the status of the raid controller
# @param storcli The path to storcli command utility, followed by the controller
# number, e.g. 'storcli64 /c0'.
# @param logDevices If given, a list of desired logical device numbers
# @param commands_a An array to push the used command to
# @return A hash, each key a value of the raid controller info
sub getControllerInfo {
my $storcli = shift;
my $commands_a = shift;
my $command = '';
$storcli =~ /^(.*)\/c[0-9]+/;
$command = $1 . 'adpallinfo a' . $CONTROLLER;
push @{$commands_a}, $command;
my @output = `$command`;
if ($? >> 8 != 0) {
print "Invalid StorCLI command! ($command)\n";
exit(STATE_UNKNOWN);
}
my %foundController_h;
foreach my $line (@output) {
if ($line =~ /\:/) {
my @lineVals = split(':', $line);
$lineVals[0] =~ s/^\s+|\s+$//g;
$lineVals[1] =~ s/^\s+|\s+$//g;
$foundController_h{$lineVals[0]} = $lineVals[1];
}
}
return \%foundController_h;
}
# Checks the status of the raid controller
# @param statusLevel_a The status level array, elem 0 is the current status,
# elem 1 the warning sensors, elem 2 the critical sensors, elem 3 the verbose
# information for the sensors.
# @param foundController The hash of controller infos, created by getControllerInfo
sub getControllerStatus {
my @statusLevel_a = @{(shift)};
my %foundController = %{(shift)};
my $status;
foreach my $key (%foundController) {
if ($key eq 'ROC temperature') {
$foundController{$key} =~ /^([0-9]+\.?[0-9]+).*$/;
if (defined($1)) {
if (!(checkThreshs($1, $C_TEMP_CRITICAL))) {
$status = 'Critical';
push @{$statusLevel_a[2]}, 'ROC_Temperature';
}
elsif (!(checkThreshs($1, $C_TEMP_WARNING))) {
$status = 'Warning';
push @{$statusLevel_a[1]}, 'ROC_Temperature';
}
$statusLevel_a[3]->{'ROC_Temperature'} = $1;
}
}
elsif ($key eq 'Degraded') {
if ($foundController{$key} != 0) {
$status = 'Warning';
push @{$statusLevel_a[1]}, 'CTR_Degraded_drives';
$statusLevel_a[3]->{'CTR_Degraded_drives'} = $foundController{$key};
}
}
elsif ($key eq 'Offline') {
if ($foundController{$key} != 0) {
$status = 'Warning';
push @{$statusLevel_a[1]}, 'CTR_Offline_drives';
$statusLevel_a[3]->{'CTR_Offline_drives'} = $foundController{$key};
}
}
elsif ($key eq 'Critical Disks') {
if ($foundController{$key} != 0) {
$status = 'Critical';
push @{$statusLevel_a[2]}, 'CTR_Critical_disks';
$statusLevel_a[3]->{'CTR_Critical_disks'} = $foundController{$key};
}
}
elsif ($key eq 'Failed Disks') {
if ($foundController{$key} != 0) {
$status = 'Critical';
push @{$statusLevel_a[2]}, 'CTR_Failed_disks';
$statusLevel_a[3]->{'CTR_Failed_disks'} = $foundController{$key};
}
}
elsif ($key eq 'Memory Correctable Errors') {
if ($foundController{$key} != 0) {
$status = 'Warning';
push @{$statusLevel_a[1]}, 'CTR_Memory_correctable_errors';
$statusLevel_a[3]->{'CTR_Memory_correctable_errors'} = $foundController{$key};
}
}
elsif ($key eq 'Memory Uncorrectable Errors') {
if ($foundController{$key} != 0) {
$status = 'Critical';
push @{$statusLevel_a[2]}, 'CTR_Memory_Uncorrectable_errors';
$statusLevel_a[3]->{'CTR_Memory_Uncorrectable_errors'} = $foundController{$key};
}
}
}
if (defined($status)) {
if ($status eq 'Warning') {
if (${$statusLevel_a[0]} ne 'Critical') {
${$statusLevel_a[0]} = 'Warning';
}
}
else {
${$statusLevel_a[0]} = 'Critical';
}
$statusLevel_a[3]->{'CTR_Status'} = $status;
}
else {
$statusLevel_a[3]->{'CTR_Status'} = 'OK';
}
}