| 1 |
package HP::Proliant::Component::TemperatureSubsystem; |
| 2 |
our @ISA = qw(HP::Proliant::Component); |
| 3 |
|
| 4 |
use strict; |
| 5 |
use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; |
| 6 |
|
| 7 |
sub new { |
| 8 |
my $class = shift; |
| 9 |
################################## custom_thresholds |
| 10 |
my %params = @_; |
| 11 |
my $self = { |
| 12 |
runtime => $params{runtime}, |
| 13 |
rawdata => $params{rawdata}, |
| 14 |
method => $params{method}, |
| 15 |
condition => $params{condition}, |
| 16 |
status => $params{status}, |
| 17 |
temperatures => [], |
| 18 |
blacklisted => 0, |
| 19 |
info => undef, |
| 20 |
extendedinfo => undef, |
| 21 |
}; |
| 22 |
bless $self, $class; |
| 23 |
if ($params{runtime}->{options}->{customthresholds}) { |
| 24 |
if (-f $params{runtime}->{options}->{customthresholds}) { |
| 25 |
$params{runtime}->{options}->{customthresholds} = |
| 26 |
do { local (@ARGV, $/) = |
| 27 |
$params{runtime}->{options}->{customthresholds}; <> }; |
| 28 |
} |
| 29 |
foreach my $ct_items |
| 30 |
(split(/\//, $params{runtime}->{options}->{customthresholds})) { |
| 31 |
if ($ct_items =~ /^(\d+):(\d+)$/) { |
| 32 |
$params{runtime}->{options}->{thresholds}->{$1} = $2; |
| 33 |
} else { |
| 34 |
die sprintf "invalid threshold %s", $ct_items; |
| 35 |
} |
| 36 |
} |
| 37 |
} |
| 38 |
if ($self->{method} eq 'snmp') { |
| 39 |
return HP::Proliant::Component::TemperatureSubsystem::SNMP->new(%params); |
| 40 |
} elsif ($self->{method} eq 'cli') { |
| 41 |
return HP::Proliant::Component::TemperatureSubsystem::CLI->new(%params); |
| 42 |
} else { |
| 43 |
die "unknown method"; |
| 44 |
} |
| 45 |
return $self; |
| 46 |
} |
| 47 |
|
| 48 |
sub check { |
| 49 |
my $self = shift; |
| 50 |
my $errorfound = 0; |
| 51 |
$self->add_info('checking temperatures'); |
| 52 |
if (scalar (@{$self->{temperatures}}) == 0) { |
| 53 |
#$self->overall_check(); |
| 54 |
$self->add_info('no temperatures found'); |
| 55 |
} else { |
| 56 |
foreach (sort { $a->{cpqHeTemperatureIndex} <=> $b->{cpqHeTemperatureIndex}} |
| 57 |
@{$self->{temperatures}}) { |
| 58 |
$_->check(); |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
sub dump { |
| 64 |
my $self = shift; |
| 65 |
foreach (@{$self->{temperatures}}) { |
| 66 |
$_->dump(); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
package HP::Proliant::Component::TemperatureSubsystem::Temperature; |
| 72 |
our @ISA = qw(HP::Proliant::Component::TemperatureSubsystem); |
| 73 |
|
| 74 |
use strict; |
| 75 |
use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; |
| 76 |
|
| 77 |
sub new { |
| 78 |
my $class = shift; |
| 79 |
my %params = @_; |
| 80 |
my $self = { |
| 81 |
runtime => $params{runtime}, |
| 82 |
cpqHeTemperatureChassis => $params{cpqHeTemperatureChassis}, |
| 83 |
cpqHeTemperatureIndex => $params{cpqHeTemperatureIndex}, |
| 84 |
cpqHeTemperatureLocale => $params{cpqHeTemperatureLocale}, |
| 85 |
cpqHeTemperatureCelsius => $params{cpqHeTemperatureCelsius}, |
| 86 |
cpqHeTemperatureThresholdCelsius => $params{cpqHeTemperatureThresholdCelsius}, |
| 87 |
cpqHeTemperatureCondition => $params{cpqHeTemperatureCondition}, |
| 88 |
cpqHeTemperatureThresholdType => $params{cpqHeTemperatureThresholdType} || "unknown", |
| 89 |
blacklisted => 0, |
| 90 |
info => undef, |
| 91 |
extendedinfo => undef, |
| 92 |
}; |
| 93 |
bless $self, $class; |
| 94 |
if ($params{runtime}->{options}->{celsius}) { |
| 95 |
$self->{cpqHeTemperatureUnits} = 'C'; |
| 96 |
$self->{cpqHeTemperature} = $self->{cpqHeTemperatureCelsius}; |
| 97 |
$self->{cpqHeTemperatureThreshold} = |
| 98 |
$self->{cpqHeTemperatureThresholdCelsius}; |
| 99 |
} else { |
| 100 |
$self->{cpqHeTemperatureUnits} = 'F'; |
| 101 |
$self->{cpqHeTemperature} = |
| 102 |
(($self->{cpqHeTemperatureCelsius} * 9) / 5) + 32; |
| 103 |
$self->{cpqHeTemperatureThreshold} = |
| 104 |
(($self->{cpqHeTemperatureThresholdCelsius} * 9) / 5) + 32; |
| 105 |
} |
| 106 |
my $index = $self->{cpqHeTemperatureIndex}; |
| 107 |
if (exists $params{runtime}->{options}->{thresholds}->{$index}) { |
| 108 |
$self->{cpqHeTemperatureThreshold} = |
| 109 |
$params{runtime}->{options}->{thresholds}->{$index}; |
| 110 |
|
| 111 |
} |
| 112 |
if ($self->{cpqHeTemperatureThresholdCelsius} == -99) { |
| 113 |
bless $self, 'HP::Proliant::Component::TemperatureSubsystem::SoSTemperature'; |
| 114 |
} elsif ($self->{cpqHeTemperatureThresholdCelsius} == 0) { |
| 115 |
# taucht auf, seit man gen8 ueber das ilo abfragen kann |
| 116 |
bless $self, 'HP::Proliant::Component::TemperatureSubsystem::SoSTemperature'; |
| 117 |
} |
| 118 |
return $self; |
| 119 |
} |
| 120 |
|
| 121 |
sub check { |
| 122 |
my $self = shift; |
| 123 |
$self->blacklist('t', $self->{cpqHeTemperatureIndex}); |
| 124 |
if ($self->{cpqHeTemperature} > $self->{cpqHeTemperatureThreshold}) { |
| 125 |
$self->add_info(sprintf "%d %s temperature too high (%d%s, %d max)", |
| 126 |
$self->{cpqHeTemperatureIndex}, $self->{cpqHeTemperatureLocale}, |
| 127 |
$self->{cpqHeTemperature}, $self->{cpqHeTemperatureUnits}, |
| 128 |
$self->{cpqHeTemperatureThreshold}); |
| 129 |
$self->add_message(CRITICAL, $self->{info}); |
| 130 |
} elsif ($self->{cpqHeTemperature} < 0) { |
| 131 |
# #21 SCSI_BACKPLANE_ZONE -1C/31F 60C/140F OK - can't be true |
| 132 |
$self->add_info(sprintf "%d %s temperature too low (%d%s)", |
| 133 |
$self->{cpqHeTemperatureIndex}, $self->{cpqHeTemperatureLocale}, |
| 134 |
$self->{cpqHeTemperature}, $self->{cpqHeTemperatureUnits}); |
| 135 |
$self->add_message(CRITICAL, $self->{info}); |
| 136 |
} else { |
| 137 |
$self->add_info(sprintf "%d %s temperature is %d%s (%d max)", |
| 138 |
$self->{cpqHeTemperatureIndex}, $self->{cpqHeTemperatureLocale}, |
| 139 |
$self->{cpqHeTemperature}, $self->{cpqHeTemperatureUnits}, |
| 140 |
$self->{cpqHeTemperatureThreshold}); |
| 141 |
} |
| 142 |
if ($self->{runtime}->{options}->{perfdata} == 2) { |
| 143 |
$self->{runtime}->{plugin}->add_perfdata( |
| 144 |
label => sprintf('temp_%s', $self->{cpqHeTemperatureIndex}), |
| 145 |
value => $self->{cpqHeTemperature}, |
| 146 |
warning => $self->{cpqHeTemperatureThreshold}, |
| 147 |
critical => $self->{cpqHeTemperatureThreshold} |
| 148 |
); |
| 149 |
} elsif ($self->{runtime}->{options}->{perfdata} == 1) { |
| 150 |
$self->{runtime}->{plugin}->add_perfdata( |
| 151 |
label => sprintf('temp_%s_%s', $self->{cpqHeTemperatureIndex}, |
| 152 |
$self->{cpqHeTemperatureLocale}), |
| 153 |
value => $self->{cpqHeTemperature}, |
| 154 |
warning => $self->{cpqHeTemperatureThreshold}, |
| 155 |
critical => $self->{cpqHeTemperatureThreshold} |
| 156 |
); |
| 157 |
} |
| 158 |
$self->add_extendedinfo(sprintf "temp_%s=%d", |
| 159 |
$self->{cpqHeTemperatureIndex}, |
| 160 |
$self->{cpqHeTemperature}); |
| 161 |
} |
| 162 |
|
| 163 |
sub dump { |
| 164 |
my $self = shift; |
| 165 |
printf "[TEMP_%s]\n", $self->{cpqHeTemperatureIndex}; |
| 166 |
foreach (qw(cpqHeTemperatureChassis cpqHeTemperatureIndex |
| 167 |
cpqHeTemperatureLocale cpqHeTemperatureCelsius cpqHeTemperatureThreshold |
| 168 |
cpqHeTemperatureThresholdType cpqHeTemperatureCondition)) { |
| 169 |
printf "%s: %s\n", $_, $self->{$_}; |
| 170 |
} |
| 171 |
printf "info: %s\n\n", $self->{info}; |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
package HP::Proliant::Component::TemperatureSubsystem::SoSTemperature; |
| 176 |
our @ISA = qw(HP::Proliant::Component::TemperatureSubsystem::Temperature); |
| 177 |
|
| 178 |
use strict; |
| 179 |
use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; |
| 180 |
|
| 181 |
sub check { |
| 182 |
my $self = shift; |
| 183 |
$self->blacklist('t', $self->{cpqHeTemperatureIndex}); |
| 184 |
$self->add_info(sprintf "%d %s temperature is %d%s (no thresh.)", |
| 185 |
$self->{cpqHeTemperatureIndex}, $self->{cpqHeTemperatureLocale}, |
| 186 |
$self->{cpqHeTemperature}, $self->{cpqHeTemperatureUnits}); |
| 187 |
if ($self->{runtime}->{options}->{perfdata} == 2) { |
| 188 |
$self->{runtime}->{plugin}->add_perfdata( |
| 189 |
label => sprintf('temp_%s', $self->{cpqHeTemperatureIndex}), |
| 190 |
value => $self->{cpqHeTemperature}, |
| 191 |
); |
| 192 |
} elsif ($self->{runtime}->{options}->{perfdata} == 1) { |
| 193 |
$self->{runtime}->{plugin}->add_perfdata( |
| 194 |
label => sprintf('temp_%s_%s', $self->{cpqHeTemperatureIndex}, |
| 195 |
$self->{cpqHeTemperatureLocale}), |
| 196 |
value => $self->{cpqHeTemperature}, |
| 197 |
); |
| 198 |
} |
| 199 |
$self->add_extendedinfo(sprintf "temp_%s=%d", |
| 200 |
$self->{cpqHeTemperatureIndex}, |
| 201 |
$self->{cpqHeTemperature}); |
| 202 |
} |
| 203 |
|
| 204 |
1; |
| 205 |
|