Debian Codegraph @

src/centreon/common/cisco/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 centreon::common::cisco::standard::snmp::mode::components::psu;
22
23 use strict;
24 use warnings;
25
26 my %map_psu_source = (
27 1 => 'unknown',
28 2 => 'ac',
29 3 => 'dc',
30 4 => 'externalPowerSupply',
31 5 => 'internalRedundant'
32 );
33 my %map_psu_state1 = (
34 1 => 'normal',
35 2 => 'warning',
36 3 => 'critical',
37 4 => 'shutdown',
38 5 => 'not present',
39 6 => 'not functioning'
40 );
41 my %map_psu_state2 = (
42 1 => 'offEnvOther',
43 2 => 'on',
44 3 => 'offAdmin',
45 4 => 'offDenied',
46 5 => 'offEnvPower',
47 6 => 'offEnvTemp',
48 7 => 'offEnvFan',
49 8 => 'failed',
50 9 => 'onButFanFail',
51 10 => 'offCooling',
52 11 => 'offConnectorRating',
53 12 => 'onButInlinePowerFail'
54 );
55
56 my $oid_ciscoEnvMonSupplyStatusEntry = '.1.3.6.1.4.1.9.9.13.1.5.1'; # CISCO-ENVMON-MIB
57 my $oid_cefcFRUPowerOperStatus = '.1.3.6.1.4.1.9.9.117.1.1.2.1.2'; # CISCO-ENTITY-SENSOR-MIB
58
59 sub load {
60 my ($self) = @_;
61
62 push @{$self->{request}}, { oid => $oid_ciscoEnvMonSupplyStatusEntry }, { oid => $oid_cefcFRUPowerOperStatus };
63 }
64
65 sub check_psu_envmon {
66 my ($self) = @_;
67
68 my $mapping = {
69 ciscoEnvMonSupplyStatusDescr => { oid => '.1.3.6.1.4.1.9.9.13.1.5.1.2' },
70 ciscoEnvMonSupplyState => { oid => '.1.3.6.1.4.1.9.9.13.1.5.1.3', map => \%map_psu_state1 },
71 ciscoEnvMonSupplySource => { oid => '.1.3.6.1.4.1.9.9.13.1.5.1.4', map => \%map_psu_source }
72 };
73
74 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_ciscoEnvMonSupplyStatusEntry}})) {
75 next if ($oid !~ /^$mapping->{ciscoEnvMonSupplyStatusDescr}->{oid}\./);
76 $oid =~ /\.([0-9]+)$/;
77 my $instance = $1;
78
79 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonSupplyStatusEntry}, instance => $instance);
80
81 next if ($self->check_filter(section => 'psu', instance => $instance, name => $result->{ciscoEnvMonSupplyStatusDescr}));
82 next if ($result->{ciscoEnvMonSupplyState} =~ /not present/i &&
83 $self->absent_problem(section => 'psu', instance => $instance, name => $result->{ciscoEnvMonSupplyStatusDescr}));
84 $self->{components}->{psu}->{total}++;
85
86 $self->{output}->output_add(
87 long_msg => sprintf(
88 "power supply '%s' status is %s [instance: %s] [source: %s]",
89 $result->{ciscoEnvMonSupplyStatusDescr}, $result->{ciscoEnvMonSupplyState},
90 $instance, $result->{ciscoEnvMonSupplySource}
91 )
92 );
93 my $exit = $self->get_severity(section => 'psu', instance => $instance, value => $result->{ciscoEnvMonSupplyState});
94 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
95 $self->{output}->output_add(
96 severity => $exit,
97 short_msg => sprintf(
98 "Power supply '%s' status is %s",
99 $result->{ciscoEnvMonSupplyStatusDescr}, $result->{ciscoEnvMonSupplyState}
100 )
101 );
102 }
103 }
104 }
105
106 sub check_psu_entity {
107 my ($self) = @_;
108
109 my $mapping = {
110 cefcFRUPowerOperStatus => { oid => '.1.3.6.1.4.1.9.9.117.1.1.2.1.2', map => \%map_psu_state2 }
111 };
112 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_cefcFRUPowerOperStatus}})) {
113 $oid =~ /\.([0-9]+)$/;
114 my $instance = $1;
115
116 my $psu_descr = $self->{results}->{ $self->{physical_name} }->{ $self->{physical_name} . '.' . $instance };
117 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cefcFRUPowerOperStatus}, instance => $instance);
118
119 next if ($self->check_filter(section => 'psu', instance => $instance, name => $psu_descr));
120
121 $self->{components}->{psu}->{total}++;
122 $self->{output}->output_add(
123 long_msg => sprintf(
124 "Power supply '%s' status is %s [instance: %s]",
125 $psu_descr, $result->{cefcFRUPowerOperStatus}, $instance
126 )
127 );
128 my $exit = $self->get_severity(section => 'psu', instance => $instance, value => $result->{cefcFRUPowerOperStatus});
129 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
130 $self->{output}->output_add(
131 severity => $exit,
132 short_msg => sprintf(
133 "Power supply '%s/%s' status is %s",
134 $psu_descr, $instance, $result->{cefcFRUPowerOperStatus}
135 )
136 );
137 }
138 }
139 }
140
141 sub check {
142 my ($self) = @_;
143
144 $self->{output}->output_add(long_msg => "Checking power supplies");
145 $self->{components}->{psu} = { name => 'psus', total => 0, skip => 0 };
146 return if ($self->check_filter(section => 'psu'));
147
148 check_psu_envmon($self);
149 check_psu_entity($self) if (defined($self->{option_results}->{add_fru_power}));
150 }
151
152 1;