Debian Codegraph @

src/network/dlink/standard/snmp/mode/components/psu.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::psu;
22
23 use strict;
24 use warnings;
25 use centreon::plugins::misc;
26
27 my $map_status_equipment = {
28 0 => 'other', 1 => 'lowVoltage', 2 => 'overCurrent',
29 3 => 'working', 4 => 'fail', 5 => 'connect',
30 6 => 'disconnect'
31 };
32 my $map_status = {
33 1 => 'inOperation', 2 => 'failed', 3 => 'empty'
34 };
35
36 my $mapping_equipment = {
37 status => { oid => '.1.3.6.1.4.1.171.12.11.1.6.1.3', map => $map_status_equipment } # swPowerStatus
38 };
39 my $mapping_industrial = {
40 description => { oid => '.1.3.6.1.4.1.171.14.5.1.1.3.1.3' }, # dEntityExtEnvPowerDescr
41 status => { oid => '.1.3.6.1.4.1.171.14.5.1.1.3.1.6', map => $map_status } # dEntityExtEnvPowerStatus
42 };
43 my $oid_dEntityExtEnvPowerEntry = '.1.3.6.1.4.1.171.14.5.1.1.3.1';
44
45 my $mapping_common = {
46 description => { oid => '.1.3.6.1.4.1.171.17.5.1.1.3.1.3' }, # esEntityExtEnvPowerDescr
47 status => { oid => '.1.3.6.1.4.1.171.17.5.1.1.3.1.6', map => $map_status } # esEntityExtEnvPowerStatus
48 };
49 my $oid_esEntityExtEnvPowerEntry = '.1.3.6.1.4.1.171.17.5.1.1.3.1';
50
51 sub load {
52 my ($self) = @_;
53
54 push @{$self->{request}},
55 { oid => $mapping_equipment->{status}->{oid} },
56 { oid => $oid_dEntityExtEnvPowerEntry, start => $mapping_industrial->{description}->{oid} },
57 { oid => $oid_esEntityExtEnvPowerEntry, start => $mapping_common->{description}->{oid} }
58 ;
59 }
60
61 sub check_psu {
62 my ($self, %options) = @_;
63
64 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $options{entry} }})) {
65 next if ($oid !~ /^$options{mapping}->{status}->{oid}\.(\d+)\.(\d+)$/);
66 my ($unit_id, $psu_id) = ($1, $2);
67 my $instance = $1 . '.' . $2;
68 my $result = $self->{snmp}->map_instance(mapping => $options{mapping}, results => $self->{results}->{ $options{entry} }, instance => $instance);
69
70 my $description = 'unit' . $unit_id . ':psu' . $psu_id;
71 next if ($self->check_filter(section => 'psu', instance => $instance));
72 $self->{components}->{psu}->{total}++;
73
74 $self->{output}->output_add(
75 long_msg => sprintf(
76 "power supply '%s' status is '%s' [instance: %s, description: %s]",
77 $description,
78 $result->{status},
79 $instance,
80 defined($result->{description}) ? centreon::plugins::misc::trim($result->{description}) : '-'
81 )
82 );
83 my $exit = $self->get_severity(section => 'psu', value => $result->{status});
84 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
85 $self->{output}->output_add(
86 severity => $exit,
87 short_msg => sprintf(
88 "Power supply '%s' status is '%s'",
89 $description, $result->{status}
90 )
91 );
92 }
93 }
94 }
95
96 sub check {
97 my ($self) = @_;
98
99 $self->{output}->output_add(long_msg => 'checking power supplies');
100 $self->{components}->{psu} = { name => 'psu', total => 0, skip => 0 };
101 return if ($self->check_filter(section => 'psu'));
102
103 check_psu($self, entry => $mapping_equipment->{status}->{oid}, mapping => $mapping_equipment);
104 check_psu($self, entry => $oid_dEntityExtEnvPowerEntry, mapping => $mapping_industrial);
105 check_psu($self, entry => $oid_esEntityExtEnvPowerEntry, mapping => $mapping_common);
106 }
107
108 1;