Debian Codegraph @

src/network/dlink/standard/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 network::dlink::standard::snmp::mode::components::temperature;
22
23 use strict;
24 use warnings;
25
26 my $map_status = {
27 1 => 'ok', 2 => 'abnormal'
28 };
29
30 my $mapping_equipment = {
31 swTemperatureCurrent => { oid => '.1.3.6.1.4.1.171.12.11.1.8.1.2' }
32 };
33 my $mapping_industrial = {
34 description => { oid => '.1.3.6.1.4.1.171.14.5.1.1.1.1.3' }, # dEntityExtEnvTempDescr
35 current => { oid => '.1.3.6.1.4.1.171.14.5.1.1.1.1.4' }, # dEntityExtEnvTempCurrent
36 threshold_low => { oid => '.1.3.6.1.4.1.171.14.5.1.1.1.1.5' }, # dEntityExtEnvTempThresholdLow
37 threshold_high => { oid => '.1.3.6.1.4.1.171.14.5.1.1.1.1.6' }, # dEntityExtEnvTempThresholdHigh
38 status => { oid => '.1.3.6.1.4.1.171.14.5.1.1.1.1.7', map => $map_status } # dEntityExtEnvTempStatus
39 };
40 my $oid_dEntityExtEnvTempEntry = '.1.3.6.1.4.1.171.14.5.1.1.1.1';
41
42 my $mapping_common = {
43 description => { oid => '.1.3.6.1.4.1.171.17.5.1.1.1.1.3' }, # esEntityExtEnvTempDescr
44 current => { oid => '.1.3.6.1.4.1.171.17.5.1.1.1.1.4' }, # esEntityExtEnvTempCurrent
45 threshold_low => { oid => '.1.3.6.1.4.1.171.17.5.1.1.1.1.5' }, # esEntityExtEnvTempThresholdLow
46 threshold_high => { oid => '.1.3.6.1.4.1.171.17.5.1.1.1.1.6' }, # esEntityExtEnvTempThresholdHigh
47 status => { oid => '.1.3.6.1.4.1.171.17.5.1.1.1.1.7', map => $map_status } # esEntityExtEnvTempStatus
48 };
49 my $oid_esEntityExtEnvTempEntry = '.1.3.6.1.4.1.171.17.5.1.1.1.1';
50
51 sub load {
52 my ($self) = @_;
53
54 push @{$self->{request}},
55 { oid => $mapping_equipment->{swTemperatureCurrent}->{oid} },
56 { oid => $oid_dEntityExtEnvTempEntry, start => $mapping_industrial->{description}->{oid} },
57 { oid => $oid_esEntityExtEnvTempEntry, start => $mapping_common->{description}->{oid} }
58 ;
59 }
60
61 sub check_temperature_equipment {
62 my ($self, %options) = @_;
63
64 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $mapping_equipment->{swTemperatureCurrent}->{oid} }})) {
65 $oid =~ /^$mapping_equipment->{swTemperatureCurrent}->{oid}\.(.*)$/;
66 my $instance = $1;
67 my $result = $self->{snmp}->map_instance(mapping => $mapping_equipment, results => $self->{results}->{ $mapping_equipment->{swTemperatureCurrent}->{oid} }, instance => $instance);
68
69 next if ($self->check_filter(section => 'temperature', instance => $instance));
70 $self->{components}->{temperature}->{total}++;
71
72 $self->{output}->output_add(long_msg =>
73 sprintf(
74 "temperature '%s' is %dC.",
75 $instance,
76 $result->{swTemperatureCurrent}
77 )
78 );
79
80 my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{swTemperatureCurrent});
81 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
82 $self->{output}->output_add(
83 severity => $exit,
84 short_msg => sprintf(
85 "Temperature '%s' is %s degree centigrade",
86 $instance,
87 $result->{swTemperatureCurrent}
88 )
89 );
90 }
91 $self->{output}->perfdata_add(
92 unit => 'C',
93 nlabel => 'hardware.temperature.celsius',
94 instances => $instance,
95 value => $result->{swTemperatureCurrent},
96 warning => $warn,
97 critical => $crit
98 );
99 }
100 }
101
102 sub check_temperature {
103 my ($self, %options) = @_;
104
105 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $options{entry} }})) {
106 next if ($oid !~ /^$options{mapping}->{status}->{oid}\.(\d+)\.(\d+)$/);
107 my ($unit_id, $temp_id) = ($1, $2);
108 my $instance = $1 . '.' . $2;
109 my $result = $self->{snmp}->map_instance(mapping => $options{mapping}, results => $self->{results}->{ $options{entry} }, instance => $instance);
110
111 my $description = 'unit' . $unit_id . ':temp' . $temp_id;
112 next if ($self->check_filter(section => 'temperature', instance => $instance));
113 $self->{components}->{temperature}->{total}++;
114
115 $self->{output}->output_add(
116 long_msg => sprintf(
117 "temperature '%s' status is '%s' [instance: %s, description: %s, current: %s]",
118 $description,
119 $result->{status},
120 $instance,
121 $result->{description},
122 $result->{current}
123 )
124 );
125 my $exit = $self->get_severity(section => 'temperature', value => $result->{status});
126 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
127 $self->{output}->output_add(
128 severity => $exit,
129 short_msg => sprintf(
130 "temperature '%s' status is %s",
131 $description, $result->{status}
132 )
133 );
134 }
135
136 next if (!defined($result->{current}));
137
138 my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{current});
139 if ($checked == 0) {
140 my $warn_th = '';
141 my $crit_th = defined($result->{threshold_high}) && $result->{threshold_high} =~ /\d/ ? $result->{threshold_high} : '';
142 $crit_th = $result->{threshold_low} . ':' . $crit_th if (defined($result->{threshold_low}) && $result->{threshold_low} =~ /\d/);
143
144 $self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th);
145 $self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th);
146 $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance);
147 $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance)
148 }
149
150 if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
151 $self->{output}->output_add(
152 severity => $exit2,
153 short_msg => sprintf(
154 "temperature '%s' is %s degree centigrate",
155 $description,
156 $result->{current}
157 )
158 );
159 }
160 $self->{output}->perfdata_add(
161 unit => 'C',
162 nlabel => 'hardware.temperature.celsius',
163 instances => ['unit' . $unit_id, 'temp' . $temp_id],
164 value => $result->{current},
165 warning => $warn,
166 critical => $crit
167 );
168 }
169 }
170
171 sub check {
172 my ($self) = @_;
173
174 $self->{output}->output_add(long_msg => 'checking temperatures');
175 $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0};
176 return if ($self->check_filter(section => 'temperature'));
177
178 check_temperature_equipment($self);
179 check_temperature($self, entry => $oid_dEntityExtEnvTempEntry, mapping => $mapping_industrial);
180 check_temperature($self, entry => $oid_esEntityExtEnvTempEntry, mapping => $mapping_common);
181 }
182
183 1;