| 1 |
package HP::Proliant::Component::DiskSubsystem::Da::CLI; |
| 2 |
our @ISA = qw(HP::Proliant::Component::DiskSubsystem::Da); |
| 3 |
|
| 4 |
use strict; |
| 5 |
use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; |
| 6 |
|
| 7 |
sub new { |
| 8 |
my $class = shift; |
| 9 |
my %params = @_; |
| 10 |
my $self = { |
| 11 |
controllers => [], |
| 12 |
accelerators => [], |
| 13 |
enclosures => [], |
| 14 |
physical_drives => [], |
| 15 |
logical_drives => [], |
| 16 |
spare_drives => [], |
| 17 |
blacklisted => 0, |
| 18 |
}; |
| 19 |
bless $self, $class; |
| 20 |
return $self; |
| 21 |
} |
| 22 |
|
| 23 |
sub init { |
| 24 |
my $self = shift; |
| 25 |
my $hpacucli = $self->{rawdata}; |
| 26 |
my $slot = 0; |
| 27 |
my $type = "unkn"; |
| 28 |
my @lines = (); |
| 29 |
my $thistype = 0; |
| 30 |
my $tmpcntl = {}; |
| 31 |
my $tmpaccel = {}; |
| 32 |
my $tmpld = {}; |
| 33 |
my $tmppd = {}; |
| 34 |
my $tmpencl = {}; |
| 35 |
my $cntlindex = 0; |
| 36 |
my $enclosureindex = 0; |
| 37 |
my $ldriveindex = 0; |
| 38 |
my $pdriveindex = 0; |
| 39 |
my $incontroller = 0; |
| 40 |
foreach (split(/\n/, $hpacucli)) { |
| 41 |
next unless /^status/; |
| 42 |
next if /^status\s*$/; |
| 43 |
s/^status\s*//; |
| 44 |
if (/(MSA[\s\w]+)\s+in\s+(\w+)/) { |
| 45 |
$incontroller = 1; |
| 46 |
$slot = $2; |
| 47 |
$cntlindex++; |
| 48 |
$tmpcntl->{$slot}->{cpqDaCntlrIndex} = $cntlindex; |
| 49 |
$tmpcntl->{$slot}->{cpqDaCntlrModel} = $1; |
| 50 |
$tmpcntl->{$slot}->{cpqDaCntlrSlot} = $slot; |
| 51 |
} elsif (/([\s\w]+) in Slot\s+(\d+)/) { |
| 52 |
$incontroller = 1; |
| 53 |
$slot = $2; |
| 54 |
$cntlindex++; |
| 55 |
$tmpcntl->{$slot}->{cpqDaCntlrIndex} = $cntlindex; |
| 56 |
$tmpcntl->{$slot}->{cpqDaCntlrModel} = $1; |
| 57 |
$tmpcntl->{$slot}->{cpqDaCntlrSlot} = $slot; |
| 58 |
} elsif (/Controller Status: (\w+)/) { |
| 59 |
$tmpcntl->{$slot}->{cpqDaCntlrBoardCondition} = lc $1; |
| 60 |
$tmpcntl->{$slot}->{cpqDaCntlrCondition} = lc $1; |
| 61 |
} elsif (/Cache Status: ([\w\s]+?)\s*$/) { |
| 62 |
# Cache Status: OK |
| 63 |
# Cache Status: Not Configured |
| 64 |
# Cache Status: Temporarily Disabled |
| 65 |
$tmpaccel->{$slot}->{cpqDaAccelCntlrIndex} = $cntlindex; |
| 66 |
$tmpaccel->{$slot}->{cpqDaAccelSlot} = $slot; |
| 67 |
#condition: other,ok,degraded,failed |
| 68 |
#status: other,invalid,enabled,tmpDisabled,permDisabled |
| 69 |
$tmpaccel->{$slot}->{cpqDaAccelCondition} = lc $1; |
| 70 |
if ($tmpaccel->{$slot}->{cpqDaAccelCondition} eq 'ok') { |
| 71 |
$tmpaccel->{$slot}->{cpqDaAccelStatus} = 'enabled'; |
| 72 |
} elsif ($tmpaccel->{$slot}->{cpqDaAccelCondition} eq 'not configured') { |
| 73 |
$tmpaccel->{$slot}->{cpqDaAccelCondition} = 'ok'; |
| 74 |
$tmpaccel->{$slot}->{cpqDaAccelStatus} = 'enabled'; |
| 75 |
} elsif ($tmpaccel->{$slot}->{cpqDaAccelCondition} eq 'temporarily disabled') { |
| 76 |
$tmpaccel->{$slot}->{cpqDaAccelCondition} = 'ok'; |
| 77 |
$tmpaccel->{$slot}->{cpqDaAccelStatus} = 'tmpDisabled'; |
| 78 |
} elsif ($tmpaccel->{$slot}->{cpqDaAccelCondition} eq 'permanently disabled') { |
| 79 |
$tmpaccel->{$slot}->{cpqDaAccelCondition} = 'ok'; |
| 80 |
$tmpaccel->{$slot}->{cpqDaAccelStatus} = 'permDisabled'; |
| 81 |
} else { |
| 82 |
$tmpaccel->{$slot}->{cpqDaAccelStatus} = 'enabled'; |
| 83 |
} |
| 84 |
} elsif (/Battery.* Status: (\w+)/) { |
| 85 |
# sowas gibts auch Battery/Capacitor Status: OK |
| 86 |
$tmpaccel->{$slot}->{cpqDaAccelBattery} = lc $1; |
| 87 |
} elsif (/^\s*$/) { |
| 88 |
} |
| 89 |
} |
| 90 |
$slot = 0; |
| 91 |
$cntlindex = 0; |
| 92 |
$enclosureindex = 0; |
| 93 |
$ldriveindex = 0; |
| 94 |
$pdriveindex = 0; |
| 95 |
foreach (split(/\n/, $hpacucli)) { |
| 96 |
next unless /^config/; |
| 97 |
next if /^config\s*$/; |
| 98 |
s/^config\s*//; |
| 99 |
if (/(MSA[\s\w]+)\s+in\s+(\w+)/) { |
| 100 |
$slot = $2; |
| 101 |
$cntlindex++; |
| 102 |
$pdriveindex = 1; |
| 103 |
} elsif (/([\s\w]+) in Slot\s+(\d+)/) { |
| 104 |
#if ($slot ne $2 || ! $slot) { |
| 105 |
$cntlindex++; |
| 106 |
# 2012-12-15 das passt nicht zur oberen schleife |
| 107 |
# ich habe keine ahnung, was der hintergrund fuer dieses if ist |
| 108 |
#} |
| 109 |
$slot = $2; |
| 110 |
$pdriveindex = 1; |
| 111 |
} elsif (/([\s\w]+) at Port ([\w]+), Box (\d+), (.*)/) { |
| 112 |
$enclosureindex++; |
| 113 |
$tmpencl->{$slot}->{$enclosureindex}->{cpqDaEnclCntlrIndex} = $cntlindex; |
| 114 |
$tmpencl->{$slot}->{$enclosureindex}->{cpqDaEnclIndex} = $enclosureindex; |
| 115 |
$tmpencl->{$slot}->{$enclosureindex}->{cpqDaEnclPort} = $2; |
| 116 |
$tmpencl->{$slot}->{$enclosureindex}->{cpqDaEnclBox} = $3; |
| 117 |
$tmpencl->{$slot}->{$enclosureindex}->{cpqDaEnclCondition} = $4; |
| 118 |
$tmpencl->{$slot}->{$enclosureindex}->{cpqDaEnclStatus} = |
| 119 |
$tmpencl->{$slot}->{$enclosureindex}->{cpqDaEnclCondition}; |
| 120 |
$tmpencl->{$slot}->{$enclosureindex}->{cpqDaLogDrvPhyDrvIDs} = 'unknown'; |
| 121 |
} elsif (/logicaldrive\s+(.+?)\s+\((.*)\)/) { |
| 122 |
# logicaldrive 1 (683.5 GB, RAID 5, OK) |
| 123 |
# logicaldrive 1 (683.5 GB, RAID 5, OK) |
| 124 |
# logicaldrive 2 (442 MB, RAID 1+0, OK) |
| 125 |
$ldriveindex = $1; |
| 126 |
$tmpld->{$slot}->{$ldriveindex}->{cpqDaLogDrvCntlrIndex} = $cntlindex; |
| 127 |
$tmpld->{$slot}->{$ldriveindex}->{cpqDaLogDrvIndex} = $ldriveindex; |
| 128 |
($tmpld->{$slot}->{$ldriveindex}->{cpqDaLogDrvSize}, |
| 129 |
$tmpld->{$slot}->{$ldriveindex}->{cpqDaLogDrvFaultTol}, |
| 130 |
$tmpld->{$slot}->{$ldriveindex}->{cpqDaLogDrvCondition}) = |
| 131 |
map { lc $_ } split(/,\s*/, $2); |
| 132 |
$tmpld->{$slot}->{$ldriveindex}->{cpqDaLogDrvStatus} = |
| 133 |
$tmpld->{$slot}->{$ldriveindex}->{cpqDaLogDrvCondition}; |
| 134 |
$tmpld->{$slot}->{$ldriveindex}->{cpqDaLogDrvPhyDrvIDs} = 'unknown'; |
| 135 |
} elsif (/physicaldrive\s+(.+?)\s+\((.*)\)/) { |
| 136 |
# physicaldrive 2:0 (port 2:id 0 , Parallel SCSI, 36.4 GB, OK) |
| 137 |
# physicaldrive 2I:1:6 (port 2I:box 1:bay 6, SAS, 146 GB, OK) |
| 138 |
# physicaldrive 1:1 (box 1:bay 1, Parallel SCSI, 146 GB, OK) |
| 139 |
my $name = $1; |
| 140 |
my($location, $type, $size, $status) = split(/,/, $2); |
| 141 |
$status =~ s/^\s+//g; |
| 142 |
$status =~ s/\s+$//g; |
| 143 |
$status = lc $status; |
| 144 |
my %location = (); |
| 145 |
foreach (split(/:/, $location)) { |
| 146 |
$location{$1} = $2 if /(\w+)\s+(\w+)/; |
| 147 |
} |
| 148 |
$location{box} ||= 0; |
| 149 |
$location{id} ||= $pdriveindex; |
| 150 |
$location{bay} ||= $location{id}; |
| 151 |
$location{port} ||= $location{bay}; |
| 152 |
$tmppd->{$slot}->{$name}->{name} = lc $name; |
| 153 |
$tmppd->{$slot}->{$name}->{cpqDaPhyDrvCntlrIndex} = $cntlindex; |
| 154 |
$tmppd->{$slot}->{$name}->{cpqDaPhyDrvIndex} = $location{id}; |
| 155 |
$tmppd->{$slot}->{$name}->{cpqDaPhyDrvBay} = $location{bay}; |
| 156 |
$tmppd->{$slot}->{$name}->{cpqDaPhyDrvBusNumber} = $location{port}; |
| 157 |
$tmppd->{$slot}->{$name}->{cpqDaPhyDrvSize} = $size; |
| 158 |
$tmppd->{$slot}->{$name}->{cpqDaPhyDrvStatus} = $status; |
| 159 |
$tmppd->{$slot}->{$name}->{cpqDaPhyDrvCondition} = $status; |
| 160 |
$tmppd->{$slot}->{$name}->{ldriveindex} = $ldriveindex || -1; |
| 161 |
foreach (keys %{$tmppd->{$slot}->{$name}}) { |
| 162 |
$tmppd->{$slot}->{$name}->{$_} =~ s/^\s+//g; |
| 163 |
$tmppd->{$slot}->{$name}->{$_} =~ s/\s+$//g; |
| 164 |
$tmppd->{$slot}->{$name}->{$_} = lc $tmppd->{$slot}->{$name}->{$_}; |
| 165 |
} |
| 166 |
$pdriveindex++; |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
foreach my $slot (keys %{$tmpcntl}) { |
| 171 |
if (exists $tmpcntl->{$slot}->{cpqDaCntlrModel} && |
| 172 |
! $self->identified($tmpcntl->{$slot}->{cpqDaCntlrModel})) { |
| 173 |
delete $tmpcntl->{$slot}; |
| 174 |
delete $tmpaccel->{$slot}; |
| 175 |
delete $tmpencl->{$slot}; |
| 176 |
delete $tmpld->{$slot}; |
| 177 |
delete $tmppd->{$slot}; |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
#printf "%s\n", Data::Dumper::Dumper($tmpcntl); |
| 182 |
#printf "%s\n", Data::Dumper::Dumper($tmpaccel); |
| 183 |
#printf "%s\n", Data::Dumper::Dumper($tmpld); |
| 184 |
#printf "%s\n", Data::Dumper::Dumper($tmppd); |
| 185 |
foreach my $slot (sort { |
| 186 |
$tmpcntl->{$a}->{cpqDaCntlrIndex} <=> $tmpcntl->{$b}->{cpqDaCntlrIndex} |
| 187 |
}keys %{$tmpcntl}) { |
| 188 |
$tmpcntl->{$slot}->{runtime} = $self->{runtime}; |
| 189 |
push(@{$self->{controllers}}, |
| 190 |
HP::Proliant::Component::DiskSubsystem::Da::Controller->new( |
| 191 |
%{$tmpcntl->{$slot}})); |
| 192 |
} |
| 193 |
foreach my $slot (sort { |
| 194 |
$tmpaccel->{$a}->{cpqDaAccelCntlrIndex} <=> $tmpaccel->{$b}->{cpqDaAccelCntlrIndex} |
| 195 |
} keys %{$tmpaccel}) { |
| 196 |
$tmpaccel->{$slot}->{runtime} = $self->{runtime}; |
| 197 |
push(@{$self->{accelerators}}, |
| 198 |
HP::Proliant::Component::DiskSubsystem::Da::Accelerator->new( |
| 199 |
%{$tmpaccel->{$slot}})); |
| 200 |
} |
| 201 |
foreach my $slot (keys %{$tmpencl}) { |
| 202 |
foreach my $enclosureindex (keys %{$tmpencl->{$slot}}) { |
| 203 |
$tmpencl->{$slot}->{$enclosureindex}->{runtime} = $self->{runtime}; |
| 204 |
push(@{$self->{enclosures}}, |
| 205 |
HP::Proliant::Component::DiskSubsystem::Da::Enclosure->new( |
| 206 |
%{$tmpencl->{$slot}->{$enclosureindex}})); |
| 207 |
} |
| 208 |
} |
| 209 |
foreach my $slot (keys %{$tmpld}) { |
| 210 |
foreach my $ldriveindex (keys %{$tmpld->{$slot}}) { |
| 211 |
$tmpld->{$slot}->{$ldriveindex}->{runtime} = $self->{runtime}; |
| 212 |
push(@{$self->{logical_drives}}, |
| 213 |
HP::Proliant::Component::DiskSubsystem::Da::LogicalDrive->new( |
| 214 |
%{$tmpld->{$slot}->{$ldriveindex}})); |
| 215 |
} |
| 216 |
foreach my $pdriveindex (sort { |
| 217 |
(split ':', $a, 2)[0] cmp (split ':', $b, 2)[0] || |
| 218 |
(split ':', $a, 2)[1] cmp (split ':', $b, 2)[1] || |
| 219 |
(split ':', $a, 2)[2] <=> (split ':', $b, 2)[2] |
| 220 |
} keys %{$tmppd->{$slot}}) { |
| 221 |
$tmppd->{$slot}->{$pdriveindex}->{runtime} = $self->{runtime}; |
| 222 |
push(@{$self->{physical_drives}}, |
| 223 |
HP::Proliant::Component::DiskSubsystem::Da::PhysicalDrive->new( |
| 224 |
%{$tmppd->{$slot}->{$pdriveindex}})); |
| 225 |
} |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
sub identified { |
| 230 |
my $self = shift; |
| 231 |
my $info = shift; |
| 232 |
return 1 if $info =~ /Parallel SCSI/; |
| 233 |
return 1 if $info =~ /Smart Array/; # Trond: works fine on E200i, P400, E400 |
| 234 |
return 1 if $info =~ /MSA500/; |
| 235 |
#return 1 if $info =~ /Smart Array (5|6)/; |
| 236 |
#return 1 if $info =~ /Smart Array P400i/; # snmp sagt Da, trotz SAS in cli |
| 237 |
#return 1 if $info =~ /Smart Array P410i/; # dto |
| 238 |
return 0; |
| 239 |
} |