| 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::hirschmann::standard::snmp::mode::components::psu; |
| 22 |
|
| 23 |
use strict; |
| 24 |
use warnings; |
| 25 |
|
| 26 |
my $map_hios_psu_state = { |
| 27 |
1 => 'present', |
| 28 |
2 => 'defective', |
| 29 |
3 => 'notInstalled', |
| 30 |
4 => 'unknown' |
| 31 |
}; |
| 32 |
my $map_classic_psu_state = { |
| 33 |
1 => 'ok', |
| 34 |
2 => 'failed', |
| 35 |
3 => 'notInstalled', |
| 36 |
4 => 'unknown' |
| 37 |
}; |
| 38 |
my $map_classic_psu_mon = { |
| 39 |
1 => 'error', 2 => 'ignore' |
| 40 |
}; |
| 41 |
my $mapping_classic_devmon = { |
| 42 |
ps1_mon => { oid => '.1.3.6.1.4.1.248.14.2.12.3.1.9', map => $map_classic_psu_mon }, # hmDevMonSensePS1State |
| 43 |
ps2_mon => { oid => '.1.3.6.1.4.1.248.14.2.12.3.1.10', map => $map_classic_psu_mon }, # hmDevMonSensePS2State |
| 44 |
ps3_mon => { oid => '.1.3.6.1.4.1.248.14.2.12.3.1.14', map => $map_classic_psu_mon }, # hmDevMonSensePS3State |
| 45 |
ps4_mon => { oid => '.1.3.6.1.4.1.248.14.2.12.3.1.15', map => $map_classic_psu_mon }, # hmDevMonSensePS4State |
| 46 |
ps5_mon => { oid => '.1.3.6.1.4.1.248.14.2.12.3.1.17', map => $map_classic_psu_mon }, # hmDevMonSensePS5State |
| 47 |
ps6_mon => { oid => '.1.3.6.1.4.1.248.14.2.12.3.1.18', map => $map_classic_psu_mon }, # hmDevMonSensePS6State |
| 48 |
ps7_mon => { oid => '.1.3.6.1.4.1.248.14.2.12.3.1.19', map => $map_classic_psu_mon }, # hmDevMonSensePS7State |
| 49 |
ps8_mon => { oid => '.1.3.6.1.4.1.248.14.2.12.3.1.20', map => $map_classic_psu_mon } # hmDevMonSensePS8State |
| 50 |
}; |
| 51 |
my $mapping_classic_psu = { |
| 52 |
psu_state => { oid => '.1.3.6.1.4.1.248.14.1.2.1.3', map => $map_classic_psu_state } # hmPSState |
| 53 |
}; |
| 54 |
my $oid_classic_devmon_entry = '.1.3.6.1.4.1.248.14.2.12.3.1'; # hmDevMonConfigEntry |
| 55 |
|
| 56 |
my $mapping_hios_psu = { |
| 57 |
psu_state => { oid => '.1.3.6.1.4.1.248.11.11.1.1.1.1.2', map => $map_hios_psu_state } # hm2PSState |
| 58 |
}; |
| 59 |
|
| 60 |
sub load { |
| 61 |
my ($self) = @_; |
| 62 |
|
| 63 |
push @{$self->{myrequest}->{classic}}, |
| 64 |
{ oid => $oid_classic_devmon_entry, start => $mapping_classic_devmon->{ps1_mon}->{oid} }, |
| 65 |
{ oid => $mapping_classic_psu->{psu_state}->{oid} }; |
| 66 |
push @{$self->{myrequest}->{hios}}, |
| 67 |
{ oid => $mapping_hios_psu->{psu_state}->{oid} }; |
| 68 |
} |
| 69 |
|
| 70 |
sub check_psu_classic { |
| 71 |
my ($self) = @_; |
| 72 |
|
| 73 |
my $devmons = {}; |
| 74 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $mapping_classic_psu->{psu_state}->{oid} }})) { |
| 75 |
next if ($oid !~ /^$mapping_classic_psu->{psu_state}->{oid}\.(\d+)\.(\d+)$/); |
| 76 |
my $instance = $1 . '.' . $2; |
| 77 |
my ($sysid, $psid) = ($1, $2); |
| 78 |
my $result = $self->{snmp}->map_instance( |
| 79 |
mapping => $mapping_classic_psu, |
| 80 |
results => $self->{results}->{ $mapping_classic_psu->{psu_state}->{oid} }, |
| 81 |
instance => $instance |
| 82 |
); |
| 83 |
|
| 84 |
if (!defined($devmons->{$sysid})) { |
| 85 |
$devmons->{$sysid} = $self->{snmp}->map_instance( |
| 86 |
mapping => $mapping_classic_devmon, |
| 87 |
results => $self->{results}->{$oid_classic_devmon_entry}, |
| 88 |
instance => $sysid |
| 89 |
); |
| 90 |
} |
| 91 |
|
| 92 |
if (defined($devmons->{$sysid}->{'ps' . $psid . '_mon'}) && $devmons->{$sysid}->{'ps' . $psid . '_mon'} eq 'ignore') { |
| 93 |
$result->{psu_state} = 'ignore'; |
| 94 |
} |
| 95 |
|
| 96 |
next if ($self->check_filter(section => 'psu', instance => $instance)); |
| 97 |
next if ($result->{psu_state} =~ /notInstalled/i && |
| 98 |
$self->absent_problem(section => 'psu', instance => $instance)); |
| 99 |
$self->{components}->{psu}->{total}++; |
| 100 |
|
| 101 |
$self->{output}->output_add( |
| 102 |
long_msg => sprintf( |
| 103 |
"power supply '%s' status is %s [instance: %s].", |
| 104 |
$instance, $result->{psu_state}, |
| 105 |
$instance |
| 106 |
) |
| 107 |
); |
| 108 |
my $exit = $self->get_severity(section => 'psu', value => $result->{psu_state}); |
| 109 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 110 |
$self->{output}->output_add( |
| 111 |
severity => $exit, |
| 112 |
short_msg => sprintf( |
| 113 |
"Power supply '%s' status is %s", |
| 114 |
$instance, $result->{psu_state} |
| 115 |
) |
| 116 |
); |
| 117 |
} |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
sub check_psu_hios { |
| 122 |
my ($self) = @_; |
| 123 |
|
| 124 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $mapping_hios_psu->{psu_state}->{oid} }})) { |
| 125 |
next if ($oid !~ /^$mapping_hios_psu->{psu_state}->{oid}\.(.*)$/); |
| 126 |
my $instance = $1; |
| 127 |
|
| 128 |
my $result = $self->{snmp}->map_instance( |
| 129 |
mapping => $mapping_hios_psu, |
| 130 |
results => $self->{results}->{ $mapping_hios_psu->{psu_state}->{oid} }, |
| 131 |
instance => $instance |
| 132 |
); |
| 133 |
|
| 134 |
next if ($self->check_filter(section => 'psu', instance => $instance)); |
| 135 |
next if ($result->{psu_state} =~ /notInstalled/i && |
| 136 |
$self->absent_problem(section => 'psu', instance => $instance)); |
| 137 |
$self->{components}->{psu}->{total}++; |
| 138 |
|
| 139 |
$self->{output}->output_add( |
| 140 |
long_msg => sprintf( |
| 141 |
"power supply '%s' status is %s [instance: %s].", |
| 142 |
$instance, $result->{psu_state}, |
| 143 |
$instance |
| 144 |
) |
| 145 |
); |
| 146 |
my $exit = $self->get_severity(section => 'psu', value => $result->{psu_state}); |
| 147 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 148 |
$self->{output}->output_add( |
| 149 |
severity => $exit, |
| 150 |
short_msg => sprintf( |
| 151 |
"Power supply '%s' status is %s", |
| 152 |
$instance, $result->{psu_state} |
| 153 |
) |
| 154 |
); |
| 155 |
} |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
sub check { |
| 160 |
my ($self) = @_; |
| 161 |
|
| 162 |
$self->{output}->output_add(long_msg => 'Checking power supplies'); |
| 163 |
$self->{components}->{psu} = { name => 'psus', total => 0, skip => 0 }; |
| 164 |
return if ($self->check_filter(section => 'psu')); |
| 165 |
|
| 166 |
check_psu_classic($self) if ($self->{os_type} eq 'classic'); |
| 167 |
check_psu_hios($self) if ($self->{os_type} eq 'hios'); |
| 168 |
} |
| 169 |
|
| 170 |
1; |