| 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::pdu::cyberpower::snmp::mode::load; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); |
| 28 |
|
| 29 |
sub custom_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return 'state: ' . $self->{result_values}->{state}; |
| 33 |
} |
| 34 |
|
| 35 |
sub device_long_output { |
| 36 |
my ($self, %options) = @_; |
| 37 |
|
| 38 |
return "checking device '" . $options{instance_value}->{display} . "'"; |
| 39 |
} |
| 40 |
|
| 41 |
sub prefix_device_output { |
| 42 |
my ($self, %options) = @_; |
| 43 |
|
| 44 |
return "Device '" . $options{instance_value}->{display} . "' "; |
| 45 |
} |
| 46 |
|
| 47 |
sub prefix_bank_output { |
| 48 |
my ($self, %options) = @_; |
| 49 |
|
| 50 |
return "bank '" . $options{instance_value}->{display} . "' "; |
| 51 |
} |
| 52 |
|
| 53 |
sub prefix_phase_output { |
| 54 |
my ($self, %options) = @_; |
| 55 |
|
| 56 |
return "phase '" . $options{instance_value}->{display} . "' "; |
| 57 |
} |
| 58 |
|
| 59 |
sub set_counters { |
| 60 |
my ($self, %options) = @_; |
| 61 |
|
| 62 |
$self->{maps_counters_type} = [ |
| 63 |
{ |
| 64 |
name => 'devices', type => 3, cb_prefix_output => 'prefix_device_output', cb_long_output => 'device_long_output', indent_long_output => ' ', message_multiple => 'All devices are ok', |
| 65 |
group => [ |
| 66 |
{ name => 'banks', display_long => 1, cb_prefix_output => 'prefix_bank_output', message_multiple => 'banks are ok', type => 1, skipped_code => { -10 => 1 } }, |
| 67 |
{ name => 'phases', display_long => 1, cb_prefix_output => 'prefix_phase_output', message_multiple => 'phases are ok', type => 1, skipped_code => { -10 => 1 } } |
| 68 |
] |
| 69 |
} |
| 70 |
]; |
| 71 |
|
| 72 |
$self->{maps_counters}->{banks} = [ |
| 73 |
{ |
| 74 |
label => 'bank-status', |
| 75 |
type => 2, |
| 76 |
warning_default => '%{state} =~ /low|nearOverload/i', |
| 77 |
critical_default => '%{state} =~ /^overload/i', |
| 78 |
set => { |
| 79 |
key_values => [ { name => 'state' }, { name => 'display' } ], |
| 80 |
closure_custom_output => $self->can('custom_status_output'), |
| 81 |
closure_custom_perfdata => sub { return 0; }, |
| 82 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 83 |
} |
| 84 |
}, |
| 85 |
{ label => 'bank-current', nlabel => 'bank.current.ampere', set => { |
| 86 |
key_values => [ { name => 'current' } ], |
| 87 |
output_template => 'current : %s A', |
| 88 |
perfdatas => [ |
| 89 |
{ template => '%s', unit => 'A', min => 0, label_extra_instance => 1 } |
| 90 |
] |
| 91 |
} |
| 92 |
} |
| 93 |
]; |
| 94 |
|
| 95 |
$self->{maps_counters}->{phases} = [ |
| 96 |
{ |
| 97 |
label => 'phase-status', |
| 98 |
type => 2, |
| 99 |
warning_default => '%{state} =~ /low|nearOverload/i', |
| 100 |
critical_default => '%{state} =~ /^overload/i', |
| 101 |
set => { |
| 102 |
key_values => [ { name => 'state' }, { name => 'display' } ], |
| 103 |
closure_custom_output => $self->can('custom_status_output'), |
| 104 |
closure_custom_perfdata => sub { return 0; }, |
| 105 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 106 |
} |
| 107 |
}, |
| 108 |
{ label => 'phase-current', nlabel => 'phase.current.ampere', set => { |
| 109 |
key_values => [ { name => 'current' } ], |
| 110 |
output_template => 'current : %s A', |
| 111 |
perfdatas => [ |
| 112 |
{ template => '%s', unit => 'A', min => 0, label_extra_instance => 1 } |
| 113 |
] |
| 114 |
} |
| 115 |
}, |
| 116 |
{ label => 'phase-power', nlabel => 'phase.power.watt', set => { |
| 117 |
key_values => [ { name => 'power' } ], |
| 118 |
output_template => 'power : %s W', |
| 119 |
perfdatas => [ |
| 120 |
{ template => '%s', unit => 'W', min => 0, label_extra_instance => 1 } |
| 121 |
] |
| 122 |
} |
| 123 |
}, |
| 124 |
{ label => 'phase-voltage', nlabel => 'phase.voltage.volt', set => { |
| 125 |
key_values => [ { name => 'voltage' } ], |
| 126 |
output_template => 'voltage : %s V', |
| 127 |
perfdatas => [ |
| 128 |
{ template => '%s', unit => 'V', min => 0, label_extra_instance => 1 } |
| 129 |
] |
| 130 |
} |
| 131 |
} |
| 132 |
]; |
| 133 |
} |
| 134 |
|
| 135 |
sub new { |
| 136 |
my ($class, %options) = @_; |
| 137 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 138 |
bless $self, $class; |
| 139 |
|
| 140 |
$options{options}->add_options(arguments => { |
| 141 |
}); |
| 142 |
|
| 143 |
return $self; |
| 144 |
} |
| 145 |
|
| 146 |
my $oid_ePDUIdentName = '.1.3.6.1.4.1.3808.1.1.3.1.1'; |
| 147 |
my $oid_ePDU2DeviceConfigName = '.1.3.6.1.4.1.3808.1.1.6.3.2.1.3'; |
| 148 |
|
| 149 |
my $map_pdu_status = { |
| 150 |
1 => 'normal', 2 => 'low', |
| 151 |
3 => 'nearOverload', 4 => 'overload' |
| 152 |
}; |
| 153 |
|
| 154 |
sub check_pdu { |
| 155 |
my ($self, %options) = @_; |
| 156 |
|
| 157 |
return if (scalar(keys %{$self->{devices}}) > 0); |
| 158 |
|
| 159 |
$self->{devices}->{ $options{device} } = { |
| 160 |
display => $options{device}, |
| 161 |
banks => {}, |
| 162 |
phases => {} |
| 163 |
}; |
| 164 |
|
| 165 |
my $mapping = { |
| 166 |
current => { oid => '.1.3.6.1.4.1.3808.1.1.3.2.3.1.1.2' }, # ePDULoadStatusLoad |
| 167 |
state => { oid => '.1.3.6.1.4.1.3808.1.1.3.2.3.1.1.3', map => $map_pdu_status }, # ePDULoadStatusLoadState |
| 168 |
phase => { oid => '.1.3.6.1.4.1.3808.1.1.3.2.3.1.1.4' }, # ePDULoadStatusPhaseNumber |
| 169 |
bank => { oid => '.1.3.6.1.4.1.3808.1.1.3.2.3.1.1.5' }, # ePDULoadStatusBankNumber [Bank 0 = no bank (phase total)] |
| 170 |
}; |
| 171 |
|
| 172 |
my $oid_ePDULoadStatusEntry = '.1.3.6.1.4.1.3808.1.1.3.2.3.1.1'; |
| 173 |
my $snmp_result = $options{snmp}->get_table( |
| 174 |
oid => $oid_ePDULoadStatusEntry, |
| 175 |
start => $mapping->{current}->{oid}, |
| 176 |
end => $mapping->{bank}->{oid}, |
| 177 |
nothing_quit => 1 |
| 178 |
); |
| 179 |
|
| 180 |
foreach my $oid (keys %$snmp_result) { |
| 181 |
next if ($oid !~ /^$mapping->{state}->{oid}\.(.*)$/); |
| 182 |
my $instance = $1; |
| 183 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); |
| 184 |
|
| 185 |
$result->{current} /= 10; |
| 186 |
if ($result->{bank} == 0) { |
| 187 |
$self->{devices}->{ $options{device} }->{phases}->{ $result->{phase} } = { |
| 188 |
display => $result->{phase}, |
| 189 |
%$result |
| 190 |
}; |
| 191 |
} else { |
| 192 |
$self->{devices}->{ $options{device} }->{banks}->{ $result->{bank} } = { display => $result->{bank}, current => 0 } |
| 193 |
if (!defined($self->{devices}->{ $options{device} }->{banks}->{ $result->{bank} })); |
| 194 |
$self->{devices}->{ $options{device} }->{banks}->{ $result->{bank} }->{state} = $result->{state}; |
| 195 |
$self->{devices}->{ $options{device} }->{banks}->{ $result->{bank} }->{current} += ($result->{current} / 10); |
| 196 |
} |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
sub check_pdu2 { |
| 201 |
my ($self, %options) = @_; |
| 202 |
|
| 203 |
my $mapping_phase = { |
| 204 |
module => { oid => '.1.3.6.1.4.1.3808.1.1.6.4.4.1.2' }, # ePDU2PhaseStatusModuleIndex |
| 205 |
number => { oid => '.1.3.6.1.4.1.3808.1.1.6.4.4.1.3' }, # ePDU2PhaseStatusNumber |
| 206 |
state => { oid => '.1.3.6.1.4.1.3808.1.1.6.4.4.1.4', map => $map_pdu_status }, # ePDU2PhaseStatusLoadState |
| 207 |
current => { oid => '.1.3.6.1.4.1.3808.1.1.6.4.4.1.5' }, # ePDU2PhaseStatusLoad |
| 208 |
voltage => { oid => '.1.3.6.1.4.1.3808.1.1.6.4.4.1.6' }, # ePDU2PhaseStatusVoltage |
| 209 |
power => { oid => '.1.3.6.1.4.1.3808.1.1.6.4.4.1.7' } # ePDU2PhaseStatusPower |
| 210 |
}; |
| 211 |
my $mapping_bank = { |
| 212 |
module => { oid => '.1.3.6.1.4.1.3808.1.1.6.5.4.1.2' }, # ePDU2BankStatusModuleIndex |
| 213 |
number => { oid => '.1.3.6.1.4.1.3808.1.1.6.5.4.1.3' }, # ePDU2BankStatusNumber |
| 214 |
state => { oid => '.1.3.6.1.4.1.3808.1.1.6.5.4.1.4', map => $map_pdu_status }, # ePDU2BankStatusLoadState |
| 215 |
current => { oid => '.1.3.6.1.4.1.3808.1.1.6.5.4.1.5' } # ePDU2BankStatusLoad |
| 216 |
}; |
| 217 |
|
| 218 |
my $oid_ePDU2PhaseStatusEntry = '.1.3.6.1.4.1.3808.1.1.6.4.4.1'; |
| 219 |
my $oid_ePDU2BankStatusEntry = '.1.3.6.1.4.1.3808.1.1.6.5.4.1'; |
| 220 |
my $snmp_result = $options{snmp}->get_multiple_table(oids => [ |
| 221 |
{ oid => $oid_ePDU2PhaseStatusEntry, end => $mapping_phase->{power}->{oid} }, |
| 222 |
{ oid => $oid_ePDU2BankStatusEntry, end => $mapping_bank->{current}->{oid} } |
| 223 |
]); |
| 224 |
|
| 225 |
foreach (keys %{$snmp_result->{$oid_ePDU2PhaseStatusEntry}}) { |
| 226 |
next if (! /^$mapping_phase->{state}->{oid}\.(.*)$/); |
| 227 |
my $result = $options{snmp}->map_instance(mapping => $mapping_phase, results => $snmp_result->{$oid_ePDU2PhaseStatusEntry}, instance => $1); |
| 228 |
|
| 229 |
my $device_name = $options{devices}->{ $oid_ePDU2DeviceConfigName . '.' . $result->{module} }; |
| 230 |
if (!defined($self->{devices}->{$device_name})) { |
| 231 |
$self->{devices}->{$device_name} = { |
| 232 |
display => $device_name, |
| 233 |
banks => {}, |
| 234 |
phases => {} |
| 235 |
}; |
| 236 |
} |
| 237 |
|
| 238 |
$self->{devices}->{$device_name}->{phases}->{ $result->{number} } = { |
| 239 |
display => $result->{number}, |
| 240 |
state => $result->{state}, |
| 241 |
current => $result->{current} / 10, |
| 242 |
voltage => $result->{voltage}/10, |
| 243 |
power => $result->{power} |
| 244 |
} |
| 245 |
} |
| 246 |
|
| 247 |
foreach (keys %{$snmp_result->{$oid_ePDU2BankStatusEntry}}) { |
| 248 |
next if (! /^$mapping_bank->{state}->{oid}\.(.*)$/); |
| 249 |
my $result = $options{snmp}->map_instance(mapping => $mapping_bank, results => $snmp_result->{$oid_ePDU2BankStatusEntry}, instance => $1); |
| 250 |
|
| 251 |
my $device_name = $options{devices}->{ $oid_ePDU2DeviceConfigName . '.' . $result->{module} }; |
| 252 |
if (!defined($self->{devices}->{$device_name})) { |
| 253 |
$self->{devices}->{$device_name} = { |
| 254 |
display => $device_name, |
| 255 |
banks => {}, |
| 256 |
phases => {} |
| 257 |
}; |
| 258 |
} |
| 259 |
|
| 260 |
$self->{devices}->{$device_name}->{banks}->{ $result->{number} } = { |
| 261 |
display => $result->{number}, |
| 262 |
status => $result->{state}, |
| 263 |
current => $result->{current} / 10 |
| 264 |
} |
| 265 |
} |
| 266 |
} |
| 267 |
|
| 268 |
sub manage_selection { |
| 269 |
my ($self, %options) = @_; |
| 270 |
|
| 271 |
my $snmp_result = $options{snmp}->get_multiple_table( |
| 272 |
oids => [ |
| 273 |
{ oid => $oid_ePDUIdentName }, |
| 274 |
{ oid => $oid_ePDU2DeviceConfigName } |
| 275 |
], |
| 276 |
nothing_quit => 1 |
| 277 |
); |
| 278 |
|
| 279 |
$self->{devices} = {}; |
| 280 |
$self->check_pdu2(snmp => $options{snmp}, devices => $snmp_result->{$oid_ePDU2DeviceConfigName}); |
| 281 |
$self->check_pdu( |
| 282 |
snmp => $options{snmp}, |
| 283 |
device => defined($snmp_result->{$oid_ePDUIdentName}->{$oid_ePDUIdentName . '.0'}) ? $snmp_result->{$oid_ePDUIdentName}->{$oid_ePDUIdentName . '.0'} : 'unknown' |
| 284 |
); |
| 285 |
} |
| 286 |
|
| 287 |
1; |
| 288 |
|
| 289 |
__END__ |
| 290 |
|
| 291 |
=head1 MODE |
| 292 |
|
| 293 |
Check phase/bank load. |
| 294 |
|
| 295 |
=over 8 |
| 296 |
|
| 297 |
=item B<--unknown-bank-status> |
| 298 |
|
| 299 |
Define the conditions to match for the status to be UNKNOWN. |
| 300 |
You can use the following variables: %{state}, %{display} |
| 301 |
|
| 302 |
=item B<--warning-bank-status> |
| 303 |
|
| 304 |
Define the conditions to match for the status to be WARNING (default: '%{state} =~ /low|nearOverload/i'). |
| 305 |
You can use the following variables: %{state}, %{display} |
| 306 |
|
| 307 |
=item B<--critical-bank-status> |
| 308 |
|
| 309 |
Define the conditions to match for the status to be CRITICAL (default: '%{state} =~ /^overload/'). |
| 310 |
You can use the following variables: %{state}, %{display} |
| 311 |
|
| 312 |
=item B<--unknown-phase-status> |
| 313 |
|
| 314 |
Define the conditions to match for the status to be UNKNOWN. |
| 315 |
You can use the following variables: %{state}, %{display} |
| 316 |
|
| 317 |
=item B<--warning-phase-status> |
| 318 |
|
| 319 |
Define the conditions to match for the status to be WARNING (default: '%{state} =~ /low|nearOverload/i'). |
| 320 |
You can use the following variables: %{state}, %{display} |
| 321 |
|
| 322 |
=item B<--critical-phase-status> |
| 323 |
|
| 324 |
Define the conditions to match for the status to be CRITICAL (default: '%{state} =~ /^overload/i'). |
| 325 |
You can use the following variables: %{state}, %{display} |
| 326 |
|
| 327 |
=item B<--warning-*> B<--critical-*> |
| 328 |
|
| 329 |
Thresholds. |
| 330 |
Can be: 'phase-current', 'phase-power', 'phase-voltage', 'bank-current'. |
| 331 |
|
| 332 |
=back |
| 333 |
|
| 334 |
=cut |