Debian Codegraph @

src/network/extreme/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::extreme::snmp::mode::components::psu;
22
23 use strict;
24 use warnings;
25
26 my %map_psu_status = (
27 1 => 'notPresent',
28 2 => 'presentOK',
29 3 => 'presentNotOK',
30 4 => 'presentPowerOff'
31 );
32
33 my $mapping = {
34 extremePowerSupplyStatus => { oid => '.1.3.6.1.4.1.1916.1.1.1.27.1.2', map => \%map_psu_status },
35 extremePowerSupplyFan1Speed => { oid => '.1.3.6.1.4.1.1916.1.1.1.27.1.6' },
36 extremePowerSupplyFan2Speed => { oid => '.1.3.6.1.4.1.1916.1.1.1.27.1.7' },
37 extremePowerSupplyInputPowerUsage => { oid => '.1.3.6.1.4.1.1916.1.1.1.27.1.9' },
38 extremePowerSupplyInputPowerUsageUnitMultiplier => { oid => '.1.3.6.1.4.1.1916.1.1.1.27.1.11' },
39 };
40 my $oid_extremePowerSupplyEntry = '.1.3.6.1.4.1.1916.1.1.1.27.1';
41
42 sub load {
43 my ($self) = @_;
44
45 push @{$self->{request}}, { oid => $oid_extremePowerSupplyEntry, start => $mapping->{extremePowerSupplyStatus}->{oid} };
46 }
47
48 sub check_fan_speed {
49 my ($self, %options) = @_;
50
51 if (!defined($options{value}) || $options{value} < 0) {
52 return ;
53 }
54
55 my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'psu.fan', instance => $options{instance}, value => $options{value});
56 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
57 $self->{output}->output_add(
58 severity => $exit,
59 short_msg => sprintf(
60 "Power supply fan '%s' is '%s' rpm",
61 $options{instance},
62 $options{value}
63 )
64 );
65 }
66 $self->{output}->perfdata_add(
67 label => 'psu_fan_' . $options{instance}, unit => 'rpm',
68 value => $options{value},
69 warning => $warn,
70 critical => $crit,
71 min => 0
72 );
73 }
74
75 sub check {
76 my ($self) = @_;
77
78 $self->{output}->output_add(long_msg => "Checking power supplies");
79 $self->{components}->{psu} = {name => 'power supplies', total => 0, skip => 0};
80 return if ($self->check_filter(section => 'psu'));
81
82 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_extremePowerSupplyEntry}})) {
83 next if ($oid !~ /^$mapping->{extremePowerSupplyStatus}->{oid}\.(.*)$/);
84 my $instance = $1;
85 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_extremePowerSupplyEntry}, instance => $instance);
86
87 next if ($self->check_filter(section => 'psu', instance => $instance));
88 if ($result->{extremePowerSupplyStatus} =~ /notPresent/i) {
89 $self->absent_problem(section => 'psu', instance => $instance);
90 next;
91 }
92
93 my $power = $result->{extremePowerSupplyInputPowerUsage} * (10 ** $result->{extremePowerSupplyInputPowerUsageUnitMultiplier});
94 $self->{components}->{psu}->{total}++;
95 $self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is '%s' [instance = %s, fan1speed = %s, fan2speed = %s, power = %s]",
96 $instance, $result->{extremePowerSupplyStatus}, $instance,
97 $result->{extremePowerSupplyFan1Speed}, $result->{extremePowerSupplyFan2Speed}, $power
98 ));
99 my $exit = $self->get_severity(section => 'psu', value => $result->{extremePowerSupplyStatus});
100 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
101 $self->{output}->output_add(severity => $exit,
102 short_msg => sprintf("Power supply '%s' status is '%s'", $instance, $result->{extremePowerSupplyStatus}));
103 }
104
105 check_fan_speed($self, value => $result->{extremePowerSupplyFan1Speed}, instance => $instance . '.1');
106 check_fan_speed($self, value => $result->{extremePowerSupplyFan2Speed}, instance => $instance . '.2');
107
108 if ($power != 0) {
109 my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'psu', instance => 'psu', value => $power);
110 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
111 $self->{output}->output_add(severity => $exit,
112 short_msg => sprintf("Power supply '%s' power is '%s' W", $instance, $power));
113 }
114 $self->{output}->perfdata_add(
115 label => 'psu_power', unit => 'W',
116 nlabel => 'hardware.powersupply.power.watt',
117 instances => $instance,
118 value => $power,
119 warning => $warn,
120 critical => $crit,
121 min => 0
122 );
123 }
124 }
125 }
126
127 1;