-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcciss-showharderr
executable file
·149 lines (125 loc) · 3.67 KB
/
cciss-showharderr
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
#!/usr/bin/perl
# vim:sw=4:sts=4
#
# Shows hard errors on HDDs connected to HPE/HP/Compaq SmartArray/CCISS
# controllers.
#
# Written by Niklas Edmundsson in May 2014
# Copyright (C) 2014-2020 Niklas Edmundsson <nikke@acc.umu.se>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
use warnings;
no warnings 'portable'; # Support for 64-bit ints required
use strict;
use File::Temp qw/ :mktemp /;
my @utils=qw{ssacli hpssacli hpacucli};
my $sacli;
# Extracts an ADU report for a controller and prints HDDs with hard errors.
sub show_hdd_harderr($) {
my $ctrl = shift;
my $currhdd="";
my $currctrl="";
my %h;
my $fh;
my $zipfile = mktemp("/tmp/adufile.XXXXXXXXXX").".zip";
system("$sacli ctrl slot=$ctrl diag file=$zipfile > /dev/null");
if(! -s $zipfile) {
die "$sacli diag failed";
}
open($fh, "unzip -p $zipfile ADUReport.txt |") || die "unzip $zipfile: failed: $!";
while(<$fh>) {
s/[\n\r]$//; # Nuke DOS line endings
if(/^\S/) {
if(!/Monitor and Performance Statistics.*Factory/) {
$currctrl="";
$currhdd="";
next;
}
if(/in\s(slot\s(\S+)|Embedded\sSlot).*\s([^: ][^: ]+:\S+)\s/) {
my $ctrlpos = $1;
$currctrl = $2;
$currhdd = $3;
if($ctrlpos eq "Embedded Slot") {
$currctrl = 0;
}
if($ctrl ne $currctrl) {
die "Unexpected ctrl $currctrl found while processing $ctrl";
}
next;
}
else {
die "No ctrl/disk found on line '$_'\n";
}
}
next unless($currhdd);
if(/\s+(.*?)\s\s+(.*)/) {
my $n = $1;
my $v = $2;
if($v =~ /^0x[0-9a-fA-F]+$/) {
$v = hex($v);
}
$v =~ s/\s+$//;
$h{$currhdd}{$n} = $v;
}
}
close($fh) || die "unzip $zipfile: failed: $!";
unlink($zipfile);
my %ehash;
foreach my $k (sort keys %h) {
if(!defined($h{$k}{'Product Revision'}) || !defined($h{$k}{'Read Errors Hard'}) || !defined($h{$k}{'Write Errors Hard'})) {
printf "%-7s %-16s %s\n", "ctrl=$ctrl", $k, "No info (not a HP/Compaq HDD?)";
next;
}
my $errs = 0;
if($h{$k}{'Read Errors Hard'} > $errs) {
$errs = $h{$k}{'Read Errors Hard'};
}
if($h{$k}{'Write Errors Hard'} > $errs) {
$errs = $h{$k}{'Write Errors Hard'};
}
if($errs > 0) {
$ehash{$k} = $errs;
}
}
foreach my $k (sort {$ehash{$b}<=>$ehash{$a}} keys %ehash) {
my $mod = $h{$k}{'Product Revision'};
$mod =~ s/^ATA\s+//;
$mod =~ s/\s+/ /g;
printf "%-7s %-8s %-18s %-10s %-9s %s\n", "ctrl=$ctrl", $k, $mod, $h{$k}{'Serial Number'}, "read=$h{$k}{'Read Errors Hard'}", "write=$h{$k}{'Write Errors Hard'}";
}
}
my $fh;
my %slots;
# Find controllers slots
# hpssacli support Pxxx onwards, hpacucli supports stuff until Px2x.
foreach my $util (@utils) {
open($fh, "$util controller all show 2>/dev/null |");
while(<$fh>) {
chomp;
if(/Slot\s+(\d+[a-z]*)/) {
$slots{$1} = 1;
}
}
close($fh);
if(%slots) {
$sacli = $util;
last;
}
}
if(! %slots) {
die("No controllers found using any of " . join(" ", @utils));
}
foreach my $ctrl (sort keys %slots) {
show_hdd_harderr($ctrl);
}