From 72b2afedb19ba1daf11c5ecf7a17398baac077fd Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 24 Mar 2020 11:27:14 +0100 Subject: [PATCH] add vdom for interfaces fortigate --- .../fortigate/snmp/mode/interfaces.pm | 197 +++++++++++++++ network/fortinet/fortigate/snmp/plugin.pm | 2 +- snmp_standard/mode/interfaces.pm | 224 ++++++++++-------- 3 files changed, 319 insertions(+), 104 deletions(-) create mode 100644 centreon/common/fortinet/fortigate/snmp/mode/interfaces.pm diff --git a/centreon/common/fortinet/fortigate/snmp/mode/interfaces.pm b/centreon/common/fortinet/fortigate/snmp/mode/interfaces.pm new file mode 100644 index 000000000..2c39ef269 --- /dev/null +++ b/centreon/common/fortinet/fortigate/snmp/mode/interfaces.pm @@ -0,0 +1,197 @@ +# +# Copyright 2020 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package centreon::common::fortinet::fortigate::snmp::mode::interfaces; + +use base qw(snmp_standard::mode::interfaces); + +use strict; +use warnings; + +sub set_oids_label { + my ($self, %options) = @_; + + $self->SUPER::set_oids_label(%options); + $self->{oids_label}->{vdom} = { oid => '.1.3.6.1.4.1.12356.101.7.2.1.1.1', cache => 'reload_cache_vdom_index' }; +} + +sub reload_cache_vdom_index { + my ($self, %options) = @_; + + my $oid_fgVdEntName = '.1.3.6.1.4.1.12356.101.3.2.1.1.2'; + my $snmp_result = $self->{snmp}->get_table(oid => $oid_fgVdEntName); + + my $store_index = defined($options{store_index}) && $options{store_index} == 1 ? 1 : 0; + foreach (keys %{$options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }}) { + /^$self->{oids_label}->{$options{name}}->{oid}\.(.*)$/; + push @{$options{datas}->{all_ids}}, $1 if ($store_index == 1); + + $options{datas}->{$options{name} . "_" . $1} = $snmp_result->{ $oid_fgVdEntName . '.' . $options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }->{$_} }; + } +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + return $self; +} + + +1; + +__END__ + +=head1 MODE + +Check interfaces. + +=over 8 + +=item B<--add-global> + +Check global port statistics (By default if no --add-* option is set). + +=item B<--add-status> + +Check interface status. + +=item B<--add-duplex-status> + +Check duplex status (with --warning-status and --critical-status). + +=item B<--add-traffic> + +Check interface traffic. + +=item B<--add-errors> + +Check interface errors. + +=item B<--add-cast> + +Check interface cast. + +=item B<--add-speed> + +Check interface speed. + +=item B<--add-volume> + +Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting). + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{admstatus} eq "up" and %{opstatus} ne "up"'). +Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display} + +=item B<--warning-*> + +Threshold warning. +Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down', +'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard', +'in-ucast' (%), 'in-bcast' (%), 'in-mcast' (%), 'out-ucast' (%), 'out-bcast' (%), 'out-mcast' (%), +'speed' (b/s). + +=item B<--critical-*> + +Threshold critical. +Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down', +'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard', +'in-ucast' (%), 'in-bcast' (%), 'in-mcast' (%), 'out-ucast' (%), 'out-bcast' (%), 'out-mcast' (%), +'speed' (b/s). + +=item B<--units-traffic> + +Units of thresholds for the traffic (Default: '%') ('%', 'b/s'). + +=item B<--units-errors> + +Units of thresholds for errors/discards (Default: '%') ('%', 'absolute'). + +=item B<--nagvis-perfdata> + +Display traffic perfdata to be compatible with nagvis widget. + +=item B<--interface> + +Set the interface (number expected) ex: 1,2,... (empty means 'check all interface'). + +=item B<--name> + +Allows to use interface name with option --interface instead of interface oid index (Can be a regexp) + +=item B<--speed> + +Set interface speed for incoming/outgoing traffic (in Mb). + +=item B<--speed-in> + +Set interface speed for incoming traffic (in Mb). + +=item B<--speed-out> + +Set interface speed for outgoing traffic (in Mb). + +=item B<--no-skipped-counters> + +Don't skip counters when no change. + +=item B<--force-counters32> + +Force to use 32 bits counters (even in snmp v2c and v3). Should be used when 64 bits counters are buggy. + +=item B<--reload-cache-time> + +Time in minutes before reloading cache file (default: 180). + +=item B<--oid-filter> + +Choose OID used to filter interface (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr, Vdom). + +=item B<--oid-display> + +Choose OID used to display interface (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr, Vdom). + +=item B<--oid-extra-display> + +Add an OID to display. + +=item B<--display-transform-src> + +Regexp src to transform display value. + +=item B<--display-transform-dst> + +Regexp dst to transform display value. + +=item B<--show-cache> + +Display cache interface datas. + +=back + +=cut diff --git a/network/fortinet/fortigate/snmp/plugin.pm b/network/fortinet/fortigate/snmp/plugin.pm index 693214c43..bf748554f 100644 --- a/network/fortinet/fortigate/snmp/plugin.pm +++ b/network/fortinet/fortigate/snmp/plugin.pm @@ -36,7 +36,7 @@ sub new { 'cpu' => 'centreon::common::fortinet::fortigate::snmp::mode::cpu', 'disk' => 'centreon::common::fortinet::fortigate::snmp::mode::disk', 'hardware' => 'centreon::common::fortinet::fortigate::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', + 'interfaces' => 'centreon::common::fortinet::fortigate::snmp::mode::interfaces', 'ips-stats' => 'centreon::common::fortinet::fortigate::snmp::mode::ipsstats', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'list-virtualdomains' => 'centreon::common::fortinet::fortigate::snmp::mode::listvirtualdomains', diff --git a/snmp_standard/mode/interfaces.pm b/snmp_standard/mode/interfaces.pm index c0a9a3a35..013e6b125 100644 --- a/snmp_standard/mode/interfaces.pm +++ b/snmp_standard/mode/interfaces.pm @@ -34,7 +34,7 @@ sub custom_threshold_output { my ($self, %options) = @_; my $status = 'ok'; my $message; - + eval { local $SIG{__WARN__} = sub { $message = $_[0]; }; local $SIG{__DIE__} = sub { $message = $_[0]; }; @@ -90,14 +90,14 @@ sub custom_cast_calc { my $diff_cast = ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}}); my $total = $diff_cast - + ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref1}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref1}}) - + ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref2}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref2}}); + + ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref1}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref1}}) + + ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref2}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref2}}); if ($total == 0 && !defined($self->{instance_mode}->{option_results}->{no_skipped_counters})) { $self->{error_msg} = "skipped"; return -2; } - + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; $self->{result_values}->{$options{extra_options}->{label_ref} . '_prct'} = $total == 0 ? 0 : $diff_cast * 100 / $total; return 0; @@ -126,7 +126,7 @@ sub custom_traffic_perfdata { $self->{output}->perfdata_add( label => $self->{result_values}->{label}, instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, - value => sprintf("%.2f", $self->{result_values}->{traffic_per_seconds}), + value => sprintf('%.2f', $self->{result_values}->{traffic_per_seconds}), warning => $warning, critical => $critical, min => 0, max => $self->{result_values}->{speed} @@ -136,7 +136,7 @@ sub custom_traffic_perfdata { label => 'traffic_' . $self->{result_values}->{label}, unit => 'b/s', nlabel => $self->{nlabel}, instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, - value => sprintf("%.2f", $self->{result_values}->{traffic_per_seconds}), + value => sprintf('%.2f', $self->{result_values}->{traffic_per_seconds}), warning => $warning, critical => $critical, min => 0, max => $self->{result_values}->{speed} @@ -160,10 +160,11 @@ sub custom_traffic_output { my ($self, %options) = @_; my ($traffic_value, $traffic_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{traffic_per_seconds}, network => 1); - my $msg = sprintf("Traffic %s : %s/s (%s)", - ucfirst($self->{result_values}->{label}), $traffic_value . $traffic_unit, - defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-'); - return $msg; + return sprintf( + 'Traffic %s : %s/s (%s)', + ucfirst($self->{result_values}->{label}), $traffic_value . $traffic_unit, + defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-' + ); } sub custom_traffic_calc { @@ -171,13 +172,13 @@ sub custom_traffic_calc { return -10 if (defined($self->{instance_mode}->{last_status}) && $self->{instance_mode}->{last_status} == 0); if ($options{new_datas}->{$self->{instance} . '_mode_traffic'} ne $options{old_datas}->{$self->{instance} . '_mode_traffic'}) { - $self->{error_msg} = "buffer creation"; + $self->{error_msg} = 'buffer creation'; return -2; } my $diff_traffic = ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}}); if ($diff_traffic == 0 && !defined($self->{instance_mode}->{option_results}->{no_skipped_counters})) { - $self->{error_msg} = "skipped"; + $self->{error_msg} = 'skipped'; return -2; } @@ -187,7 +188,7 @@ sub custom_traffic_calc { $self->{result_values}->{traffic_prct} = $self->{result_values}->{traffic_per_seconds} * 100 / $options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}}; $self->{result_values}->{speed} = $options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}}; } - + $self->{result_values}->{label} = $options{extra_options}->{label_ref}; $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; return 0; @@ -223,7 +224,7 @@ sub custom_errors_perfdata { sub custom_errors_threshold { my ($self, %options) = @_; - + my $exit = 'ok'; if ($self->{instance_mode}->{option_results}->{units_errors} eq '%') { $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); @@ -236,10 +237,11 @@ sub custom_errors_threshold { sub custom_errors_output { my ($self, %options) = @_; - my $msg = sprintf("Packets %s : %.2f%% (%s)", - $self->{result_values}->{label}, - $self->{result_values}->{prct}, $self->{result_values}->{used}); - return $msg; + return sprintf( + 'Packets %s : %.2f%% (%s)', + $self->{result_values}->{label}, + $self->{result_values}->{prct}, $self->{result_values}->{used} + ); } sub custom_errors_calc { @@ -250,7 +252,7 @@ sub custom_errors_calc { $self->{error_msg} = "buffer creation"; return -2; } - + my $diff = ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref1} . $options{extra_options}->{label_ref2}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref1} . $options{extra_options}->{label_ref2}}); my $total = ($options{new_datas}->{$self->{instance} . '_total_' . $options{extra_options}->{label_ref1} . '_packets'} - @@ -259,7 +261,7 @@ sub custom_errors_calc { $self->{error_msg} = "skipped"; return -2; } - + $self->{result_values}->{prct} = $total == 0 ? 0 : $diff * 100 / $total; $self->{result_values}->{used} = $diff; $self->{result_values}->{total} = $total; @@ -296,8 +298,8 @@ sub set_counters_global { output_use => 'total_port_absolute', threshold_use => 'total_port_absolute', perfdatas => [ { label => 'total_port', value => 'total_port_absolute', template => '%s', - min => 0, max => 'total_port_absolute' }, - ], + min => 0, max => 'total_port_absolute' } + ] } }, { label => 'global-admin-up', filter => 'add_global', nlabel => 'total.interfaces.admin.up.count', set => { @@ -306,8 +308,8 @@ sub set_counters_global { output_use => 'global_admin_up_absolute', threshold_use => 'global_admin_up_absolute', perfdatas => [ { label => 'total_admin_up', value => 'global_admin_up_absolute', template => '%s', - min => 0, max => 'total_port_absolute' }, - ], + min => 0, max => 'total_port_absolute' } + ] } }, { label => 'total-admin-down', filter => 'add_global', nlabel => 'total.interfaces.admin.down.count', set => { @@ -316,8 +318,8 @@ sub set_counters_global { output_use => 'global_admin_down_absolute', threshold_use => 'global_admin_down_absolute', perfdatas => [ { label => 'total_admin_down', value => 'global_admin_down_absolute', template => '%s', - min => 0, max => 'total_port_absolute' }, - ], + min => 0, max => 'total_port_absolute' } + ] } }, { label => 'total-oper-up', filter => 'add_global', nlabel => 'total.interfaces.operational.up.count', set => { @@ -326,8 +328,8 @@ sub set_counters_global { output_use => 'global_oper_up_absolute', threshold_use => 'global_oper_up_absolute', perfdatas => [ { label => 'total_oper_up', value => 'global_oper_up_absolute', template => '%s', - min => 0, max => 'total_port_absolute' }, - ], + min => 0, max => 'total_port_absolute' } + ] } }, { label => 'total-oper-down', filter => 'add_global', nlabel => 'total.interfaces.operational.down.count', set => { @@ -336,10 +338,10 @@ sub set_counters_global { output_use => 'global_oper_down_absolute', threshold_use => 'global_oper_down_absolute', perfdatas => [ { label => 'global_oper_down', value => 'global_oper_down_absolute', template => '%s', - min => 0, max => 'total_port_absolute' }, - ], + min => 0, max => 'total_port_absolute' } + ] } - }, + } ; } @@ -352,9 +354,9 @@ sub set_counters_status { closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => $self->can('custom_threshold_output'), + closure_custom_threshold_check => $self->can('custom_threshold_output') } - }, + } ; } @@ -370,7 +372,7 @@ sub set_counters_traffic { closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in' }, closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic In : %s', closure_custom_perfdata => $self->can('custom_traffic_perfdata'), - closure_custom_threshold_check => $self->can('custom_traffic_threshold'), + closure_custom_threshold_check => $self->can('custom_traffic_threshold') } }, { label => 'out-traffic', filter => 'add_traffic', nlabel => 'interface.traffic.out.bitspersecond', set => { @@ -379,9 +381,9 @@ sub set_counters_traffic { closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out' }, closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic Out : %s', closure_custom_perfdata => $self->can('custom_traffic_perfdata'), - closure_custom_threshold_check => $self->can('custom_traffic_threshold'), + closure_custom_threshold_check => $self->can('custom_traffic_threshold') } - }, + } ; } @@ -396,7 +398,7 @@ sub set_counters_errors { closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc_extra_options => { label_ref1 => 'in', label_ref2 => 'discard' }, closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets In Discard : %s', closure_custom_perfdata => $self->can('custom_errors_perfdata'), - closure_custom_threshold_check => $self->can('custom_errors_threshold'), + closure_custom_threshold_check => $self->can('custom_errors_threshold') } }, { label => 'in-error', filter => 'add_errors', nlabel => 'interface.packets.in.errors.count', set => { @@ -404,7 +406,7 @@ sub set_counters_errors { closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc_extra_options => { label_ref1 => 'in', label_ref2 => 'error' }, closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets In Error : %s', closure_custom_perfdata => $self->can('custom_errors_perfdata'), - closure_custom_threshold_check => $self->can('custom_errors_threshold'), + closure_custom_threshold_check => $self->can('custom_errors_threshold') } }, { label => 'out-discard', filter => 'add_errors', nlabel => 'interface.packets.out.discards.count', set => { @@ -412,7 +414,7 @@ sub set_counters_errors { closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc_extra_options => { label_ref1 => 'out', label_ref2 => 'discard' }, closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets Out Discard : %s', closure_custom_perfdata => $self->can('custom_errors_perfdata'), - closure_custom_threshold_check => $self->can('custom_errors_threshold'), + closure_custom_threshold_check => $self->can('custom_errors_threshold') } }, { label => 'out-error', filter => 'add_errors', nlabel => 'interface.packets.out.errors.count', set => { @@ -420,9 +422,9 @@ sub set_counters_errors { closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc_extra_options => { label_ref1 => 'out', label_ref2 => 'error' }, closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets Out Error : %s', closure_custom_perfdata => $self->can('custom_errors_perfdata'), - closure_custom_threshold_check => $self->can('custom_errors_threshold'), + closure_custom_threshold_check => $self->can('custom_errors_threshold') } - }, + } ; } @@ -439,8 +441,8 @@ sub set_counters_cast { output_use => 'iucast_prct', threshold_use => 'iucast_prct', perfdatas => [ { value => 'iucast_prct', template => '%.2f', - unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, - ], + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' } + ] } }, { label => 'in-bcast', filter => 'add_cast', nlabel => 'interface.packets.in.broadcast.count', set => { @@ -450,8 +452,8 @@ sub set_counters_cast { output_use => 'ibcast_prct', threshold_use => 'ibcast_prct', perfdatas => [ { value => 'ibcast_prct', template => '%.2f', - unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, - ], + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' } + ] } }, { label => 'in-mcast', filter => 'add_cast', nlabel => 'interface.packets.in.multicast.count', set => { @@ -461,8 +463,8 @@ sub set_counters_cast { output_use => 'imcast_prct', threshold_use => 'imcast_prct', perfdatas => [ { value => 'imcast_prct', template => '%.2f', - unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, - ], + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' } + ] } }, { label => 'out-ucast', filter => 'add_cast', nlabel => 'interface.packets.out.unicast.count', set => { @@ -472,8 +474,8 @@ sub set_counters_cast { output_use => 'oucast_prct', threshold_use => 'oucast_prct', perfdatas => [ { value => 'oucast_prct', template => '%.2f', - unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, - ], + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' } + ] } }, { label => 'out-bcast', filter => 'add_cast', nlabel => 'interface.packets.out.broadcast.count', set => { @@ -483,8 +485,8 @@ sub set_counters_cast { output_use => 'obcast_prct', threshold_use => 'obcast_prct', perfdatas => [ { value => 'obcast_prct', template => '%.2f', - unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, - ], + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' } + ] } }, { label => 'out-mcast', filter => 'add_cast', nlabel => 'interface.packets.out.multicast.count', set => { @@ -494,8 +496,8 @@ sub set_counters_cast { output_use => 'omcast_prct', threshold_use => 'omcast_prct', perfdatas => [ { value => 'omcast_prct', template => '%.2f', - unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, - ], + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' } + ] } }, ; @@ -515,8 +517,8 @@ sub set_counters_speed { output_use => 'speed', threshold_use => 'speed', perfdatas => [ { value => 'speed', template => '%s', - unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display' }, - ], + unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display' } + ] } }, ; @@ -534,8 +536,8 @@ sub set_counters_volume { output_change_bytes => 1, perfdatas => [ { label => 'volume_in', value => 'in_volume_absolute', template => '%s', - unit => 'B', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + unit => 'B', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } + ] } }, { label => 'out-volume', filter => 'add_volume', nlabel => 'interface.volume.out.bytes', set => { @@ -544,10 +546,10 @@ sub set_counters_volume { output_change_bytes => 1, perfdatas => [ { label => 'volume_out', value => 'out_volume_absolute', template => '%s', - unit => 'B', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + unit => 'B', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } + ] } - }, + } ; } @@ -576,7 +578,7 @@ sub set_counters { sub prefix_interface_output { my ($self, %options) = @_; - + return "Interface '" . $options{instance_value}->{display} . "'$options{instance_value}->{extra_display} " } @@ -606,13 +608,13 @@ sub set_key_values_status { sub set_key_values_in_traffic { my ($self, %options) = @_; - + return [ { name => 'in', diff => 1 }, { name => 'speed_in'}, { name => 'display' }, { name => 'mode_traffic' } ]; } sub set_key_values_out_traffic { my ($self, %options) = @_; - + return [ { name => 'out', diff => 1 }, { name => 'speed_out'}, { name => 'display' }, { name => 'mode_traffic' } ]; } @@ -629,7 +631,7 @@ sub set_oids_label { sub set_oids_status { my ($self, %options) = @_; - + $self->{oid_adminstatus} = '.1.3.6.1.2.1.2.2.1.7'; $self->{oid_adminstatus_mapping} = { 1 => 'up', 2 => 'down', 3 => 'testing', 4 => 'unknown', 5 => 'dormant', 6 => 'notPresent', 7 => 'lowerLayerDown', @@ -646,7 +648,7 @@ sub set_oids_status { sub set_oids_errors { my ($self, %options) = @_; - + $self->{oid_ifInDiscards} = '.1.3.6.1.2.1.2.2.1.13'; $self->{oid_ifInErrors} = '.1.3.6.1.2.1.2.2.1.14'; $self->{oid_ifOutDiscards} = '.1.3.6.1.2.1.2.2.1.19'; @@ -655,7 +657,7 @@ sub set_oids_errors { sub set_oids_traffic { my ($self, %options) = @_; - + $self->{oid_speed32} = '.1.3.6.1.2.1.2.2.1.5'; # in b/s $self->{oid_in32} = '.1.3.6.1.2.1.2.2.1.10'; # in B $self->{oid_out32} = '.1.3.6.1.2.1.2.2.1.16'; # in B @@ -666,7 +668,7 @@ sub set_oids_traffic { sub set_oids_cast { my ($self, %options) = @_; - + # 32bits $self->{oid_ifInUcastPkts} = '.1.3.6.1.2.1.2.2.1.11'; $self->{oid_ifInBroadcastPkts} = '.1.3.6.1.2.1.31.1.1.1.3'; @@ -674,7 +676,7 @@ sub set_oids_cast { $self->{oid_ifOutUcastPkts} = '.1.3.6.1.2.1.2.2.1.17'; $self->{oid_ifOutMulticastPkts} = '.1.3.6.1.2.1.31.1.1.1.4'; $self->{oid_ifOutBroadcastPkts} = '.1.3.6.1.2.1.31.1.1.1.5'; - + # 64 bits $self->{oid_ifHCInUcastPkts} = '.1.3.6.1.2.1.31.1.1.1.7'; $self->{oid_ifHCInMulticastPkts} = '.1.3.6.1.2.1.31.1.1.1.8'; @@ -686,14 +688,14 @@ sub set_oids_cast { sub set_oids_speed { my ($self, %options) = @_; - + $self->{oid_speed32} = '.1.3.6.1.2.1.2.2.1.5'; # in b/s $self->{oid_speed64} = '.1.3.6.1.2.1.31.1.1.1.15'; # need multiple by '1000000' } sub check_oids_label { my ($self, %options) = @_; - + foreach (('oid_filter', 'oid_display')) { $self->{option_results}->{$_} = lc($self->{option_results}->{$_}) if (defined($self->{option_results}->{$_})); if (!defined($self->{oids_label}->{$self->{option_results}->{$_}}->{oid})) { @@ -703,7 +705,7 @@ sub check_oids_label { $self->{output}->option_exit(); } } - + if (defined($self->{option_results}->{oid_extra_display})) { $self->{option_results}->{oid_extra_display} = lc($self->{option_results}->{oid_extra_display}); if (!defined($self->{oids_label}->{$self->{option_results}->{oid_extra_display}}->{oid})) { @@ -715,55 +717,55 @@ sub check_oids_label { sub default_check_status { my ($self, %options) = @_; - + return '%{opstatus} eq "up"'; } sub default_warning_status { my ($self, %options) = @_; - + return ''; } sub default_critical_status { my ($self, %options) = @_; - + return '%{admstatus} eq "up" and %{opstatus} ne "up"'; } sub default_global_admin_up_rule { my ($self, %options) = @_; - + return '%{admstatus} eq "up"'; } sub default_global_admin_down_rule { my ($self, %options) = @_; - + return '%{admstatus} ne "up"'; } sub default_global_oper_up_rule { my ($self, %options) = @_; - + return '%{opstatus} eq "up"'; } sub default_global_oper_down_rule { my ($self, %options) = @_; - + return '%{opstatus} ne "up"'; } sub default_oid_filter_name { my ($self, %options) = @_; - + return 'ifname'; } sub default_oid_display_name { my ($self, %options) = @_; - + return 'ifname'; } @@ -798,7 +800,7 @@ sub new { 'show-cache' => { name => 'show_cache' }, 'reload-cache-time:s' => { name => 'reload_cache_time', default => 180 }, 'nagvis-perfdata' => { name => 'nagvis_perfdata' }, - 'force-counters32' => { name => 'force_counters32' }, + 'force-counters32' => { name => 'force_counters32' } }); if ($self->{no_traffic} == 0) { $options{options}->add_options(arguments => { 'add-traffic' => { name => 'add_traffic' } }); @@ -817,26 +819,26 @@ sub new { } if ($self->{no_oid_options} == 0) { $options{options}->add_options(arguments => { - 'oid-filter:s' => { name => 'oid_filter', default => $self->default_oid_filter_name() }, - 'oid-display:s' => { name => 'oid_display', default => $self->default_oid_display_name() }, - 'oid-extra-display:s' => { name => 'oid_extra_display' }, + 'oid-filter:s' => { name => 'oid_filter', default => $self->default_oid_filter_name() }, + 'oid-display:s' => { name => 'oid_display', default => $self->default_oid_display_name() }, + 'oid-extra-display:s' => { name => 'oid_extra_display' } }); } if ($self->{no_interfaceid_options} == 0) { $options{options}->add_options(arguments => { - 'name' => { name => 'use_name' }, + 'name' => { name => 'use_name' } }); } - + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); - + return $self; } sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - + $self->set_oids_label(); $self->check_oids_label(); @@ -912,9 +914,9 @@ sub check_oids_options_change { sub reload_cache_index_value { my ($self, %options) = @_; - + my $store_index = defined($options{store_index}) && $options{store_index} == 1 ? 1 : 0; - foreach ($self->{snmp}->oid_lex_sort(keys %{$options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }})) { + foreach (keys %{$options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }}) { /^$self->{oids_label}->{$options{name}}->{oid}\.(.*)$/; push @{$options{datas}->{all_ids}}, $1 if ($store_index == 1); $options{datas}->{$options{name} . "_" . $1} = $self->{output}->to_utf8($options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }->{$_}); @@ -923,9 +925,9 @@ sub reload_cache_index_value { sub reload_cache_values_index { my ($self, %options) = @_; - + my $store_index = defined($options{store_index}) && $options{store_index} == 1 ? 1 : 0; - foreach ($self->{snmp}->oid_lex_sort(keys %{$options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }})) { + foreach (keys %{$options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }}) { /^$self->{oids_label}->{$options{name}}->{oid}\.(.*)$/; push @{$options{datas}->{all_ids}}, $options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }->{$_} if ($store_index == 1); if (defined($options{datas}->{$options{name} . "_" . $options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }->{$_}})) { @@ -985,7 +987,8 @@ sub add_selected_interface { $self->{int}->{$options{id}} = { display => $self->get_display_value(id => $options{id}), extra_display => '' }; if (defined($self->{option_results}->{oid_extra_display})) { - $self->{int}->{$options{id}}->{extra_display} = ' [ ' . $self->{statefile_cache}->get(name => $self->{option_results}->{oid_extra_display} . "_" . $options{id}) . ' ]'; + my $name = $self->{statefile_cache}->get(name => $self->{option_results}->{oid_extra_display} . '_' . $options{id}); + $self->{int}->{$options{id}}->{extra_display} = ' [ ' . (defined($name) ? $name : '') . ' ]'; } } @@ -1068,21 +1071,34 @@ sub load_errors { my ($self, %options) = @_; $self->set_oids_errors(); - $self->{snmp}->load(oids => [$self->{oid_ifInDiscards}, $self->{oid_ifInErrors}, - $self->{oid_ifOutDiscards}, $self->{oid_ifOutErrors}], instances => $self->{array_interface_selected}); + $self->{snmp}->load( + oids => [ + $self->{oid_ifInDiscards}, $self->{oid_ifInErrors}, + $self->{oid_ifOutDiscards}, $self->{oid_ifOutErrors} + ], + instances => $self->{array_interface_selected} + ); } sub load_cast { my ($self, %options) = @_; $self->set_oids_cast(); - $self->{snmp}->load(oids => [$self->{oid_ifInUcastPkts}, $self->{oid_ifInBroadcastPkts}, $self->{oid_ifInMulticastPkts}, - $self->{oid_ifOutUcastPkts}, $self->{oid_ifOutMulticastPkts}, $self->{oid_ifOutBroadcastPkts}], - instances => $self->{array_interface_selected}); + $self->{snmp}->load( + oids => [ + $self->{oid_ifInUcastPkts}, $self->{oid_ifInBroadcastPkts}, $self->{oid_ifInMulticastPkts}, + $self->{oid_ifOutUcastPkts}, $self->{oid_ifOutMulticastPkts}, $self->{oid_ifOutBroadcastPkts} + ], + instances => $self->{array_interface_selected} + ); if (!$self->{snmp}->is_snmpv1() && !defined($self->{option_results}->{force_counters32})) { - $self->{snmp}->load(oids => [$self->{oid_ifHCInUcastPkts}, $self->{oid_ifHCInMulticastPkts}, $self->{oid_ifHCInBroadcastPkts}, - $self->{oid_ifHCOutUcastPkts}, $self->{oid_ifHCOutMulticastPkts}, $self->{oid_ifHCOutBroadcastPkts}], - instances => $self->{array_interface_selected}); + $self->{snmp}->load( + oids => [ + $self->{oid_ifHCInUcastPkts}, $self->{oid_ifHCInMulticastPkts}, $self->{oid_ifHCInBroadcastPkts}, + $self->{oid_ifHCOutUcastPkts}, $self->{oid_ifHCOutMulticastPkts}, $self->{oid_ifHCOutBroadcastPkts} + ], + instances => $self->{array_interface_selected} + ); } } @@ -1151,8 +1167,10 @@ sub add_result_global { } } - $self->{global} = { total_port => 0, global_admin_up => 0, global_admin_down => 0, - global_oper_up => 0, global_oper_down => 0}; + $self->{global} = { + total_port => 0, global_admin_up => 0, global_admin_down => 0, + global_oper_up => 0, global_oper_down => 0 + }; foreach (@{$self->{array_interface_selected}}) { my $opstatus = $self->{oid_opstatus_mapping}->{$self->{results}->{$self->{oid_opstatus} . '.' . $_}}; my $admstatus = $self->{oid_adminstatus_mapping}->{$self->{results}->{$self->{oid_adminstatus} . '.' . $_}};