| 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::emerson::snmp::mode::psusage; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use Digest::MD5 qw(md5_hex); |
| 28 |
|
| 29 |
sub set_counters { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
$self->{maps_counters_type} = [ |
| 33 |
{ name => 'ps', type => 3, cb_prefix_output => 'prefix_ps_output', cb_long_output => 'ps_long_output', indent_long_output => ' ', message_multiple => 'All power sources are ok', |
| 34 |
group => [ |
| 35 |
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }, |
| 36 |
{ name => 'line', display_long => 1, cb_prefix_output => 'prefix_line_output', message_multiple => 'All power source lines are ok', type => 1, skipped_code => { -10 => 1 } }, |
| 37 |
] |
| 38 |
} |
| 39 |
]; |
| 40 |
|
| 41 |
$self->{maps_counters}->{global} = [ |
| 42 |
{ label => 'power', nlabel => 'powersource.total.input.power.watt', set => { |
| 43 |
key_values => [ { name => 'PwrTotal' } ], |
| 44 |
output_template => 'Total input power : %s W', output_error_template => "total input power : %s", |
| 45 |
perfdatas => [ |
| 46 |
{ label => 'power', value => 'PwrTotal', template => '%s', |
| 47 |
unit => 'W', min => 0, label_extra_instance => 1 }, |
| 48 |
], |
| 49 |
} |
| 50 |
}, |
| 51 |
{ label => 'energy', nlabel => 'powersource.total.accumulated.energy.kilowatthour', set => { |
| 52 |
key_values => [ { name => 'EnergyAccum', diff => 1 } ], |
| 53 |
output_template => 'Total energy : %.3f kWh', output_error_template => "Total energy : %s", |
| 54 |
perfdatas => [ |
| 55 |
{ label => 'energy', value => 'EnergyAccum', template => '%.3f', |
| 56 |
unit => 'kWh', min => 0, label_extra_instance => 1 }, |
| 57 |
], |
| 58 |
} |
| 59 |
}, |
| 60 |
{ label => 'current-neutral', nlabel => 'powersource.neutral.current.ampacrms', set => { |
| 61 |
key_values => [ { name => 'EcNeutral' } ], |
| 62 |
output_template => 'Current neutral : %s Amp AC RMS', output_error_template => "Current neutral : %s", |
| 63 |
perfdatas => [ |
| 64 |
{ label => 'current_neutral', value => 'EcNeutral', template => '%s', |
| 65 |
unit => 'AmpAcRMS', min => 0, label_extra_instance => 1 }, |
| 66 |
], |
| 67 |
} |
| 68 |
}, |
| 69 |
]; |
| 70 |
$self->{maps_counters}->{line} = [ |
| 71 |
{ label => 'line-load', nlabel => 'line.load.percentage', set => { |
| 72 |
key_values => [ { name => 'load' } ], |
| 73 |
output_template => 'Load : %.2f %%', output_error_template => "Load : %s", |
| 74 |
perfdatas => [ |
| 75 |
{ label => 'line_load', value => 'load', template => '%.2f', |
| 76 |
unit => '%', min => 0, max => 100, label_extra_instance => 1 }, |
| 77 |
], |
| 78 |
} |
| 79 |
}, |
| 80 |
{ label => 'line-current', nlabel => 'line.neutral.current.ampere', set => { |
| 81 |
key_values => [ { name => 'current' }], |
| 82 |
output_template => 'Current : %.2f A', output_error_template => "Current : %s", |
| 83 |
perfdatas => [ |
| 84 |
{ label => 'line_current', value => 'current', template => '%.2f', |
| 85 |
unit => 'A', min => 0, label_extra_instance => 1 }, |
| 86 |
], |
| 87 |
} |
| 88 |
}, |
| 89 |
]; |
| 90 |
} |
| 91 |
|
| 92 |
sub prefix_ps_output { |
| 93 |
my ($self, %options) = @_; |
| 94 |
|
| 95 |
return "Power source '" . $options{instance_value}->{display} . "' "; |
| 96 |
} |
| 97 |
|
| 98 |
sub ps_long_output { |
| 99 |
my ($self, %options) = @_; |
| 100 |
|
| 101 |
return "checking power source '" . $options{instance_value}->{display} . "'"; |
| 102 |
} |
| 103 |
|
| 104 |
sub prefix_line_output { |
| 105 |
my ($self, %options) = @_; |
| 106 |
|
| 107 |
return "Power source line '" . $options{instance_value}->{display} . "' "; |
| 108 |
} |
| 109 |
|
| 110 |
sub new { |
| 111 |
my ($class, %options) = @_; |
| 112 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); |
| 113 |
bless $self, $class; |
| 114 |
|
| 115 |
$options{options}->add_options(arguments => { |
| 116 |
'filter-name:s' => { name => 'filter_name' }, |
| 117 |
}); |
| 118 |
|
| 119 |
return $self; |
| 120 |
} |
| 121 |
|
| 122 |
my %map_phase = (1 => 'phase1', 2 => 'phase2', 3 => 'phase3'); |
| 123 |
|
| 124 |
my $mapping = { |
| 125 |
lgpPduEntryUsrLabel => { oid => '.1.3.6.1.4.1.476.1.42.3.8.20.1.10' }, |
| 126 |
lgpPduEntrySysAssignLabel => { oid => '.1.3.6.1.4.1.476.1.42.3.8.20.1.15' }, |
| 127 |
}; |
| 128 |
my $mapping2 = { |
| 129 |
lgpPduPsEntrySysAssignLabel => { oid => '.1.3.6.1.4.1.476.1.42.3.8.30.20.1.15' }, |
| 130 |
lgpPduPsEntryEnergyAccum => { oid => '.1.3.6.1.4.1.476.1.42.3.8.30.20.1.50' }, # 0.1 Kilowatt-Hour |
| 131 |
lgpPduPsEntryPwrTotal => { oid => '.1.3.6.1.4.1.476.1.42.3.8.30.20.1.65' }, # Watt |
| 132 |
lgpPduPsEntryEcNeutral => { oid => '.1.3.6.1.4.1.476.1.42.3.8.30.20.1.70' }, # 0.1 Amp-AC-RMS |
| 133 |
}; |
| 134 |
my $mapping3 = { |
| 135 |
lgpPduPsLineEntryLine => { oid => '.1.3.6.1.4.1.476.1.42.3.8.30.40.1.15', map => \%map_phase }, |
| 136 |
lgpPduPsLineEntryEcHundredths => { oid => '.1.3.6.1.4.1.476.1.42.3.8.30.40.1.22' }, # 0.01 A |
| 137 |
lgpPduPsLineEntryEcUsedBeforeAlarm => { oid => '.1.3.6.1.4.1.476.1.42.3.8.30.40.1.39' }, # % |
| 138 |
}; |
| 139 |
my $oid_lgpPduEntry = '.1.3.6.1.4.1.476.1.42.3.8.20.1'; |
| 140 |
my $oid_lgpPduPsEntry = '.1.3.6.1.4.1.476.1.42.3.8.30.20.1'; |
| 141 |
my $oid_lgpPduPsLineEntry = '.1.3.6.1.4.1.476.1.42.3.8.30.40.1'; |
| 142 |
|
| 143 |
sub manage_selection { |
| 144 |
my ($self, %options) = @_; |
| 145 |
|
| 146 |
$self->{cache_name} = "pdu_emerson_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . |
| 147 |
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' . |
| 148 |
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); |
| 149 |
|
| 150 |
$self->{ps} = {}; |
| 151 |
my $snmp_result = $options{snmp}->get_multiple_table( |
| 152 |
oids => [ |
| 153 |
{ oid => $oid_lgpPduEntry, start => $mapping->{lgpPduEntryUsrLabel}->{oid}, end => $mapping->{lgpPduEntrySysAssignLabel}->{oid} }, |
| 154 |
{ oid => $oid_lgpPduPsEntry, start => $mapping2->{lgpPduPsEntrySysAssignLabel}->{oid}, end => $mapping2->{lgpPduPsEntryEcNeutral}->{oid} }, |
| 155 |
{ oid => $oid_lgpPduPsLineEntry, start => $mapping3->{lgpPduPsLineEntryLine}->{oid}, end => $mapping3->{lgpPduPsLineEntryEcUsedBeforeAlarm}->{oid} }, |
| 156 |
], |
| 157 |
nothing_quit => 1 |
| 158 |
); |
| 159 |
foreach my $oid (keys %{$snmp_result->{$oid_lgpPduPsEntry}}) { |
| 160 |
next if ($oid !~ /^$mapping2->{lgpPduPsEntrySysAssignLabel}->{oid}\.(\d+)\.(\d+)/); |
| 161 |
my ($pdu_index, $ps_index) = ($1, $2); |
| 162 |
|
| 163 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_lgpPduEntry}, instance => $pdu_index); |
| 164 |
my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{$oid_lgpPduPsEntry}, instance => $pdu_index . '.' . $ps_index); |
| 165 |
|
| 166 |
my $name = (defined($result->{lgpPduEntryUsrLabel}) && $result->{lgpPduEntryUsrLabel} ne '' ? $result->{lgpPduEntryUsrLabel} : $result->{lgpPduEntrySysAssignLabel}); |
| 167 |
$name .= '~' . $result2->{lgpPduPsEntrySysAssignLabel}; |
| 168 |
|
| 169 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 170 |
$name !~ /$self->{option_results}->{filter_name}/) { |
| 171 |
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1); |
| 172 |
next; |
| 173 |
} |
| 174 |
|
| 175 |
$self->{ps}->{$name} = { |
| 176 |
display => $name, |
| 177 |
global => { |
| 178 |
display => $name, |
| 179 |
EnergyAccum => $result2->{lgpPduPsEntryEnergyAccum} * 0.1, |
| 180 |
PwrTotal => $result2->{lgpPduPsEntryPwrTotal}, |
| 181 |
EcNeutral => defined($result2->{lgpPduPsEntryEcNeutral}) ? $result2->{lgpPduPsEntryEcNeutral} * 0.1 : undef, |
| 182 |
}, |
| 183 |
line => {}, |
| 184 |
}; |
| 185 |
|
| 186 |
foreach my $oid (keys %{$snmp_result->{$oid_lgpPduPsLineEntry}}) { |
| 187 |
next if ($oid !~ /^$mapping3->{lgpPduPsLineEntryEcUsedBeforeAlarm}->{oid}\.$pdu_index\.$ps_index\.(\d+)/); |
| 188 |
my $line_index = $1; |
| 189 |
my $result3 = $options{snmp}->map_instance(mapping => $mapping3, results => $snmp_result->{$oid_lgpPduPsLineEntry}, instance => $pdu_index . '.' . $ps_index . '.' . $line_index); |
| 190 |
|
| 191 |
$self->{ps}->{$name}->{line}->{$result3->{lgpPduPsLineEntryLine}} = { |
| 192 |
display => $result3->{lgpPduPsLineEntryLine}, |
| 193 |
current => defined($result3->{lgpPduPsLineEntryEcHundredths}) ? $result3->{lgpPduPsLineEntryEcHundredths} * 0.01 : undef, |
| 194 |
load => $result3->{lgpPduPsLineEntryEcUsedBeforeAlarm}, |
| 195 |
}; |
| 196 |
} |
| 197 |
} |
| 198 |
|
| 199 |
if (scalar(keys %{$self->{ps}}) <= 0) { |
| 200 |
$self->{output}->add_option_msg(short_msg => "Cannot find power sources."); |
| 201 |
$self->{output}->option_exit(); |
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
1; |
| 206 |
|
| 207 |
__END__ |
| 208 |
|
| 209 |
=head1 MODE |
| 210 |
|
| 211 |
Check power source usage. |
| 212 |
|
| 213 |
=over 8 |
| 214 |
|
| 215 |
=item B<--filter-name> |
| 216 |
|
| 217 |
Filter power source name (can be a regexp). |
| 218 |
|
| 219 |
=item B<--filter-counters> |
| 220 |
|
| 221 |
Only display some counters (regexp can be used). |
| 222 |
Example: --filter-counters='^(power|energy)$' |
| 223 |
|
| 224 |
=item B<--warning-*> |
| 225 |
|
| 226 |
Warning threshold. |
| 227 |
Can be: 'power', 'energy', 'current-neutral', |
| 228 |
'line-load', 'line-current'. |
| 229 |
|
| 230 |
=item B<--critical-*> |
| 231 |
|
| 232 |
Critical threshold. |
| 233 |
Can be: 'power', 'energy', 'current-neutral', |
| 234 |
'line-load', 'line-current'. |
| 235 |
|
| 236 |
=back |
| 237 |
|
| 238 |
=cut |