| 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::h3c::snmp::mode::components::sensor; |
| 22 |
|
| 23 |
use strict; |
| 24 |
use warnings; |
| 25 |
|
| 26 |
my %map_sensor_status = ( |
| 27 |
1 => 'notSupported', |
| 28 |
2 => 'normal', |
| 29 |
4 => 'entityAbsent', |
| 30 |
81 => 'sensorError', |
| 31 |
91 => 'hardwareFaulty' |
| 32 |
); |
| 33 |
|
| 34 |
sub check { |
| 35 |
my ($self) = @_; |
| 36 |
|
| 37 |
$self->{output}->output_add(long_msg => "Checking sensors"); |
| 38 |
$self->{components}->{sensor} = {name => 'sensors', total => 0, skip => 0}; |
| 39 |
return if ($self->check_filter(section => 'sensor')); |
| 40 |
|
| 41 |
my $mapping = { |
| 42 |
EntityExtErrorStatus => { oid => $self->{branch} . '.19', map => \%map_sensor_status }, |
| 43 |
}; |
| 44 |
my $mapping2 = { |
| 45 |
EntityExtTemperature => { oid => $self->{branch} . '.12' }, |
| 46 |
EntityExtTemperatureThreshold => { oid => $self->{branch} . '.13' }, |
| 47 |
}; |
| 48 |
|
| 49 |
my @instances = $self->get_instance_class(class => { 8 => 1 }); |
| 50 |
return if (scalar(@instances) == 0); |
| 51 |
|
| 52 |
$self->{snmp}->load( |
| 53 |
oids => [$mapping2->{EntityExtTemperature}->{oid}, $mapping2->{EntityExtTemperatureThreshold}->{oid}], |
| 54 |
instances => [@instances] |
| 55 |
); |
| 56 |
my $results = $self->{snmp}->get_leef(); |
| 57 |
|
| 58 |
my ($exit, $warn, $crit, $checked); |
| 59 |
foreach my $instance (sort @instances) { |
| 60 |
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$self->{branch} . '.19'}, instance => $instance); |
| 61 |
my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $results, instance => $instance); |
| 62 |
|
| 63 |
next if (!defined($result->{EntityExtErrorStatus})); |
| 64 |
next if ($self->check_filter(section => 'sensor', instance => $instance)); |
| 65 |
if ($result->{EntityExtErrorStatus} =~ /entityAbsent/i) { |
| 66 |
$self->absent_problem(section => 'sensor', instance => $instance); |
| 67 |
next; |
| 68 |
} |
| 69 |
|
| 70 |
my $name = ''; |
| 71 |
$name = $self->get_short_name(instance => $instance) if (defined($self->{short_name}) && $self->{short_name} == 1); |
| 72 |
$name = $self->get_long_name(instance => $instance) unless (defined($self->{short_name}) && $self->{short_name} == 1 && defined($name) && $name ne ''); |
| 73 |
$self->{components}->{sensor}->{total}++; |
| 74 |
|
| 75 |
$self->{output}->output_add( |
| 76 |
long_msg => sprintf( |
| 77 |
"Sensor '%s' status is '%s' [instance: %s]", |
| 78 |
$name, $result->{EntityExtErrorStatus}, $instance |
| 79 |
) |
| 80 |
); |
| 81 |
$exit = $self->get_severity(section => 'sensor', value => $result->{EntityExtErrorStatus}); |
| 82 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 83 |
$self->{output}->output_add( |
| 84 |
severity => $exit, |
| 85 |
short_msg => sprintf("Sensor '%s' status is '%s'", $name, $result->{EntityExtErrorStatus}) |
| 86 |
); |
| 87 |
} |
| 88 |
|
| 89 |
next if (defined($result2->{EntityExtTemperature}) && ($result2->{EntityExtTemperature} <= 0 || $result2->{EntityExtTemperature} == 65535)); |
| 90 |
|
| 91 |
($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result2->{EntityExtTemperature}); |
| 92 |
if ($checked == 0 && defined($result2->{EntityExtTemperatureThreshold}) && |
| 93 |
$result2->{EntityExtTemperatureThreshold} > 0 && $result2->{EntityExtTemperatureThreshold} < 65535) { |
| 94 |
my $crit_th = '~:' . $result2->{EntityExtTemperatureThreshold}; |
| 95 |
$self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => undef); |
| 96 |
$self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th); |
| 97 |
|
| 98 |
$exit = $self->{perfdata}->threshold_check( |
| 99 |
value => $result2->{EntityExtTemperature}, |
| 100 |
threshold => [ |
| 101 |
{ label => 'critical-temperature-instance-' . $instance, exit_litteral => 'critical' }, |
| 102 |
{ label => 'warning-temperature-instance-' . $instance, exit_litteral => 'warning' } |
| 103 |
] |
| 104 |
); |
| 105 |
$warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance); |
| 106 |
$crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance); |
| 107 |
} |
| 108 |
|
| 109 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 110 |
$self->{output}->output_add( |
| 111 |
severity => $exit, |
| 112 |
short_msg => sprintf("Temperature sensor '%s' is %s degree centigrade", $name, $result2->{EntityExtTemperature}) |
| 113 |
); |
| 114 |
} |
| 115 |
|
| 116 |
$self->{output}->perfdata_add( |
| 117 |
label => 'temp', unit => 'C', |
| 118 |
nlabel => 'hardware.sensor.temperature.celsius', |
| 119 |
instances => $instance, |
| 120 |
value => $result2->{EntityExtTemperature}, |
| 121 |
warning => $warn, |
| 122 |
critical => $crit, |
| 123 |
); |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
1; |