| 1 |
package HP::BladeSystem; |
| 2 |
|
| 3 |
use strict; |
| 4 |
use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; |
| 5 |
use Data::Dumper; |
| 6 |
|
| 7 |
our @ISA = qw(HP::Server HP::Proliant::Component::SNMP); |
| 8 |
|
| 9 |
sub init { |
| 10 |
my $self = shift; |
| 11 |
$self->{components} = { |
| 12 |
common_enclosure_subsystem => undef, |
| 13 |
power_enclosure_subsystem => undef, |
| 14 |
power_supply_subsystem => undef, |
| 15 |
net_connector_subsystem => undef, |
| 16 |
server_blade_subsystem => undef, |
| 17 |
}; |
| 18 |
$self->{serial} = 'unknown'; |
| 19 |
$self->{product} = 'unknown'; |
| 20 |
$self->{romversion} = 'unknown'; |
| 21 |
$self->trace(3, 'BladeSystem identified'); |
| 22 |
$self->collect(); |
| 23 |
if (! $self->{runtime}->{plugin}->check_messages()) { |
| 24 |
$self->set_serial(); |
| 25 |
$self->analyze_common_enclosures(); |
| 26 |
$self->analyze_power_enclosures(); |
| 27 |
$self->analyze_power_supplies(); |
| 28 |
$self->analyze_net_connectors(); |
| 29 |
$self->analyze_server_blades(); |
| 30 |
$self->check_common_enclosures(); |
| 31 |
$self->check_power_enclosures(); |
| 32 |
$self->check_power_supplies(); |
| 33 |
$self->check_net_connectors(); |
| 34 |
$self->check_server_blades(); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
sub identify { |
| 39 |
my $self = shift; |
| 40 |
return sprintf "System: '%s', S/N: '%s'", |
| 41 |
$self->{product}, $self->{serial}; |
| 42 |
} |
| 43 |
|
| 44 |
sub dump { |
| 45 |
my $self = shift; |
| 46 |
printf STDERR "serial %s\n", $self->{serial}; |
| 47 |
printf STDERR "product %s\n", $self->{product}; |
| 48 |
printf STDERR "romversion %s\n", $self->{romversion}; |
| 49 |
printf STDERR "%s\n", Data::Dumper::Dumper($self->{enclosures}); |
| 50 |
} |
| 51 |
|
| 52 |
sub analyze_common_enclosures { |
| 53 |
my $self = shift; |
| 54 |
$self->{components}->{common_enclosure_subsystem} = |
| 55 |
HP::BladeSystem::Component::CommonEnclosureSubsystem->new( |
| 56 |
rawdata => $self->{rawdata}, |
| 57 |
method => $self->{method}, |
| 58 |
runtime => $self->{runtime}, |
| 59 |
); |
| 60 |
} |
| 61 |
|
| 62 |
sub analyze_power_enclosures { |
| 63 |
my $self = shift; |
| 64 |
$self->{components}->{power_enclosure_subsystem} = |
| 65 |
HP::BladeSystem::Component::PowerEnclosureSubsystem->new( |
| 66 |
rawdata => $self->{rawdata}, |
| 67 |
method => $self->{method}, |
| 68 |
runtime => $self->{runtime}, |
| 69 |
); |
| 70 |
} |
| 71 |
|
| 72 |
sub analyze_power_supplies { |
| 73 |
my $self = shift; |
| 74 |
$self->{components}->{power_supply_subsystem} = |
| 75 |
HP::BladeSystem::Component::PowerSupplySubsystem->new( |
| 76 |
rawdata => $self->{rawdata}, |
| 77 |
method => $self->{method}, |
| 78 |
runtime => $self->{runtime}, |
| 79 |
); |
| 80 |
} |
| 81 |
|
| 82 |
sub analyze_net_connectors { |
| 83 |
my $self = shift; |
| 84 |
$self->{components}->{net_connector_subsystem} = |
| 85 |
HP::BladeSystem::Component::NetConnectorSubsystem->new( |
| 86 |
rawdata => $self->{rawdata}, |
| 87 |
method => $self->{method}, |
| 88 |
runtime => $self->{runtime}, |
| 89 |
); |
| 90 |
} |
| 91 |
|
| 92 |
sub analyze_server_blades { |
| 93 |
my $self = shift; |
| 94 |
$self->{components}->{server_blade_subsystem} = |
| 95 |
HP::BladeSystem::Component::ServerBladeSubsystem->new( |
| 96 |
rawdata => $self->{rawdata}, |
| 97 |
method => $self->{method}, |
| 98 |
runtime => $self->{runtime}, |
| 99 |
); |
| 100 |
} |
| 101 |
|
| 102 |
sub check_common_enclosures { |
| 103 |
my $self = shift; |
| 104 |
$self->{components}->{common_enclosure_subsystem}->check(); |
| 105 |
$self->{components}->{common_enclosure_subsystem}->dump() |
| 106 |
if $self->{runtime}->{options}->{verbose} >= 2; |
| 107 |
} |
| 108 |
|
| 109 |
sub check_power_enclosures { |
| 110 |
my $self = shift; |
| 111 |
$self->{components}->{power_enclosure_subsystem}->check(); |
| 112 |
$self->{components}->{power_enclosure_subsystem}->dump() |
| 113 |
if $self->{runtime}->{options}->{verbose} >= 2; |
| 114 |
} |
| 115 |
|
| 116 |
sub check_power_supplies { |
| 117 |
my $self = shift; |
| 118 |
$self->{components}->{power_supply_subsystem}->check(); |
| 119 |
$self->{components}->{power_supply_subsystem}->dump() |
| 120 |
if $self->{runtime}->{options}->{verbose} >= 2; |
| 121 |
} |
| 122 |
|
| 123 |
sub check_net_connectors { |
| 124 |
my $self = shift; |
| 125 |
$self->{components}->{net_connector_subsystem}->check(); |
| 126 |
$self->{components}->{net_connector_subsystem}->dump() |
| 127 |
if $self->{runtime}->{options}->{verbose} >= 2; |
| 128 |
} |
| 129 |
|
| 130 |
sub check_server_blades { |
| 131 |
my $self = shift; |
| 132 |
$self->{components}->{server_blade_subsystem}->check(); |
| 133 |
$self->{components}->{server_blade_subsystem}->dump() |
| 134 |
if $self->{runtime}->{options}->{verbose} >= 2; |
| 135 |
} |
| 136 |
|
| 137 |
sub collect { |
| 138 |
my $self = shift; |
| 139 |
if ($self->{runtime}->{plugin}->opts->snmpwalk) { |
| 140 |
my $cpqRackMibCondition = '1.3.6.1.4.1.232.22.1.3.0'; |
| 141 |
$self->trace(3, 'getting cpqRackMibCondition'); |
| 142 |
if (! exists $self->{rawdata}->{$cpqRackMibCondition}) { |
| 143 |
$self->add_message(CRITICAL, |
| 144 |
'snmpwalk returns no health data (cpqrack-mib)'); |
| 145 |
} |
| 146 |
} else { |
| 147 |
my $net_snmp_version = Net::SNMP->VERSION(); # 5.002000 or 6.000000 |
| 148 |
#$params{'-translate'} = [ |
| 149 |
# -all => 0x0 |
| 150 |
#]; |
| 151 |
my ($session, $error) = |
| 152 |
Net::SNMP->session(%{$self->{runtime}->{snmpparams}}); |
| 153 |
if (! defined $session) { |
| 154 |
$self->{plugin}->add_message(CRITICAL, 'cannot create session object'); |
| 155 |
$self->trace(1, Data::Dumper::Dumper($self->{runtime}->{snmpparams})); |
| 156 |
} else { |
| 157 |
# revMajor is often used for discovery of hp devices |
| 158 |
my $cpqSeMibRev = '1.3.6.1.4.1.232.22.1'; |
| 159 |
my $cpqSeMibRevMajor = '1.3.6.1.4.1.232.22.1.1.0'; |
| 160 |
my $cpqRackMibCondition = '1.3.6.1.4.1.232.22.1.3.0'; |
| 161 |
$self->trace(3, 'getting cpqRackMibCondition'); |
| 162 |
my $result = $session->get_request( |
| 163 |
-varbindlist => [$cpqRackMibCondition] |
| 164 |
); |
| 165 |
if (!defined($result) || |
| 166 |
$result->{$cpqRackMibCondition} eq 'noSuchInstance' || |
| 167 |
$result->{$cpqRackMibCondition} eq 'noSuchObject' || |
| 168 |
$result->{$cpqRackMibCondition} eq 'endOfMibView') { |
| 169 |
$self->add_message(CRITICAL, |
| 170 |
'snmpwalk returns no health data (cpqrack-mib)'); |
| 171 |
$session->close; |
| 172 |
} else { |
| 173 |
$self->trace(3, 'getting cpqRackMibCondition done'); |
| 174 |
} |
| 175 |
} |
| 176 |
if (! $self->{runtime}->{plugin}->check_messages()) { |
| 177 |
# snmp peer is alive |
| 178 |
$self->trace(2, sprintf "Protocol is %s", |
| 179 |
$self->{runtime}->{snmpparams}->{'-version'}); |
| 180 |
my $oidtrees = [ |
| 181 |
["cpqSiComponent", "1.3.6.1.4.1.232.2.2"], |
| 182 |
["cpqSiAsset", "1.3.6.1.4.1.232.2.2.2"], |
| 183 |
#["cpqRackInfo", "1.3.6.1.4.1.232.22"], |
| 184 |
['cpqRackCommonEnclosureEntry', '1.3.6.1.4.1.232.22.2.3.1.1.1'], |
| 185 |
['cpqRackCommonEnclosureTempEntry', '1.3.6.1.4.1.232.22.2.3.1.2.1'], |
| 186 |
['cpqRackCommonEnclosureFanEntry', '1.3.6.1.4.1.232.22.2.3.1.3.1'], |
| 187 |
['cpqRackCommonEnclosureFuseEntry', '1.3.6.1.4.1.232.22.2.3.1.4.1'], |
| 188 |
['cpqRackCommonEnclosureManagerEntry', '1.3.6.1.4.1.232.22.2.3.1.6.1'], |
| 189 |
['cpqRackPowerEnclosureEntry', '1.3.6.1.4.1.232.22.2.3.3.1.1'], |
| 190 |
['cpqRackServerBladeEntry', '1.3.6.1.4.1.232.22.2.4.1.1.1'], |
| 191 |
['cpqRackPowerSupplyEntry', '1.3.6.1.4.1.232.22.2.5.1.1.1'], |
| 192 |
['cpqRackNetConnectorEntry', '1.3.6.1.4.1.232.22.2.6.1.1.1'], |
| 193 |
['cpqRackMibCondition', '1.3.6.1.4.1.232.22.1.3.0'], |
| 194 |
]; |
| 195 |
my $cpqSiComponent = "1.3.6.1.4.1.232.2.2"; |
| 196 |
my $cpqSiAsset = "1.3.6.1.4.1.232.2.2.2"; |
| 197 |
my $cpqRackInfo = "1.3.6.1.4.1.232.22"; |
| 198 |
$session->translate; |
| 199 |
my $response = {}; #break the walk up in smaller pieces |
| 200 |
foreach my $subtree (@{$oidtrees}) { |
| 201 |
my $tic = time; my $tac = $tic; |
| 202 |
my $response0 = $session->get_table( |
| 203 |
-baseoid => $subtree->[1]); |
| 204 |
if (scalar (keys %{$response0}) == 0) { |
| 205 |
$self->trace(2, sprintf "maxrepetitions failed. fallback"); |
| 206 |
$response0 = $session->get_table( |
| 207 |
-maxrepetitions => 1, |
| 208 |
-baseoid => $subtree->[1]); |
| 209 |
} |
| 210 |
$tac = time; |
| 211 |
$self->trace(2, sprintf "%03d seconds for walk %s (%d oids)", |
| 212 |
$tac - $tic, $subtree->[0], scalar(keys %{$response0})); |
| 213 |
map { $response->{$_} = $response0->{$_} } keys %{$response0}; |
| 214 |
} |
| 215 |
$session->close; |
| 216 |
map { $response->{$_} =~ s/^\s+//; $response->{$_} =~ s/\s+$//; } |
| 217 |
keys %$response; |
| 218 |
$self->{rawdata} = $response; |
| 219 |
} |
| 220 |
} |
| 221 |
return $self->{runtime}->{plugin}->check_messages(); |
| 222 |
} |
| 223 |
|
| 224 |
sub set_serial { |
| 225 |
my $self = shift; |
| 226 |
|
| 227 |
my $cpqSiSysSerialNum = "1.3.6.1.4.1.232.2.2.2.1.0"; |
| 228 |
my $cpqSiProductName = "1.3.6.1.4.1.232.2.2.4.2.0"; |
| 229 |
|
| 230 |
$self->{serial} = |
| 231 |
SNMP::Utils::get_object($self->{rawdata}, $cpqSiSysSerialNum); |
| 232 |
$self->{product} = |
| 233 |
SNMP::Utils::get_object($self->{rawdata}, $cpqSiProductName); |
| 234 |
$self->{serial} = $self->{serial}; |
| 235 |
$self->{product} = lc $self->{product}; |
| 236 |
$self->{romversion} = 'unknown'; |
| 237 |
##################################################################### |
| 238 |
$self->{runtime}->{product} = $self->{product}; |
| 239 |
} |
| 240 |
|