Debian Codegraph @

src/hardware/server/dell/openmanage/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 hardware::server::dell::openmanage::snmp::mode::components::psu;
22
23 use strict;
24 use warnings;
25
26 my %map_status = (
27 1 => 'other',
28 2 => 'unknown',
29 3 => 'ok',
30 4 => 'nonCritical',
31 5 => 'critical',
32 6 => 'nonRecoverable',
33 );
34 my %map_type = (
35 1 => 'other',
36 2 => 'unknown',
37 3 => 'Linear',
38 4 => 'switching',
39 5 => 'Battery',
40 6 => 'UPS',
41 7 => 'Converter',
42 8 => 'Regulator',
43 9 => 'AC',
44 10 => 'DC',
45 11 => 'VRM',
46 );
47 my %map_state = (
48 1 => 'present',
49 2 => 'failure',
50 4 => 'predictiveFailure',
51 8 => 'ACLost',
52 16 => 'ACLostOrOutOfRange',
53 32 => 'ACPresentButOutOfRange',
54 64 => 'configurationError',
55 );
56 my %map_ConfigurationErrorType = (
57 1 => 'vendorMismatch',
58 2 => 'revisionMismatch',
59 3 => 'processorMissing',
60 );
61
62 # In MIB '10892.mib'
63 my $mapping = {
64 powerSupplyStatus => { oid => '.1.3.6.1.4.1.674.10892.1.600.12.1.5', map => \%map_status },
65 powerSupplyOutputWatts => { oid => '.1.3.6.1.4.1.674.10892.1.600.12.1.6' },
66 powerSupplyType => { oid => '.1.3.6.1.4.1.674.10892.1.600.12.1.7', map => \%map_type },
67 powerSupplyLocationName => { oid => '.1.3.6.1.4.1.674.10892.1.600.12.1.8' },
68 };
69 my $mapping2 = {
70 powerSupplySensorState => { oid => '.1.3.6.1.4.1.674.10892.1.600.12.1.11', map => \%map_state },
71 powerSupplyConfigurationErrorType => { oid => '.1.3.6.1.4.1.674.10892.1.600.12.1.12', map => \%map_ConfigurationErrorType },
72 };
73 my $oid_powerSupplyTable = '.1.3.6.1.4.1.674.10892.1.600.12';
74 my $oid_powerSupplyTableEntry = '.1.3.6.1.4.1.674.10892.1.600.12.1';
75
76 sub load {
77 my ($self) = @_;
78
79 push @{$self->{request}}, { oid => $oid_powerSupplyTable, start => $mapping->{powerSupplyStatus}->{oid}, end => $mapping->{powerSupplyLocationName}->{oid} },
80 { oid => $oid_powerSupplyTableEntry, start => $mapping2->{powerSupplySensorState}->{oid}, end => $mapping2->{powerSupplyConfigurationErrorType}->{oid} };
81 }
82
83 sub check {
84 my ($self) = @_;
85
86 $self->{output}->output_add(long_msg => "Checking power supplies");
87 $self->{components}->{psu} = {name => 'power supplies', total => 0, skip => 0};
88 return if ($self->check_filter(section => 'psu'));
89
90 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_powerSupplyTable}})) {
91 next if ($oid !~ /^$mapping->{powerSupplyStatus}->{oid}\.(.*)$/);
92 my $instance = $1;
93 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_powerSupplyTable}, instance => $instance);
94 my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$oid_powerSupplyTableEntry}, instance => $instance);
95 $result2->{powerSupplyConfigurationErrorType} = defined($result2->{powerSupplyConfigurationErrorType}) ? $result2->{powerSupplyConfigurationErrorType} : '-';
96
97 next if ($self->check_filter(section => 'psu', instance => $instance));
98
99 $self->{components}->{psu}->{total}++;
100
101 $self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is '%s' [instance: %s, location: %s, type: %s, output watts: %s, state: %s, configuration error: %s]",
102 $instance, $result->{powerSupplyStatus}, $instance,
103 $result->{powerSupplyLocationName}, $result->{powerSupplyType},
104 defined($result->{powerSupplyOutputWatts}) ? $result->{powerSupplyOutputWatts} : '-',
105 $result2->{powerSupplySensorState}, $result2->{powerSupplyConfigurationErrorType}
106 ));
107 my $exit = $self->get_severity(label => 'default', section => 'psu', value => $result->{powerSupplyStatus});
108 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
109 $self->{output}->output_add(severity => $exit,
110 short_msg => sprintf("Power supply '%s' status is '%s'",
111 $instance, $result->{powerSupplyStatus}));
112 }
113
114 if (defined($result->{powerSupplyOutputWatts}) && $result->{powerSupplyOutputWatts} =~ /[0-9]/) {
115 $result->{powerSupplyOutputWatts} /= 10;
116 my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'psu.power', instance => $instance, value => $result->{powerSupplyOutputWatts});
117
118 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
119 $self->{output}->output_add(severity => $exit,
120 short_msg => sprintf("Power supply '%s' power is %s W", $instance, $result->{powerSupplyOutputWatts}));
121 }
122 $self->{output}->perfdata_add(
123 label => 'psu_power', unit => 'W',
124 nlabel => 'hardware.powersupply.power.watt',
125 instances => $instance,
126 value => $result->{powerSupplyOutputWatts},
127 warning => $warn,
128 critical => $crit,
129 min => 0
130 );
131 }
132 }
133 }
134
135 1;