Debian Codegraph @

src/hardware/sensors/netbotz/snmp/mode/components/dewpoint.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 hardware::sensors::netbotz::snmp::mode::components::dewpoint;
22
23 use strict;
24 use warnings;
25 use hardware::sensors::netbotz::snmp::mode::components::resources qw($map_status);
26
27 sub load {
28 my ($self) = @_;
29
30 $self->{mapping_dewpoint} = {
31 dewPointSensorId => { oid => '.1.3.6.1.4.1.' . $self->{netbotz_branch} . '.4.1.3.1.1' },
32 dewPointSensorValue => { oid => '.1.3.6.1.4.1.' . $self->{netbotz_branch} . '.4.1.3.1.2' },
33 dewPointSensorErrorStatus => { oid => '.1.3.6.1.4.1.' . $self->{netbotz_branch} . '.4.1.3.1.3', map => $map_status },
34 dewPointSensorLabel => { oid => '.1.3.6.1.4.1.' . $self->{netbotz_branch} . '.4.1.3.1.4' }
35 };
36 $self->{oid_dewPointSensorEntry} = '.1.3.6.1.4.1.' . $self->{netbotz_branch} . '.4.1.3.1';
37 push @{$self->{request}}, {
38 oid => $self->{oid_dewPointSensorEntry},
39 end => $self->{mapping_dewpoint}->{dewPointSensorLabel}->{oid}
40 };
41 }
42
43 sub check {
44 my ($self) = @_;
45
46 $self->{output}->output_add(long_msg => "Checking dew points");
47 $self->{components}->{dewpoint} = { name => 'dew points', total => 0, skip => 0 };
48 return if ($self->check_filter(section => 'dewpoint'));
49
50 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $self->{oid_dewPointSensorEntry} }})) {
51 next if ($oid !~ /^$self->{mapping_dewpoint}->{dewPointSensorErrorStatus}->{oid}\.(.*)$/);
52 my $instance = $1;
53 my $result = $self->{snmp}->map_instance(
54 mapping => $self->{mapping_dewpoint},
55 results => $self->{results}->{ $self->{oid_dewPointSensorEntry} },
56 instance => $instance
57 );
58
59 next if ($self->check_filter(section => 'dewpoint', instance => $instance));
60 $self->{components}->{dewpoint}->{total}++;
61
62 $result->{dewPointSensorValue} *= 0.1;
63 my $label = defined($result->{dewPointSensorLabel}) && $result->{dewPointSensorLabel} ne '' ? $result->{dewPointSensorLabel} : $result->{dewPointSensorId};
64 $self->{output}->output_add(
65 long_msg => sprintf(
66 "dew point '%s' status is '%s' [instance = %s] [value = %s]",
67 $label,
68 $result->{dewPointSensorErrorStatus},
69 $instance,
70 $result->{dewPointSensorValue}
71 )
72 );
73
74 my $exit = $self->get_severity(label => 'default', section => 'dewpoint', value => $result->{dewPointSensorErrorStatus});
75 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
76 $self->{output}->output_add(
77 severity => $exit,
78 short_msg => sprintf(
79 "Dew point '%s' status is '%s'",
80 $label,
81 $result->{dewPointSensorErrorStatus}
82 )
83 );
84 }
85
86 my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'dewpoint', instance => $instance, value => $result->{dewPointSensorValue});
87 if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
88 $self->{output}->output_add(
89 severity => $exit2,
90 short_msg => sprintf(
91 "Dew point '%s' is %s C",
92 $label,
93 $result->{dewPointSensorValue}
94 )
95 );
96 }
97
98 $self->{output}->perfdata_add(
99 label => 'dewpoint', unit => 'C',
100 nlabel => 'hardware.sensor.dewpoint.celsius',
101 instances => $label,
102 value => $result->{dewPointSensorValue},
103 warning => $warn,
104 critical => $crit,
105 );
106 }
107 }
108
109 1;