Debian Codegraph @

src/centreon/common/adic/tape/snmp/mode/components/temperature.pm

raw
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::adic::tape::snmp::mode::components::temperature;
22
23 use strict;
24 use warnings;
25
26 my %map_status = (
27 1 => 'nominal',
28 2 => 'warningLow', 3 => 'warningHigh',
29 4 => 'alarmLow', 5 => 'alarmHigh',
30 6 => 'notInstalled', 7 => 'noData',
31 );
32
33 my $mapping = {
34 temperatureSensorName => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.30.1.2' },
35 temperatureSensorStatus => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.30.1.3', map => \%map_status },
36 temperatureSensorDegreesCelsius => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.30.1.4' },
37 temperatureSensorWarningHi => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.30.1.8' },
38 temperatureSensorNominalHi => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.30.1.6' },
39 temperatureSensorNominalLo => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.30.1.5' },
40 temperatureSensorWarningLo => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.30.1.7' },
41 temperatureSensorLocation => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.30.1.9' },
42 };
43 my $oid_temperatureSensorEntry = '.1.3.6.1.4.1.3764.1.1.200.200.30.1';
44
45 sub load {
46 my ($self) = @_;
47
48 push @{$self->{request}}, { oid => $oid_temperatureSensorEntry };
49 }
50
51 sub check {
52 my ($self) = @_;
53
54 $self->{output}->output_add(long_msg => "Checking temperatures");
55 $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0};
56 return if ($self->check_filter(section => 'temperature'));
57
58 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_temperatureSensorEntry}})) {
59 next if ($oid !~ /^$mapping->{temperatureSensorStatus}->{oid}\.(.*)$/);
60 my $instance = $1;
61 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_temperatureSensorEntry}, instance => $instance);
62
63 $result->{temperatureSensorName} =~ s/\s+/ /g;
64 $result->{temperatureSensorName} = centreon::plugins::misc::trim($result->{temperatureSensorName});
65 $result->{temperatureSensorLocation} =~ s/,/_/g;
66 my $id = $result->{temperatureSensorName} . '_' . $result->{temperatureSensorLocation};
67
68 next if ($self->check_filter(section => 'temperature', instance => $id));
69 $self->{components}->{temperature}->{total}++;
70
71 $self->{output}->output_add(long_msg => sprintf("temperature '%s' status is '%s' [instance = %s] [value = %s]",
72 $id, $result->{temperatureSensorStatus}, $id,
73 $result->{temperatureSensorDegreesCelsius}));
74
75 my $exit = $self->get_severity(label => 'sensor', section => 'temperature', value => $result->{temperatureSensorStatus});
76 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
77 $self->{output}->output_add(severity => $exit,
78 short_msg => sprintf("Temperature '%s' status is '%s'", $id, $result->{temperatureSensorStatus}));
79 next;
80 }
81
82 if (defined($result->{temperatureSensorDegreesCelsius}) && $result->{temperatureSensorDegreesCelsius} =~ /[0-9]/) {
83 my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{temperatureSensorDegreesCelsius});
84 if ($checked == 0) {
85 $result->{temperatureSensorNominalLo} = (defined($result->{temperatureSensorNominalLo}) && $result->{temperatureSensorNominalLo} =~ /[0-9]/) ?
86 $result->{temperatureSensorNominalLo} : '';
87 $result->{temperatureSensorWarningLo} = (defined($result->{temperatureSensorWarningLo}) && $result->{temperatureSensorWarningLo} =~ /[0-9]/) ?
88 $result->{temperatureSensorWarningLo} : '';
89 $result->{temperatureSensorNominalHi} = (defined($result->{temperatureSensorNominalHi}) && $result->{temperatureSensorNominalHi} =~ /[0-9]/) ?
90 $result->{temperatureSensorNominalHi} : '';
91 $result->{temperatureSensorWarningHi} = (defined($result->{temperatureSensorWarningHi}) && $result->{temperatureSensorWarningHi} =~ /[0-9]/) ?
92 $result->{temperatureSensorWarningHi} : '';
93 my $warn_th = $result->{temperatureSensorNominalLo} . ':' . $result->{temperatureSensorNominalHi};
94 my $crit_th = $result->{temperatureSensorWarningLo} . ':' . $result->{temperatureSensorWarningHi};
95 $self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th);
96 $self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th);
97
98 $exit = $self->{perfdata}->threshold_check(value => $result->{temperatureSensorDegreesCelsius}, threshold => [ { label => 'critical-temperature-instance-' . $instance, exit_litteral => 'critical' },
99 { label => 'warning-temperature-instance-' . $instance, exit_litteral => 'warning' } ]);
100 $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance);
101 $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance);
102 }
103
104 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
105 $self->{output}->output_add(severity => $exit,
106 short_msg => sprintf("Temperature '%s' is %s degree centigrade", $id, $result->{temperatureSensorDegreesCelsius}));
107 }
108 $self->{output}->perfdata_add(
109 label => 'temp', unit => 'C',
110 nlabel => 'hardware.temperature.celsius',
111 instances => $id,
112 value => $result->{temperatureSensorDegreesCelsius},
113 warning => $warn,
114 critical => $crit,
115 );
116 }
117 }
118 }
119
120 1;