Debian Codegraph @

src/centreon/common/radlan/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::radlan::snmp::mode::components::psu;
22
23 use strict;
24 use warnings;
25 use centreon::common::radlan::snmp::mode::components::resources qw(
26 $rl_envmon_state
27 $oid_rlPhdUnitEnvParamEntry
28 );
29
30 my $mapping_stack = {
31 rlPhdUnitEnvParamMainPSStatus => { oid => '.1.3.6.1.4.1.89.53.15.1.2', map => $rl_envmon_state },
32 rlPhdUnitEnvParamRedundantPSStatus => { oid => '.1.3.6.1.4.1.89.53.15.1.3', map => $rl_envmon_state }
33 };
34
35 my $mapping = {
36 rlEnvMonSupplyStatusDescr => { oid => '.1.3.6.1.4.1.89.83.1.2.1.2' },
37 rlEnvMonSupplyState => { oid => '.1.3.6.1.4.1.89.83.1.2.1.3', map => $rl_envmon_state }
38 };
39 my $oid_rlEnvMonSupplyStatusEntry = '.1.3.6.1.4.1.89.83.1.2.1';
40
41 sub load {
42 my ($self) = @_;
43
44 push @{$self->{request}}, {
45 oid => $oid_rlEnvMonSupplyStatusEntry,
46 $mapping->{rlEnvMonSupplyStatusDescr}->{oid},
47 $mapping->{rlEnvMonSupplyState}->{oid}
48 };
49 }
50
51 sub check_psu_stack {
52 my ($self) = @_;
53
54 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlPhdUnitEnvParamEntry}})) {
55 next if ($oid !~ /^$mapping_stack->{rlPhdUnitEnvParamMainPSStatus}->{oid}\.(.*)$/);
56 my $instance = $1;
57 my $result = $self->{snmp}->map_instance(mapping => $mapping_stack, results => $self->{results}->{$oid_rlPhdUnitEnvParamEntry}, instance => $instance);
58
59 foreach (['rlPhdUnitEnvParamMainPSStatus', 'main.psu'], ['rlPhdUnitEnvParamRedundantPSStatus', 'redundant.psu']) {
60 my $instance2 = 'stack.' . $instance . '.' . $_->[1];
61
62 next if ($self->check_filter(section => 'psu', instance => $instance2));
63 next if ($result->{$_->[0]} =~ /notPresent/i &&
64 $self->absent_problem(section => 'psu', instance => $instance2));
65
66 $self->{components}->{psu}->{total}++;
67 $self->{output}->output_add(
68 long_msg => sprintf(
69 "power supply '%s' status is '%s' [instance: %s]",
70 $instance2,
71 $result->{$_->[0]},
72 $instance2
73 )
74 );
75
76 my $exit = $self->get_severity(label => 'default', section => 'psu', value => $result->{$_->[0]});
77 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
78 $self->{output}->output_add(
79 severity => $exit,
80 short_msg => sprintf(
81 "Power supply '%s' status is '%s'",
82 $instance2,
83 $result->{$_->[0]}
84 )
85 );
86 }
87 }
88 }
89 }
90
91 sub check_psu {
92 my ($self) = @_;
93
94 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlEnvMonSupplyStatusEntry}})) {
95 next if ($oid !~ /^$mapping->{rlEnvMonSupplyState}->{oid}\.(.*)$/);
96 my $instance = $1;
97 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rlEnvMonSupplyStatusEntry}, instance => $instance);
98
99 next if ($self->check_filter(section => 'psu', instance => $instance));
100 if ($result->{rlEnvMonSupplyState} =~ /notPresent/i) {
101 $self->absent_problem(section => 'psu', instance => $instance);
102 next;
103 }
104
105 $self->{components}->{psu}->{total}++;
106 $self->{output}->output_add(
107 long_msg => sprintf(
108 "power supply '%s' status is '%s' [instance: %s]",
109 $result->{rlEnvMonSupplyStatusDescr},
110 $result->{rlEnvMonSupplyState},
111 $instance
112 )
113 );
114
115 my $exit = $self->get_severity(label => 'default', section => 'psu', value => $result->{rlEnvMonSupplyState});
116 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
117 $self->{output}->output_add(
118 severity => $exit,
119 short_msg => sprintf(
120 "Power supply '%s' status is '%s'",
121 $result->{rlEnvMonSupplyStatusDescr},
122 $result->{rlEnvMonSupplyState}
123 )
124 );
125 }
126 }
127 }
128
129 sub check {
130 my ($self) = @_;
131
132 $self->{output}->output_add(long_msg => "Checking power supplies");
133 $self->{components}->{psu} = { name => 'psu', total => 0, skip => 0 };
134 return if ($self->check_filter(section => 'psu'));
135
136 check_psu($self);
137 check_psu_stack($self);
138 }
139
140 1;