Debian Codegraph @

src/hardware/sensors/netbotz/snmp/mode/components/doorswitch.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::doorswitch;
22
23 use strict;
24 use warnings;
25 use hardware::sensors::netbotz::snmp::mode::components::resources qw($map_status $map_door_value);
26
27 sub load {
28 my ($self) = @_;
29
30 $self->{mapping_doorswitch} = {
31 doorSwitchSensorId => { oid => '.1.3.6.1.4.1.' . $self->{netbotz_branch} . '.4.2.2.1.1' },
32 doorSwitchSensorValue => { oid => '.1.3.6.1.4.1.' . $self->{netbotz_branch} . '.4.2.2.1.2', map => $map_door_value },
33 doorSwitchSensorErrorStatus => { oid => '.1.3.6.1.4.1.' . $self->{netbotz_branch} . '.4.2.2.1.3', map => $map_status },
34 doorSwitchSensorLabel => { oid => '.1.3.6.1.4.1.' . $self->{netbotz_branch} . '.4.2.2.1.4' }
35 };
36 $self->{oid_doorSwitchSensorEntry} = '.1.3.6.1.4.1.' . $self->{netbotz_branch} . '.4.2.2.1';
37 push @{$self->{request}}, {
38 oid => $self->{oid_doorSwitchSensorEntry},
39 end => $self->{mapping_doorswitch}->{doorSwitchSensorLabel}->{oid}
40 };
41 }
42
43 sub check {
44 my ($self) = @_;
45
46 $self->{output}->output_add(long_msg => "Checking door switches");
47 $self->{components}->{doorswitch} = { name => 'door switches', total => 0, skip => 0 };
48 return if ($self->check_filter(section => 'doorswitch'));
49
50 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $self->{oid_doorSwitchSensorEntry} }})) {
51 next if ($oid !~ /^$self->{mapping_doorswitch}->{doorSwitchSensorErrorStatus}->{oid}\.(.*)$/);
52 my $instance = $1;
53 my $result = $self->{snmp}->map_instance(
54 mapping => $self->{mapping_doorswitch},
55 results => $self->{results}->{ $self->{oid_doorSwitchSensorEntry} },
56 instance => $instance
57 );
58
59 next if ($self->check_filter(section => 'doorswitch', instance => $instance));
60 $self->{components}->{doorswitch}->{total}++;
61
62 my $label = defined($result->{doorSwitchSensorLabel}) && $result->{doorSwitchSensorLabel} ne '' ? $result->{doorSwitchSensorLabel} : $result->{doorSwitchSensorId};
63 $self->{output}->output_add(
64 long_msg => sprintf(
65 "door switch '%s' status is '%s' [instance = %s] [value = %s]",
66 $label,
67 $result->{doorSwitchSensorErrorStatus},
68 $instance,
69 $result->{doorSwitchSensorValue}
70 )
71 );
72
73 my $exit = $self->get_severity(label => 'default', section => 'doorswitch', value => $result->{doorSwitchSensorErrorStatus});
74 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
75 $self->{output}->output_add(
76 severity => $exit,
77 short_msg => sprintf(
78 "Door switch '%s' status is '%s'",
79 $label,
80 $result->{doorSwitchSensorErrorStatus}
81 )
82 );
83 }
84 }
85 }
86
87 1;