Debian Codegraph @

src/hardware/sensors/sensorip/snmp/mode/components/switch.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::sensorip::snmp::mode::components::switch;
22
23 use strict;
24 use warnings;
25
26 my %map_sw_status = (
27 1 => 'noStatus',
28 2 => 'normal',
29 4 => 'highCritical',
30 6 => 'lowCritical',
31 7 => 'sensorError',
32 8 => 'relayOn',
33 9 => 'relayOff',
34 );
35 my %map_sw_online = (
36 1 => 'online',
37 2 => 'offline',
38 );
39
40 my $mapping = {
41 sensorProbeSwitchDescription => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.18.1.1' },
42 sensorProbeSwitchStatus => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.18.1.3', map => \%map_sw_status },
43 sensorProbeSwitchOnline => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.18.1.4', map => \%map_sw_online },
44 };
45 my $oid_sensorProbeSwitchEntry = '.1.3.6.1.4.1.3854.1.2.2.1.18.1';
46
47 sub load {
48 my ($self) = @_;
49
50 push @{$self->{request}}, { oid => $oid_sensorProbeSwitchEntry, end => $mapping->{sensorProbeSwitchOnline}->{oid} };
51 }
52
53 sub check {
54 my ($self) = @_;
55
56 $self->{output}->output_add(long_msg => "Checking switch");
57 $self->{components}->{switch} = {name => 'switch', total => 0, skip => 0};
58 return if ($self->check_filter(section => 'switch'));
59
60 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_sensorProbeSwitchEntry}})) {
61 next if ($oid !~ /^$mapping->{sensorProbeSwitchStatus}->{oid}\.(.*)$/);
62 my $instance = $1;
63 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_sensorProbeSwitchEntry}, instance => $instance);
64
65 next if ($self->check_filter(section => 'switch', instance => $instance));
66 if ($result->{sensorProbeSwitchOnline} =~ /Offline/i) {
67 $self->absent_problem(section => 'switch', instance => $instance);
68 next;
69 }
70
71 $self->{components}->{switch}->{total}++;
72 $self->{output}->output_add(long_msg => sprintf("Switch sensor '%s' status is '%s' [instance : %s]",
73 $result->{sensorProbeSwitchDescription}, $result->{sensorProbeSwitchStatus}, $instance));
74 my $exit = $self->get_severity(section => 'switch', value => $result->{sensorProbeSwitchStatus});
75 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
76 $self->{output}->output_add(severity => $exit,
77 short_msg => sprintf("Switch sensor '%s' status is '%s'", $result->{sensorProbeSwitchDescription}, $result->{sensorProbeSwitchStatus}));
78 }
79 }
80 }
81
82 1;