| 1 |
# |
| 2 |
# Copyright 2024 Centreon (http://www.centreon.com/) |
| 3 |
# |
| 4 |
# Centreon is a full-fledged industry-strength solution that meets |
| 5 |
# the needs in IT infrastructure and application monitoring for |
| 6 |
# service performance. |
| 7 |
# |
| 8 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
# you may not use this file except in compliance with the License. |
| 10 |
# You may obtain a copy of the License at |
| 11 |
# |
| 12 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
# |
| 14 |
# Unless required by applicable law or agreed to in writing, software |
| 15 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
# See the License for the specific language governing permissions and |
| 18 |
# limitations under the License. |
| 19 |
# |
| 20 |
|
| 21 |
package centreon::common::foundry::snmp::mode::components::temperature; |
| 22 |
|
| 23 |
use strict; |
| 24 |
use warnings; |
| 25 |
|
| 26 |
my $mapping = { |
| 27 |
snChasActualTemperature => { oid => '.1.3.6.1.4.1.1991.1.1.1.1.18' }, |
| 28 |
snChasWarningTemperature => { oid => '.1.3.6.1.4.1.1991.1.1.1.1.19' }, |
| 29 |
snChasShutdownTemperature => { oid => '.1.3.6.1.4.1.1991.1.1.1.1.20' } |
| 30 |
}; |
| 31 |
my $oid_snChasGen = '.1.3.6.1.4.1.1991.1.1.1.1'; |
| 32 |
|
| 33 |
sub load { |
| 34 |
my ($self) = @_; |
| 35 |
|
| 36 |
push @{$self->{request}}, { |
| 37 |
oid => $oid_snChasGen, |
| 38 |
start => $mapping->{snChasActualTemperature}->{oid}, |
| 39 |
end => $mapping->{snChasShutdownTemperature}->{oid} |
| 40 |
}; |
| 41 |
} |
| 42 |
|
| 43 |
sub check { |
| 44 |
my ($self) = @_; |
| 45 |
|
| 46 |
$self->{output}->output_add(long_msg => 'Checking temperatures'); |
| 47 |
$self->{components}->{temperature} = { name => 'temperatures', total => 0, skip => 0 }; |
| 48 |
return if ($self->check_filter(section => 'temperature')); |
| 49 |
|
| 50 |
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_snChasGen}, instance => '0'); |
| 51 |
my ($name, $instance) = ('chassi', 1); |
| 52 |
|
| 53 |
next if ($self->check_filter(section => 'temperature', instance => $instance)); |
| 54 |
|
| 55 |
$self->{components}->{temperature}->{total}++; |
| 56 |
|
| 57 |
$result->{snChasActualTemperature} *= 0.5; |
| 58 |
$result->{snChasWarningTemperature} *= 0.5; |
| 59 |
$result->{snChasShutdownTemperature} *= 0.5; |
| 60 |
$self->{output}->output_add( |
| 61 |
long_msg => sprintf( |
| 62 |
"temperature '%s' is %s celsius [instance = %s]", |
| 63 |
$name, $result->{snChasActualTemperature}, $instance |
| 64 |
) |
| 65 |
); |
| 66 |
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{snChasActualTemperature}); |
| 67 |
if ($checked == 0) { |
| 68 |
my $warn_th = defined($result->{snChasWarningTemperature}) ? $result->{snChasWarningTemperature} : ''; |
| 69 |
my $crit_th = defined($result->{snChasShutdownTemperature}) ? $result->{snChasShutdownTemperature} : ''; |
| 70 |
$self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th); |
| 71 |
$self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th); |
| 72 |
|
| 73 |
$exit = $self->{perfdata}->threshold_check( |
| 74 |
value => $result->{snChasActualTemperature}, |
| 75 |
threshold => [ |
| 76 |
{ label => 'critical-temperature-instance-' . $instance, exit_litteral => 'critical' }, |
| 77 |
{ label => 'warning-temperature-instance-' . $instance, exit_litteral => 'warning' } |
| 78 |
] |
| 79 |
); |
| 80 |
$warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance); |
| 81 |
$crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance) |
| 82 |
} |
| 83 |
|
| 84 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 85 |
$self->{output}->output_add( |
| 86 |
severity => $exit, |
| 87 |
short_msg => sprintf( |
| 88 |
"temperature '%s' is %s celsius", |
| 89 |
$name, |
| 90 |
$result->{snChasActualTemperature} |
| 91 |
) |
| 92 |
); |
| 93 |
} |
| 94 |
|
| 95 |
$self->{output}->perfdata_add( |
| 96 |
nlabel => 'hardware.temperature.celsius', |
| 97 |
unit => 'C', |
| 98 |
instances => $name, |
| 99 |
value => $result->{snChasActualTemperature}, |
| 100 |
warning => $warn, |
| 101 |
critical => $crit |
| 102 |
); |
| 103 |
} |
| 104 |
|
| 105 |
1; |