| 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::cisco::standard::snmp::mode::components::temperature; |
| 22 |
|
| 23 |
use strict; |
| 24 |
use warnings; |
| 25 |
|
| 26 |
my %map_temperature_state = ( |
| 27 |
1 => 'normal', |
| 28 |
2 => 'warning', |
| 29 |
3 => 'critical', |
| 30 |
4 => 'shutdown', |
| 31 |
5 => 'not present', |
| 32 |
6 => 'not functioning' |
| 33 |
); |
| 34 |
|
| 35 |
# In MIB 'CISCO-ENVMON-MIB' |
| 36 |
my $mapping = { |
| 37 |
ciscoEnvMonTemperatureStatusDescr => { oid => '.1.3.6.1.4.1.9.9.13.1.3.1.2' }, |
| 38 |
ciscoEnvMonTemperatureStatusValue => { oid => '.1.3.6.1.4.1.9.9.13.1.3.1.3' }, |
| 39 |
ciscoEnvMonTemperatureThreshold => { oid => '.1.3.6.1.4.1.9.9.13.1.3.1.4' }, |
| 40 |
ciscoEnvMonTemperatureState => { oid => '.1.3.6.1.4.1.9.9.13.1.3.1.6', map => \%map_temperature_state } |
| 41 |
}; |
| 42 |
my $oid_ciscoEnvMonTemperatureStatusEntry = '.1.3.6.1.4.1.9.9.13.1.3.1'; |
| 43 |
|
| 44 |
sub load { |
| 45 |
my ($self) = @_; |
| 46 |
|
| 47 |
push @{$self->{request}}, { oid => $oid_ciscoEnvMonTemperatureStatusEntry }; |
| 48 |
} |
| 49 |
|
| 50 |
sub check { |
| 51 |
my ($self) = @_; |
| 52 |
|
| 53 |
$self->{output}->output_add(long_msg => "Checking temperatures"); |
| 54 |
$self->{components}->{temperature} = { name => 'temperatures', total => 0, skip => 0 }; |
| 55 |
return if ($self->check_filter(section => 'temperature')); |
| 56 |
|
| 57 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_ciscoEnvMonTemperatureStatusEntry}})) { |
| 58 |
next if ($oid !~ /^$mapping->{ciscoEnvMonTemperatureState}->{oid}\.(.*)$/); |
| 59 |
my $instance = $1; |
| 60 |
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonTemperatureStatusEntry}, instance => $instance); |
| 61 |
|
| 62 |
next if ($self->check_filter(section => 'temperature', instance => $instance, name => $result->{ciscoEnvMonTemperatureStatusDescr})); |
| 63 |
$self->{components}->{temperature}->{total}++; |
| 64 |
|
| 65 |
$self->{output}->output_add( |
| 66 |
long_msg => sprintf( |
| 67 |
"temperature '%s' status is %s [instance: %s] [value: %s C]", |
| 68 |
$result->{ciscoEnvMonTemperatureStatusDescr}, $result->{ciscoEnvMonTemperatureState}, |
| 69 |
$instance, defined($result->{ciscoEnvMonTemperatureStatusValue}) ? $result->{ciscoEnvMonTemperatureStatusValue} : '-' |
| 70 |
) |
| 71 |
); |
| 72 |
my $exit = $self->get_severity(section => 'temperature', instance => $instance, value => $result->{ciscoEnvMonTemperatureState}); |
| 73 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 74 |
$self->{output}->output_add( |
| 75 |
severity => $exit, |
| 76 |
short_msg => sprintf( |
| 77 |
"Temperature '%s' status is %s", |
| 78 |
$result->{ciscoEnvMonTemperatureStatusDescr}, $result->{ciscoEnvMonTemperatureState} |
| 79 |
) |
| 80 |
); |
| 81 |
} |
| 82 |
|
| 83 |
next if (!defined($result->{ciscoEnvMonTemperatureStatusValue})); |
| 84 |
|
| 85 |
my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, name => $result->{ciscoEnvMonTemperatureStatusDescr}, value => $result->{ciscoEnvMonTemperatureStatusValue}); |
| 86 |
if ($checked == 0) { |
| 87 |
my $warn_th = undef; |
| 88 |
my $crit_th = '~:' . $result->{ciscoEnvMonTemperatureThreshold}; |
| 89 |
$self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th); |
| 90 |
$self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th); |
| 91 |
$warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance); |
| 92 |
$crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance); |
| 93 |
} |
| 94 |
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { |
| 95 |
$self->{output}->output_add( |
| 96 |
severity => $exit2, |
| 97 |
short_msg => sprintf("Temperature '%s' is %s degree centigrade", $result->{ciscoEnvMonTemperatureStatusDescr}, $result->{ciscoEnvMonTemperatureStatusValue}) |
| 98 |
); |
| 99 |
} |
| 100 |
$self->{output}->perfdata_add( |
| 101 |
label => "temp", unit => 'C', |
| 102 |
nlabel => 'hardware.temperature.celsius', |
| 103 |
instances => $result->{ciscoEnvMonTemperatureStatusDescr}, |
| 104 |
value => $result->{ciscoEnvMonTemperatureStatusValue}, |
| 105 |
warning => $warn, |
| 106 |
critical => $crit |
| 107 |
); |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
1; |