| 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::hp::procurve::snmp::mode::interfaces; |
| 22 |
|
| 23 |
use base qw(snmp_standard::mode::interfaces); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); |
| 28 |
|
| 29 |
sub custom_poe_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return 'poe status: ' . $self->{result_values}->{poestatus}; |
| 33 |
} |
| 34 |
|
| 35 |
sub set_counters_errors { |
| 36 |
my ($self, %options) = @_; |
| 37 |
|
| 38 |
$self->SUPER::set_counters_errors(%options); |
| 39 |
|
| 40 |
push @{$self->{maps_counters}->{int}}, |
| 41 |
{ label => 'poe-status', filter => 'add_poe', type => 2, set => { |
| 42 |
key_values => [ |
| 43 |
{ name => 'poestatus' }, { name => 'opstatus' }, |
| 44 |
{ name => 'admstatus' }, { name => 'display' } |
| 45 |
], |
| 46 |
closure_custom_output => $self->can('custom_poe_status_output'), |
| 47 |
closure_custom_perfdata => sub { return 0; }, |
| 48 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 49 |
} |
| 50 |
}, |
| 51 |
{ label => 'poe-power-actual', filter => 'add_poe', nlabel => 'interface.poe.power.actual.milliwatt', set => { |
| 52 |
key_values => [ { name => 'poe_actual_power' }, { name => 'display' } ], |
| 53 |
output_template => 'poe actual power: %s mW', |
| 54 |
perfdatas => [ |
| 55 |
{ label => 'power_actual', template => '%.2f', |
| 56 |
unit => 'mW', label_extra_instance => 1, instance_use => 'display' } |
| 57 |
] |
| 58 |
} |
| 59 |
} |
| 60 |
; |
| 61 |
|
| 62 |
push @{$self->{maps_counters}->{int}}, |
| 63 |
{ label => 'input-power', filter => 'add_optical', nlabel => 'interface.input.power.dbm', set => { |
| 64 |
key_values => [ { name => 'input_power' }, { name => 'display' } ], |
| 65 |
output_template => 'Input Power : %s dBm', |
| 66 |
perfdatas => [ |
| 67 |
{ template => '%s', unit => 'dBm', label_extra_instance => 1, instance_use => 'display' } |
| 68 |
] |
| 69 |
} |
| 70 |
}, |
| 71 |
{ label => 'bias-current', filter => 'add_optical', nlabel => 'interface.bias.current.milliampere', set => { |
| 72 |
key_values => [ { name => 'bias_current' }, { name => 'display' } ], |
| 73 |
output_template => 'Bias Current : %s mA', |
| 74 |
perfdatas => [ |
| 75 |
{ template => '%s', unit => 'mA', label_extra_instance => 1, instance_use => 'display' } |
| 76 |
] |
| 77 |
} |
| 78 |
}, |
| 79 |
{ label => 'output-power', filter => 'add_optical', nlabel => 'interface.output.power.dbm', set => { |
| 80 |
key_values => [ { name => 'output_power' }, { name => 'display' } ], |
| 81 |
output_template => 'Output Power : %s dBm', |
| 82 |
perfdatas => [ |
| 83 |
{ template => '%s', unit => 'dBm', label_extra_instance => 1, instance_use => 'display' } |
| 84 |
] |
| 85 |
} |
| 86 |
}, |
| 87 |
{ label => 'voltage', filter => 'add_optical', nlabel => 'interface.voltage.volt', set => { |
| 88 |
key_values => [ { name => 'voltage' }, { name => 'display' } ], |
| 89 |
output_template => 'Voltage : %s V', |
| 90 |
perfdatas => [ |
| 91 |
{ template => '%s', unit => 'V', label_extra_instance => 1, instance_use => 'display' } |
| 92 |
] |
| 93 |
} |
| 94 |
}, |
| 95 |
{ label => 'module-temperature', filter => 'add_optical', nlabel => 'interface.module.temperature.celsius', set => { |
| 96 |
key_values => [ { name => 'module_temperature' }, { name => 'display' } ], |
| 97 |
output_template => 'Module Temperature : %.2f C', |
| 98 |
perfdatas => [ |
| 99 |
{ template => '%.2f', unit => 'C', label_extra_instance => 1, instance_use => 'display' } |
| 100 |
] |
| 101 |
} |
| 102 |
} |
| 103 |
; |
| 104 |
} |
| 105 |
|
| 106 |
sub new { |
| 107 |
my ($class, %options) = @_; |
| 108 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 109 |
bless $self, $class; |
| 110 |
|
| 111 |
$options{options}->add_options(arguments => { |
| 112 |
'add-poe' => { name => 'add_poe' }, |
| 113 |
'add-optical' => { name => 'add_optical' } |
| 114 |
}); |
| 115 |
|
| 116 |
return $self; |
| 117 |
} |
| 118 |
|
| 119 |
sub skip_interface { |
| 120 |
my ($self, %options) = @_; |
| 121 |
|
| 122 |
return ($self->{checking} =~ /cast|errors|traffic|poe|status|volume|optical/ ? 0 : 1); |
| 123 |
} |
| 124 |
|
| 125 |
sub check_options { |
| 126 |
my ($self, %options) = @_; |
| 127 |
$self->SUPER::check_options(%options); |
| 128 |
|
| 129 |
$self->{checking} = ''; |
| 130 |
foreach (('add_global', 'add_status', 'add_errors', 'add_traffic', 'add_cast', 'add_speed', 'add_volume', 'add_poe', 'add_optical')) { |
| 131 |
if (defined($self->{option_results}->{$_})) { |
| 132 |
$self->{checking} .= $_; |
| 133 |
} |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
sub reload_cache_custom { |
| 138 |
my ($self, %options) = @_; |
| 139 |
|
| 140 |
$options{datas}->{poe_ports} = {}; |
| 141 |
my $oid_hpicfPoePethPsePortOperStatus = '.1.3.6.1.4.1.11.2.14.11.1.9.1.1.1.9'; |
| 142 |
my $snmp_result = $self->{snmp}->get_table(oid => $oid_hpicfPoePethPsePortOperStatus); |
| 143 |
foreach (keys %$snmp_result) { |
| 144 |
next if (! /^$oid_hpicfPoePethPsePortOperStatus\.(\d+)\.(\d+)$/); |
| 145 |
$options{datas}->{poe_ports}->{$2} = $1 . '.' . $2; |
| 146 |
} |
| 147 |
|
| 148 |
$options{datas}->{optical_ports} = {}; |
| 149 |
my $oid_hpicfXcvrPortDesc = '.1.3.6.1.4.1.11.2.14.11.5.1.82.1.1.1.1.2'; |
| 150 |
$snmp_result = $self->{snmp}->get_table(oid => $oid_hpicfXcvrPortDesc); |
| 151 |
foreach (keys %$snmp_result) { |
| 152 |
next if (! /^$oid_hpicfXcvrPortDesc\.(\d+)$/); |
| 153 |
$options{datas}->{optical_ports}->{$1} = $snmp_result->{$_}; |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
my $mapping_optical = { |
| 158 |
module_temperature => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.82.1.1.1.1.11' }, # hpicfXcvrTemp (/1000) |
| 159 |
voltage => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.82.1.1.1.1.12' }, # hpicfXcvrVoltage |
| 160 |
bias_current => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.82.1.1.1.1.13' }, # hpicfXcvrBias (microamp / 1000) |
| 161 |
output_power => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.82.1.1.1.1.14' }, # hpicfXcvrTxPower (/1000) |
| 162 |
input_power => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.82.1.1.1.1.15' } # hpicfXcvrRxPower (/1000) |
| 163 |
}; |
| 164 |
|
| 165 |
my $oid_poe_status = '.1.3.6.1.4.1.11.2.14.11.1.9.1.1.1.9'; # hpicfPoePethPsePortOperStatus |
| 166 |
my $oid_poe_actual_power = '.1.3.6.1.4.1.11.2.14.11.1.9.1.1.1.8'; # hpicfPoePethPsePortActualPower |
| 167 |
|
| 168 |
my $map_poe_status = { 1 => 'deny', 2 => 'off', 3 => 'on' }; |
| 169 |
|
| 170 |
sub custom_load { |
| 171 |
my ($self, %options) = @_; |
| 172 |
|
| 173 |
if (defined($self->{option_results}->{add_poe})) { |
| 174 |
my $ports = $self->{statefile_cache}->get(name => 'poe_ports'); |
| 175 |
my $instances = []; |
| 176 |
foreach (@{$self->{array_interface_selected}}) { |
| 177 |
push @$instances, $ports->{$_} if (defined($ports->{$_})); |
| 178 |
} |
| 179 |
|
| 180 |
if (scalar(@$instances) > 0) { |
| 181 |
$self->{snmp}->load( |
| 182 |
oids => [ $oid_poe_status, $oid_poe_actual_power ], |
| 183 |
instances => $instances, |
| 184 |
instance_regexp => '^(.*)$' |
| 185 |
); |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
return if (!defined($self->{option_results}->{add_optical})); |
| 190 |
|
| 191 |
my $optical_ports = $self->{statefile_cache}->get(name => 'optical_ports'); |
| 192 |
$self->{snmp}->load( |
| 193 |
oids => [ map($_->{oid}, values(%$mapping_optical)) ], |
| 194 |
instances => [keys %$optical_ports] |
| 195 |
); |
| 196 |
} |
| 197 |
|
| 198 |
sub custom_add_result { |
| 199 |
my ($self, %options) = @_; |
| 200 |
|
| 201 |
if (defined($self->{option_results}->{add_poe})) { |
| 202 |
my $ports = $self->{statefile_cache}->get(name => 'poe_ports'); |
| 203 |
|
| 204 |
if (defined($ports->{ $options{instance} })) { |
| 205 |
my $index = $ports->{ $options{instance} }; |
| 206 |
if (defined($self->{results}->{$oid_poe_actual_power . '.' . $index})) { |
| 207 |
$self->{int}->{ $options{instance} }->{poe_actual_power} = $self->{results}->{$oid_poe_actual_power . '.' . $index}; |
| 208 |
} |
| 209 |
|
| 210 |
if (defined($self->{results}->{$oid_poe_status . '.' . $index})) { |
| 211 |
$self->{int}->{ $options{instance} }->{poestatus} = $map_poe_status->{ $self->{results}->{$oid_poe_status . '.' . $index} }; |
| 212 |
} |
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
return if (!defined($self->{option_results}->{add_optical})); |
| 217 |
|
| 218 |
my $optical_ports = $self->{statefile_cache}->get(name => 'optical_ports'); |
| 219 |
return if (!defined($optical_ports->{ $options{instance} })); |
| 220 |
|
| 221 |
my $result = $self->{snmp}->map_instance(mapping => $mapping_optical, results => $self->{results}, instance => $options{instance}); |
| 222 |
|
| 223 |
$self->{int}->{ $options{instance} }->{input_power} = undef; |
| 224 |
if (defined($result->{input_power}) && $result->{input_power} != 0 && $result->{input_power} != -99999999) { |
| 225 |
$self->{int}->{ $options{instance} }->{input_power} = $result->{input_power} / 1000; |
| 226 |
} |
| 227 |
|
| 228 |
$self->{int}->{$options{instance}}->{bias_current} = undef; |
| 229 |
if (defined($result->{bias_current}) && $result->{bias_current} != 0) { |
| 230 |
$self->{int}->{$options{instance}}->{bias_current} = $result->{bias_current} / 1000; |
| 231 |
} |
| 232 |
|
| 233 |
$self->{int}->{$options{instance}}->{output_power} = undef; |
| 234 |
if (defined($result->{output_power}) && $result->{output_power} != 0 && $result->{output_power} != -99999999) { |
| 235 |
$self->{int}->{$options{instance}}->{output_power} = $result->{output_power} / 1000; |
| 236 |
} |
| 237 |
|
| 238 |
$self->{int}->{$options{instance}}->{module_temperature} = undef; |
| 239 |
if (defined($result->{module_temperature}) && $result->{module_temperature} != 0) { |
| 240 |
$self->{int}->{$options{instance}}->{module_temperature} = $result->{module_temperature} / 1000; |
| 241 |
} |
| 242 |
|
| 243 |
$self->{int}->{$options{instance}}->{voltage} = undef; |
| 244 |
if (defined($result->{voltage}) && $result->{voltage} != 0) { |
| 245 |
$self->{int}->{$options{instance}}->{voltage} = $result->{voltage} / 10000; |
| 246 |
} |
| 247 |
} |
| 248 |
|
| 249 |
1; |
| 250 |
|
| 251 |
__END__ |
| 252 |
|
| 253 |
=head1 MODE |
| 254 |
|
| 255 |
Check interfaces. |
| 256 |
|
| 257 |
=over 8 |
| 258 |
|
| 259 |
=item B<--add-global> |
| 260 |
|
| 261 |
Check global port statistics (by default if no --add-* option is set). |
| 262 |
|
| 263 |
=item B<--add-status> |
| 264 |
|
| 265 |
Check interface status. |
| 266 |
|
| 267 |
=item B<--add-duplex-status> |
| 268 |
|
| 269 |
Check duplex status (with --warning-status and --critical-status). |
| 270 |
|
| 271 |
=item B<--add-traffic> |
| 272 |
|
| 273 |
Check interface traffic. |
| 274 |
|
| 275 |
=item B<--add-errors> |
| 276 |
|
| 277 |
Check interface errors. |
| 278 |
|
| 279 |
=item B<--add-cast> |
| 280 |
|
| 281 |
Check interface cast. |
| 282 |
|
| 283 |
=item B<--add-speed> |
| 284 |
|
| 285 |
Check interface speed. |
| 286 |
|
| 287 |
=item B<--add-volume> |
| 288 |
|
| 289 |
Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting). |
| 290 |
|
| 291 |
=item B<--add-poe> |
| 292 |
|
| 293 |
Check power over thernet. |
| 294 |
|
| 295 |
=item B<--add-optical> |
| 296 |
|
| 297 |
Check interface optical metrics. |
| 298 |
|
| 299 |
=item B<--check-metrics> |
| 300 |
|
| 301 |
If the expression is true, metrics are checked (default: '%{opstatus} eq "up"'). |
| 302 |
|
| 303 |
=item B<--warning-status> |
| 304 |
|
| 305 |
Define the conditions to match for the status to be WARNING. |
| 306 |
You can use the following variables: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display} |
| 307 |
|
| 308 |
=item B<--critical-status> |
| 309 |
|
| 310 |
Define the conditions to match for the status to be CRITICAL (default: '%{admstatus} eq "up" and %{opstatus} ne "up"'). |
| 311 |
You can use the following variables: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display} |
| 312 |
|
| 313 |
=item B<--warning-poe-status> |
| 314 |
|
| 315 |
Set warning threshold for poe status. |
| 316 |
You can use the following variables: %{admstatus}, %{opstatus}, %{poestatus}, %{display} |
| 317 |
|
| 318 |
=item B<--critical-poe-status> |
| 319 |
|
| 320 |
Define the conditions to match for the status to be CRITICAL. |
| 321 |
You can use the following variables: %{admstatus}, %{opstatus}, %{poestatus}, %{display} |
| 322 |
|
| 323 |
=item B<--warning-*> B<--critical-*> |
| 324 |
|
| 325 |
Thresholds. |
| 326 |
Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down', |
| 327 |
'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard', |
| 328 |
'in-ucast', 'in-bcast', 'in-mcast', 'out-ucast', 'out-bcast', 'out-mcast', |
| 329 |
'speed' (b/s). |
| 330 |
|
| 331 |
And also: 'input-power' (dBm), 'bias-current' (mA), 'output-power' (dBm), 'voltage' (mV), 'module-temperature' (C), 'poe-power-actual'. |
| 332 |
|
| 333 |
=item B<--units-traffic> |
| 334 |
|
| 335 |
Units of thresholds for the traffic (default: 'percent_delta') ('percent_delta', 'bps', 'counter'). |
| 336 |
|
| 337 |
=item B<--units-errors> |
| 338 |
|
| 339 |
Units of thresholds for errors/discards (default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'deltaps', 'counter'). |
| 340 |
|
| 341 |
=item B<--units-cast> |
| 342 |
|
| 343 |
Units of thresholds for communication types (default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'deltaps', 'counter'). |
| 344 |
|
| 345 |
=item B<--nagvis-perfdata> |
| 346 |
|
| 347 |
Display traffic perfdata to be compatible with nagvis widget. |
| 348 |
|
| 349 |
=item B<--interface> |
| 350 |
|
| 351 |
Set the interface (number expected) example: 1,2,... (empty means 'check all interfaces'). |
| 352 |
|
| 353 |
=item B<--name> |
| 354 |
|
| 355 |
Allows you to define the interface (in option --interface) by name instead of OID index. The name matching mode supports regular expressions. |
| 356 |
|
| 357 |
=item B<--speed> |
| 358 |
|
| 359 |
Set interface speed for incoming/outgoing traffic (in Mb). |
| 360 |
|
| 361 |
=item B<--speed-in> |
| 362 |
|
| 363 |
Set interface speed for incoming traffic (in Mb). |
| 364 |
|
| 365 |
=item B<--speed-out> |
| 366 |
|
| 367 |
Set interface speed for outgoing traffic (in Mb). |
| 368 |
|
| 369 |
=item B<--force-counters32> |
| 370 |
|
| 371 |
Force to use 32 bits counters (even in snmp v2c and v3). Should be used when 64 bits counters are buggy. |
| 372 |
|
| 373 |
=item B<--reload-cache-time> |
| 374 |
|
| 375 |
Time in minutes before reloading cache file (default: 180). |
| 376 |
|
| 377 |
=item B<--oid-filter> |
| 378 |
|
| 379 |
Define the OID to be used to filter interfaces (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr). |
| 380 |
|
| 381 |
=item B<--oid-display> |
| 382 |
|
| 383 |
Define the OID that will be used to name the interfaces (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr). |
| 384 |
|
| 385 |
=item B<--oid-extra-display> |
| 386 |
|
| 387 |
Add an OID to display. |
| 388 |
|
| 389 |
=item B<--display-transform-src> B<--display-transform-dst> |
| 390 |
|
| 391 |
Modify the interface name displayed by using a regular expression. |
| 392 |
|
| 393 |
Example: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' |
| 394 |
|
| 395 |
=item B<--show-cache> |
| 396 |
|
| 397 |
Display cache interface data. |
| 398 |
|
| 399 |
=back |
| 400 |
|
| 401 |
=cut |