diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/interfaces.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/interfaces.pm index 63c4c87a1..e13db1078 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/interfaces.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/interfaces.pm @@ -107,9 +107,9 @@ sub set_counters_errors { closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc_extra_options => { label_ref1 => 'in', label_ref2 => 'crc' }, closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets In Crc : %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') } - }, + } ; } @@ -119,7 +119,7 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'add-err-disable' => { name => 'add_err_disable' }, + 'add-err-disable' => { name => 'add_err_disable' } }); return $self; @@ -244,16 +244,20 @@ Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{e Thresholds. Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down', 'in-traffic', 'out-traffic', 'in-crc', 'in-error', 'in-discard', 'out-error', 'out-discard', -'in-ucast' (%), 'in-bcast' (%), 'in-mcast' (%), 'out-ucast' (%), 'out-bcast' (%), 'out-mcast' (%), +'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'). +Units of thresholds for the traffic (Default: 'percent_delta') ('percent_delta', 'bps', 'counter'). =item B<--units-errors> -Units of thresholds for errors/discards (Default: '%') ('%', 'absolute'). +Units of thresholds for errors/discards (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'counter'). + +=item B<--units-cast> + +Units of thresholds for communication types (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'counter'). =item B<--nagvis-perfdata> @@ -279,10 +283,6 @@ Set interface speed for incoming traffic (in Mb). 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. diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/snmp/mode/interfaces.pm b/centreon-plugins/centreon/common/fortinet/fortigate/snmp/mode/interfaces.pm index f65d78ac4..2f49ddeb5 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/snmp/mode/interfaces.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/snmp/mode/interfaces.pm @@ -108,29 +108,25 @@ Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{d 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-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. +Thresholds. 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' (%), +'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'). +Units of thresholds for the traffic (Default: 'percent_delta') ('percent_delta', 'bps', 'counter'). =item B<--units-errors> -Units of thresholds for errors/discards (Default: '%') ('%', 'absolute'). +Units of thresholds for errors/discards (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'counter'). + +=item B<--units-cast> + +Units of thresholds for communication types (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'counter'). =item B<--nagvis-perfdata> @@ -156,10 +152,6 @@ Set interface speed for incoming traffic (in Mb). 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. diff --git a/centreon-plugins/centreon/plugins/output.pm b/centreon-plugins/centreon/plugins/output.pm index 1a9dca860..dcce213e1 100644 --- a/centreon-plugins/centreon/plugins/output.pm +++ b/centreon-plugins/centreon/plugins/output.pm @@ -195,20 +195,21 @@ sub output_add { sub perfdata_add { my ($self, %options) = @_; my $perfdata = { - label => '', value => '', unit => '', warning => '', critical => '', min => '', max => '', mode => $self->{mode}, + label => '', value => '', unit => '', warning => '', critical => '', min => '', max => '', mode => $self->{mode} }; foreach (keys %options) { next if (!defined($options{$_})); $perfdata->{$_} = $options{$_}; } - if (defined($self->{option_results}->{use_new_perfdata}) && defined($options{nlabel})) { + if ((defined($self->{option_results}->{use_new_perfdata}) || defined($options{force_new_perfdata})) && + defined($options{nlabel})) { $perfdata->{label} = $options{nlabel}; } if (defined($options{instances})) { $options{instances} = [$options{instances}] if (!ref($options{instances})); my ($external_instance_separator, $internal_instance_separator) = ('#', '~'); - if (defined($self->{option_results}->{use_new_perfdata})) { + if (defined($self->{option_results}->{use_new_perfdata}) || defined($options{force_new_perfdata})) { $perfdata->{label} = join('~', @{$options{instances}}) . '#' . $perfdata->{label}; } else { $perfdata->{label} .= '_' . join('_', @{$options{instances}}); diff --git a/centreon-plugins/network/adva/fsp3000/snmp/mode/interfaces.pm b/centreon-plugins/network/adva/fsp3000/snmp/mode/interfaces.pm index 6cd61c452..522352b65 100644 --- a/centreon-plugins/network/adva/fsp3000/snmp/mode/interfaces.pm +++ b/centreon-plugins/network/adva/fsp3000/snmp/mode/interfaces.pm @@ -27,7 +27,7 @@ use warnings; sub set_oids_traffic { my ($self, %options) = @_; - + $self->{currentEthRx15minBytes} = '.1.3.6.1.4.1.2544.1.11.2.6.2.52.1.5'; # in B $self->{currentEthRx1dayBytes} = '.1.3.6.1.4.1.2544.1.11.2.6.2.53.1.5'; # in B $self->{currentEthTx15minBytes} = '.1.3.6.1.4.1.2544.1.11.2.6.2.56.1.3'; # in B @@ -70,8 +70,8 @@ sub set_counters { output_template => 'Laser Temperature : %.2f C', output_error_template => 'Laser Temperature : %.2f', perfdatas => [ { label => 'laser_temp', template => '%.2f', - unit => 'C', label_extra_instance => 1, instance_use => 'display' }, - ], + unit => 'C', label_extra_instance => 1, instance_use => 'display' } + ] } }, { label => 'input-power', filter => 'add_optical', nlabel => 'interface.input.power.dbm', set => { @@ -79,8 +79,8 @@ sub set_counters { output_template => 'Input Power : %s dBm', output_error_template => 'Input Power : %s', perfdatas => [ { label => 'input_power', template => '%s', - unit => 'dBm', label_extra_instance => 1, instance_use => 'display' }, - ], + unit => 'dBm', label_extra_instance => 1, instance_use => 'display' } + ] } }, { label => 'output-power', filter => 'add_optical', nlabel => 'interface.output.power.dbm', set => { @@ -88,44 +88,61 @@ sub set_counters { output_template => 'Output Power : %s dBm', output_error_template => 'Output Power : %s', perfdatas => [ { label => 'output_power', template => '%s', - unit => 'dBm', label_extra_instance => 1, instance_use => 'display' }, - ], + unit => 'dBm', label_extra_instance => 1, instance_use => 'display' } + ] } - }, + } ; } sub custom_traffic_perfdata { my ($self, %options) = @_; - + my ($warning, $critical); - if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { - $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1); - $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1); - } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') { - $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}); - $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}); + if ($self->{instance_mode}->{option_results}->{units_traffic} eq 'percent_delta' && defined($self->{result_values}->{speed})) { + $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, total => $self->{result_values}->{speed}, cast_int => 1); + $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, total => $self->{result_values}->{speed}, cast_int => 1); + } elsif ($self->{instance_mode}->{option_results}->{units_traffic} =~ /bps|counter/) { + $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}); + $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}); + } + + if ($self->{instance_mode}->{option_results}->{units_traffic} eq 'counter') { + my $nlabel = $self->{nlabel}; + $nlabel =~ s/bitspersecond/bits/; + $self->{output}->perfdata_add( + force_new_perfdata => 1, + nlabel => $nlabel, + unit => 'b', + instances => $self->{result_values}->{display}, + value => $self->{result_values}->{traffic_counter}, + warning => $warning, + critical => $critical, + min => 0 + ); + } else { + $self->{output}->perfdata_add( + 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}), + warning => $warning, + critical => $critical, + min => 0, max => $self->{result_values}->{speed} + ); } - - $self->{output}->perfdata_add( - 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}), - warning => $warning, - critical => $critical, - min => 0, max => $self->{result_values}->{speed} - ); } sub custom_traffic_threshold { my ($self, %options) = @_; my $exit = 'ok'; - if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { + if ($self->{instance_mode}->{option_results}->{units_traffic} eq 'percent_delta' && defined($self->{result_values}->{speed})) { $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_prct}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); - } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') { + } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'bps') { $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_per_seconds}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); + } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'counter') { + $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_counter}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); } return $exit; } @@ -137,9 +154,11 @@ sub custom_traffic_output { $label =~ s/_/ /g; $label =~ s/(\w+)/\u$1/g; 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)", - $label, $traffic_value . $traffic_unit, - defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-'); + my $msg = sprintf( + "Traffic %s : %s/s (%s)", + $label, $traffic_value . $traffic_unit, + defined($self->{result_values}->{traffic_prct}) ? sprintf('%.2f%%', $self->{result_values}->{traffic_prct}) : '-' + ); return $msg; } @@ -154,15 +173,16 @@ sub custom_traffic_calc { $counter = 'traffic_' . $options{extra_options}->{label_ref} . '_1day'; } - my $diff_traffic = ($options{new_datas}->{$self->{instance} . '_' . $counter} - $options{old_datas}->{$self->{instance} . '_' . $counter}); - + my $diff_traffic = ($options{new_datas}->{ $self->{instance} . '_' . $counter } - $options{old_datas}->{ $self->{instance} . '_' . $counter }); + $self->{result_values}->{traffic_per_seconds} = $diff_traffic / $options{delta_time}; + $self->{result_values}->{traffic_counter} = $options{new_datas}->{ $self->{instance} . '_' . $counter }; if (defined($options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}}) && $options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}} > 0) { $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; @@ -174,7 +194,7 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'add-optical' => { name => 'add_optical' }, + 'add-optical' => { name => 'add_optical' } } ); @@ -238,9 +258,14 @@ sub load_traffic { } $self->set_oids_traffic(); - $self->{snmp}->load(oids => [$self->{currentEthRx15minBytes}, $self->{currentEthRx1dayBytes}, - $self->{currentEthTx15minBytes}, $self->{currentEthTx1dayBytes}, - $self->{currentEthRxHighSpeed15minBytes}, $self->{currentEthRxHighSpeed1dayBytes}], instances => $self->{array_interface_selected}); + $self->{snmp}->load( + oids => [ + $self->{currentEthRx15minBytes}, $self->{currentEthRx1dayBytes}, + $self->{currentEthTx15minBytes}, $self->{currentEthTx1dayBytes}, + $self->{currentEthRxHighSpeed15minBytes}, $self->{currentEthRxHighSpeed1dayBytes} + ], + instances => $self->{array_interface_selected} + ); } sub add_result_traffic { @@ -301,19 +326,14 @@ Can used special variables like: %{admstatus}, %{opstatus}, %{display} Set critical threshold for status (Default: '%{admstatus} eq "up" and %{opstatus} ne "up"'). Can used special variables like: %{admstatus}, %{opstatus}, %{display} -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. -Can be: 'laser-temp', 'input-power', 'output-power', 'traffic-in', 'traffic-out'. - -=item B<--critical-*> - -Threshold critical. +Thresholds. Can be: 'laser-temp', 'input-power', 'output-power', 'traffic-in', 'traffic-out'. =item B<--units-traffic> -Units of thresholds for the traffic (Default: '%') ('%', 'b/s'). +Units of thresholds for the traffic (Default: 'percent_delta') ('percent_delta', 'bps', 'counter'). =item B<--interface> diff --git a/centreon-plugins/network/atrica/snmp/mode/connections.pm b/centreon-plugins/network/atrica/snmp/mode/connections.pm index acfb19f19..7f0d9e80d 100644 --- a/centreon-plugins/network/atrica/snmp/mode/connections.pm +++ b/centreon-plugins/network/atrica/snmp/mode/connections.pm @@ -151,7 +151,7 @@ sub set_counters_traffic { closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in_cir' }, closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic In CIR : %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 => 'in-eir', filter => 'add_traffic', nlabel => 'interface.traffic.in.eir.bitspersecond', set => { @@ -159,23 +159,23 @@ sub set_counters_traffic { closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in_eir' }, closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic In EIR : %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-cir', filter => 'add_traffic', nlabel => 'interface.traffic.out.cir.bitspersecond', set => { - key_values => [ { name => 'out_cir', diff => 1 }, { name => 'speed_out'}, { name => 'display' } ], + key_values => [ { name => 'out_cir', diff => 1 }, { name => 'speed_out' }, { name => 'display' } ], closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out_cir' }, closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic Out CIR : %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-eir', filter => 'add_traffic', nlabel => 'interface.traffic.out.eir.bitspersecond', set => { - key_values => [ { name => 'out_eir', diff => 1 }, { name => 'speed_out'}, { name => 'display' } ], + key_values => [ { name => 'out_eir', diff => 1 }, { name => 'speed_out' }, { name => 'display' } ], closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out_eir' }, closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic Out EIR : %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') } } ; @@ -186,19 +186,19 @@ sub set_counters_errors { push @{$self->{maps_counters}->{int}}, { label => 'in-eir-discard', filter => 'add_errors', nlabel => 'interface.packets.in.eir.discard.count', set => { - key_values => [ { name => 'in_eir_discard', diff => 1 }, { name => 'speed_in'}, { name => 'display' } ], + key_values => [ { name => 'in_eir_discard', diff => 1 }, { name => 'speed_in' }, { name => 'display' } ], closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in_eir_discard' }, closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic In EIR Discard : %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-eir-discard', filter => 'add_errors', nlabel => 'interface.packets.out.eir.discard.count', set => { - key_values => [ { name => 'out_eir_discard', diff => 1 }, { name => 'speed_out'}, { name => 'display' } ], + key_values => [ { name => 'out_eir_discard', diff => 1 }, { name => 'speed_out' }, { name => 'display' } ], closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out_eir_discard' }, closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic Out EIR Discard : %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') } } ; @@ -208,33 +208,50 @@ sub custom_traffic_perfdata { my ($self, %options) = @_; my ($warning, $critical); - if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { - $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1); - $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1); - } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') { - $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}); - $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}); + if ($self->{instance_mode}->{option_results}->{units_traffic} eq 'percent_delta' && defined($self->{result_values}->{speed})) { + $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, total => $self->{result_values}->{speed}, cast_int => 1); + $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, total => $self->{result_values}->{speed}, cast_int => 1); + } elsif ($self->{instance_mode}->{option_results}->{units_traffic} =~ /bps|counter/) { + $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}); + $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}); + } + + if ($self->{instance_mode}->{option_results}->{units_traffic} eq 'counter') { + my $nlabel = $self->{nlabel}; + $nlabel =~ s/bitspersecond/bits/; + $self->{output}->perfdata_add( + force_new_perfdata => 1, + nlabel => $nlabel, + unit => 'b', + instances => $self->{result_values}->{display}, + value => $self->{result_values}->{traffic_counter}, + warning => $warning, + critical => $critical, + min => 0 + ); + } else { + $self->{output}->perfdata_add( + label => $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}), + warning => $warning, + critical => $critical, + min => 0, max => $self->{result_values}->{speed} + ); } - - $self->{output}->perfdata_add( - label => $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}), - warning => $warning, - critical => $critical, - min => 0, max => $self->{result_values}->{speed} - ); } sub custom_traffic_threshold { my ($self, %options) = @_; my $exit = 'ok'; - if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { + if ($self->{instance_mode}->{option_results}->{units_traffic} eq 'percent_delta' && defined($self->{result_values}->{speed})) { $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_prct}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); - } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') { + } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'bps') { $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_per_seconds}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); + } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'counter') { + $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_counter}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); } return $exit; } @@ -246,9 +263,11 @@ sub custom_traffic_output { $label =~ s/_/ /g; $label =~ s/(\w+)/\u$1/g; 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)", - $label, $traffic_value . $traffic_unit, - defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-'); + my $msg = sprintf( + "Traffic %s : %s/s (%s)", + $label, $traffic_value . $traffic_unit, + defined($self->{result_values}->{traffic_prct}) ? sprintf('%.2f%%', $self->{result_values}->{traffic_prct}) : '-' + ); return $msg; } @@ -257,13 +276,10 @@ sub custom_traffic_calc { return -10 if (defined($self->{instance_mode}->{last_status}) && $self->{instance_mode}->{last_status} == 0); - 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"; - 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} }); + $self->{result_values}->{traffic_per_seconds} = $diff_traffic / $options{delta_time}; + $self->{result_values}->{traffic_counter} = $options{new_datas}->{ $self->{instance} . '_' . $options{extra_options}->{label_ref} }; if (defined($options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}}) && $options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}} > 0) { $self->{result_values}->{traffic_prct} = $self->{result_values}->{traffic_per_seconds} * 100 / $options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}}; @@ -277,8 +293,7 @@ sub custom_traffic_calc { sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, - no_set_traffic => 1, no_set_errors => 1, no_cast => 1); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_set_traffic => 1, no_set_errors => 1, no_cast => 1); bless $self, $class; return $self; @@ -304,8 +319,10 @@ sub load_traffic { $self->load_speed(%options); } $self->set_oids_traffic(); - $self->{snmp}->load(oids => [$self->{oid_ing_cir}, $self->{oid_ing_eir}, - $self->{oid_eg_cir}, $self->{oid_eg_eir}], instances => $self->{array_interface_selected}); + $self->{snmp}->load(oids => [ + $self->{oid_ing_cir}, $self->{oid_ing_eir}, + $self->{oid_eg_cir}, $self->{oid_eg_eir}], instances => $self->{array_interface_selected} + ); } sub load_errors { @@ -399,23 +416,18 @@ Default (depends of the atrica release): '%{admstatus} eq "up" and %{opstatus} ne "up"' Can used special variables like: %{admstatus}, %{opstatus}, %{display} -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. -Can be: 'in-cir', 'in-eir', 'out-cir', 'out-eir', 'in-eir-discard', 'out-eir-discard'. - -=item B<--critical-*> - -Threshold critical. +Thresholds. Can be: 'in-cir', 'in-eir', 'out-cir', 'out-eir', 'in-eir-discard', 'out-eir-discard'. =item B<--units-traffic> -Units of thresholds for the traffic (Default: '%') ('%', 'b/s'). +Units of thresholds for the traffic (Default: 'percent_delta') ('percent_delta', 'bps', 'counter'). =item B<--units-errors> -Units of thresholds for discards (Default: '%') ('%', 'b/s'). +Units of thresholds for errors/discards (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'counter'). =item B<--interface> @@ -437,10 +449,6 @@ Set interface speed for incoming traffic (in Mb). Set interface speed for outgoing traffic (in Mb). -=item B<--no-skipped-counters> - -Don't skip counters when no change. - =item B<--reload-cache-time> Time in seconds before reloading cache file (default: 180). diff --git a/centreon-plugins/network/brocade/snmp/mode/interfaces.pm b/centreon-plugins/network/brocade/snmp/mode/interfaces.pm index e17f6e5c4..677b10656 100644 --- a/centreon-plugins/network/brocade/snmp/mode/interfaces.pm +++ b/centreon-plugins/network/brocade/snmp/mode/interfaces.pm @@ -306,16 +306,20 @@ Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{e Thresholds. Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down', 'in-traffic', 'out-traffic', 'in-crc', 'in-error', 'in-discard', 'out-error', 'out-discard', -'in-ucast' (%), 'in-bcast' (%), 'in-mcast' (%), 'out-ucast' (%), 'out-bcast' (%), 'out-mcast' (%), +'in-ucast', 'in-bcast', 'in-mcast', 'out-ucast', 'out-bcast', 'out-mcast', 'speed' (b/s), 'laser-temp', 'input-power', 'output-power'. =item B<--units-traffic> -Units of thresholds for the traffic (Default: '%') ('%', 'b/s'). +Units of thresholds for the traffic (Default: 'percent_delta') ('percent_delta', 'bps', 'counter'). =item B<--units-errors> -Units of thresholds for errors/discards (Default: '%') ('%', 'absolute'). +Units of thresholds for errors/discards (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'counter'). + +=item B<--units-cast> + +Units of thresholds for communication types (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'counter'). =item B<--nagvis-perfdata> @@ -341,10 +345,6 @@ Set interface speed for incoming traffic (in Mb). 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. diff --git a/centreon-plugins/network/dlink/standard/snmp/mode/interfaces.pm b/centreon-plugins/network/dlink/standard/snmp/mode/interfaces.pm index 41df7905f..ef088b181 100644 --- a/centreon-plugins/network/dlink/standard/snmp/mode/interfaces.pm +++ b/centreon-plugins/network/dlink/standard/snmp/mode/interfaces.pm @@ -177,16 +177,20 @@ Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{e Thresholds. 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' (%), +'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'). +Units of thresholds for the traffic (Default: 'percent_delta') ('percent_delta', 'bps', 'counter'). =item B<--units-errors> -Units of thresholds for errors/discards (Default: '%') ('%', 'absolute'). +Units of thresholds for errors/discards (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'counter'). + +=item B<--units-cast> + +Units of thresholds for communication types (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'counter'). =item B<--nagvis-perfdata> @@ -212,10 +216,6 @@ Set interface speed for incoming traffic (in Mb). 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. diff --git a/centreon-plugins/network/juniper/common/junos/mode/interfaces.pm b/centreon-plugins/network/juniper/common/junos/mode/interfaces.pm index c28794c51..f597907f2 100644 --- a/centreon-plugins/network/juniper/common/junos/mode/interfaces.pm +++ b/centreon-plugins/network/juniper/common/junos/mode/interfaces.pm @@ -94,7 +94,7 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'add-optical' => { name => 'add_optical' }, + 'add-optical' => { name => 'add_optical' } } ); @@ -294,33 +294,27 @@ Set warning threshold for all error counters. Set critical threshold for all error counters. -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning (will superseed --warning-errors). +Thresholds (will superseed --[warning-critical]-errors). 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' (%), +'in-ucast', 'in-bcast', 'in-mcast', 'out-ucast', 'out-bcast', 'out-mcast', 'speed' (b/s). And also: 'fcs-errors (%)', 'input-power' (dBm), 'bias-current' (mA), 'output-power' (dBm), 'module-temperature' (C). -=item B<--critical-*> - -Threshold critical (will superseed --warning-errors). -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). - -And also: 'in-fcserror' (%), 'input-power' (dBm), 'bias-current' (mA), 'output-power' (dBm), 'module-temperature' (C). - =item B<--units-traffic> -Units of thresholds for the traffic (Default: '%') ('%', 'b/s'). +Units of thresholds for the traffic (Default: 'percent_delta') ('percent_delta', 'bps', 'counter'). =item B<--units-errors> -Units of thresholds for errors/discards (Default: '%') ('%', 'absolute'). +Units of thresholds for errors/discards (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'counter'). + +=item B<--units-cast> + +Units of thresholds for communication types (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'counter'). =item B<--nagvis-perfdata> @@ -346,10 +340,6 @@ Set interface speed for incoming traffic (in Mb). 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. diff --git a/centreon-plugins/network/mikrotik/snmp/mode/interfaces.pm b/centreon-plugins/network/mikrotik/snmp/mode/interfaces.pm index be866586b..e903d145d 100644 --- a/centreon-plugins/network/mikrotik/snmp/mode/interfaces.pm +++ b/centreon-plugins/network/mikrotik/snmp/mode/interfaces.pm @@ -74,9 +74,9 @@ sub set_counters_errors { closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc_extra_options => { label => $1 . ' ' . $2, label_ref1 => lc($1), label_ref2 => lc($2) }, closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets ' . $1 . ' ' . $2 . ' : %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') } - }, + } ; } } @@ -88,7 +88,7 @@ sub new { $options{options}->add_options(arguments => { 'warning-errors:s' => { name => 'warning_errors' }, - 'critical-errors:s' => { name => 'critical_errors' }, + 'critical-errors:s' => { name => 'critical_errors' } }); return $self; @@ -191,27 +191,12 @@ Set warning threshold for all error counters. Set critical threshold for all error counters. -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning (will superseed --warning-errors). +Thresholds (will superseed --[warning|critical]-errors). 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). - -And also: 'in-tooshort' (%), 'in-toolong' (%), 'in-fcserror' (%), 'in-alignerror' (%), 'in-fragment' (%), -'in-overflow' (%), 'in-unknownop' (%), 'in-lengtherror' (%), 'in-codeerror' (%), 'in-carriererror' (%), -'in-jabber' (%), 'in-drop' (%), 'out-tooshort' (%), 'out-toolong' (%), 'out-underrun' (%), -'out-collision' (%), 'out-excessivecollision' (%), 'out-multiplecollision' (%), 'out-singlecollision' (%), -'out-excessivedeferred' (%),'out-deferred' (%), 'out-latecollision' (%), 'out-totalcollision' (%), -'out-drop' (%), 'out-jabber' (%), 'out-fcserror' (%), 'out-fragment' (%). - -=item B<--critical-*> - -Threshold critical (will superseed --warning-errors). -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' (%), +'in-ucast', 'in-bcast', 'in-mcast', 'out-ucast', 'out-bcast', 'out-mcast', 'speed' (b/s). And also: 'in-tooshort' (%), 'in-toolong' (%), 'in-fcserror' (%), 'in-alignerror' (%), 'in-fragment' (%), @@ -223,11 +208,15 @@ And also: 'in-tooshort' (%), 'in-toolong' (%), 'in-fcserror' (%), 'in-alignerror =item B<--units-traffic> -Units of thresholds for the traffic (Default: '%') ('%', 'b/s'). +Units of thresholds for the traffic (Default: 'percent_delta') ('percent_delta', 'bps', 'counter'). =item B<--units-errors> -Units of thresholds for errors/discards (Default: '%') ('%', 'absolute'). +Units of thresholds for errors/discards (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'counter'). + +=item B<--units-cast> + +Units of thresholds for communication types (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'counter'). =item B<--nagvis-perfdata> @@ -253,10 +242,6 @@ Set interface speed for incoming traffic (in Mb). 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. diff --git a/centreon-plugins/network/mrv/optiswitch/snmp/mode/interfaces.pm b/centreon-plugins/network/mrv/optiswitch/snmp/mode/interfaces.pm index 0061a60d5..e350f8bc1 100644 --- a/centreon-plugins/network/mrv/optiswitch/snmp/mode/interfaces.pm +++ b/centreon-plugins/network/mrv/optiswitch/snmp/mode/interfaces.pm @@ -58,8 +58,8 @@ sub set_counters_global { output_use => 'global_link_up', threshold_use => 'global_link_up', perfdatas => [ { label => 'total_link_up', value => 'global_link_up', template => '%s', - min => 0, max => 'total_port' }, - ], + min => 0, max => 'total_port' } + ] } }, { label => 'total-link-down', filter => 'add_global', nlabel => 'total.interfaces.link.down.count', set => { @@ -68,10 +68,10 @@ sub set_counters_global { output_use => 'global_link_down', threshold_use => 'global_link_down', perfdatas => [ { label => 'total_link_down', value => 'global_link_down', template => '%s', - min => 0, max => 'total_port' }, - ], + min => 0, max => 'total_port' } + ] } - }, + } ; } @@ -84,9 +84,9 @@ sub set_counters_errors { closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc_extra_options => { label_ref1 => 'in', label_ref2 => 'crc' }, closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets In Crc : %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') } - }, + } ; } @@ -259,9 +259,13 @@ sub load_cast { $self->set_oids_cast(); - $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} + ); } sub load_errors { @@ -464,23 +468,24 @@ Can used special variables like: %{linkstatus}, %{admstatus}, %{opstatus}, %{dup Set critical threshold for status (Default: '%{admstatus} eq "enable" and %{opstatus} eq "enabled" and %{linkstatus} ne "true"'). Can used special variables like: %{linkstatus}, %{admstatus}, %{opstatus}, %{duplexstatus}, %{display} -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. +Thresholds. Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down', 'total-link-up', 'total-link-down', -'in-traffic', 'out-traffic', 'in-crc', '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', 'total-link-up', 'total-link-down', -'in-traffic', 'out-traffic', 'in-crc', 'in-ucast' (%), 'in-bcast' (%), 'in-mcast' (%), 'out-ucast' (%), 'out-bcast' (%), 'out-mcast' (%), +'in-traffic', 'out-traffic', 'in-crc', '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'). +Units of thresholds for the traffic (Default: 'percent_delta') ('percent_delta', 'bps', 'counter'). + +=item B<--units-errors> + +Units of thresholds for errors/discards (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'counter'). + +=item B<--units-cast> + +Units of thresholds for communication types (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'counter'). =item B<--nagvis-perfdata> @@ -506,10 +511,6 @@ Set interface speed for incoming traffic (in Mb). Set interface speed for outgoing traffic (in Mb). -=item B<--no-skipped-counters> - -Don't skip counters when no change. - =item B<--reload-cache-time> Time in minutes before reloading cache file (default: 180). diff --git a/centreon-plugins/snmp_standard/mode/interfaces.pm b/centreon-plugins/snmp_standard/mode/interfaces.pm index 4bcc97590..8538d113d 100644 --- a/centreon-plugins/snmp_standard/mode/interfaces.pm +++ b/centreon-plugins/snmp_standard/mode/interfaces.pm @@ -80,6 +80,64 @@ sub custom_status_calc { return 0; } +############### +# Cast +sub custom_cast_perfdata { + my ($self, %options) = @_; + + if ($self->{instance_mode}->{option_results}->{units_cast} =~ /percent/) { + my $nlabel = $self->{nlabel}; + $nlabel =~ s/count$/percentage/; + $self->{output}->perfdata_add( + force_new_perfdata => 1, + nlabel => $nlabel, + instances => $self->{result_values}->{display}, + value => sprintf('%.2f', $self->{result_values}->{prct}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), + unit => '%', + min => 0, + max => 100 + ); + } else { + $self->{output}->perfdata_add( + force_new_perfdata => 1, + nlabel => $self->{nlabel}, + instances => $self->{result_values}->{display}, + value => $self->{result_values}->{used}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), + min => 0, + max => $self->{result_values}->{total} + ); + } +} + +sub custom_cast_threshold { + my ($self, %options) = @_; + + my $exit = 'ok'; + if ($self->{instance_mode}->{option_results}->{units_cast} =~ /percent/) { + $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' } ]); + } else { + $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{used}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); + } + return $exit; +} + +sub custom_cast_output { + my ($self, %options) = @_; + + return sprintf( + '%s %s : %.2f%% (%s on %s)', + $self->{result_values}->{cast_going} eq 'i' ? 'In' : 'Out', + ucfirst($self->{result_values}->{cast_test}), + $self->{result_values}->{prct}, + $self->{result_values}->{used}, + $self->{result_values}->{total} + ); +} + sub custom_cast_calc { my ($self, %options) = @_; @@ -89,18 +147,36 @@ sub custom_cast_calc { return -2; } - 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}}); + my $cast_diff = ($options{new_datas}->{ $self->{instance} . '_' . $options{extra_options}->{cast_going} . $options{extra_options}->{cast_test} } - + $options{old_datas}->{ $self->{instance} . '_' . $options{extra_options}->{cast_going} . $options{extra_options}->{cast_test} }); + my $total_diff = + ($options{new_datas}->{ $self->{instance} . '_' . $options{extra_options}->{cast_going} . 'ucast' } - $options{old_datas}->{ $self->{instance} . '_' . $options{extra_options}->{cast_going} . 'ucast' }) + + ($options{new_datas}->{ $self->{instance} . '_' . $options{extra_options}->{cast_going} . 'bcast' } - $options{old_datas}->{ $self->{instance} . '_' . $options{extra_options}->{cast_going} . 'bcast' }) + + ($options{new_datas}->{ $self->{instance} . '_' . $options{extra_options}->{cast_going} . 'mcast' } - $options{old_datas}->{ $self->{instance} . '_' . $options{extra_options}->{cast_going} . 'mcast' }); + my $cast = $options{new_datas}->{ $self->{instance} . '_' . $options{extra_options}->{cast_going} . $options{extra_options}->{cast_test} }; + my $total = + $options{new_datas}->{ $self->{instance} . '_' . $options{extra_options}->{cast_going} . 'ucast' } + + $options{new_datas}->{ $self->{instance} . '_' . $options{extra_options}->{cast_going} . 'bcast' } + + $options{new_datas}->{ $self->{instance} . '_' . $options{extra_options}->{cast_going} . 'mcast' }; - if ($total == 0 && !defined($self->{instance_mode}->{option_results}->{no_skipped_counters})) { - $self->{error_msg} = "skipped"; - return -2; + $self->{result_values}->{prct} = 0; + $self->{result_values}->{used} = $cast_diff; + $self->{result_values}->{total} = $total_diff; + if ($self->{instance_mode}->{option_results}->{units_cast} eq 'percent_delta') { + $self->{result_values}->{prct} = $cast_diff * 100 / $total_diff if ($total_diff > 0); + } elsif ($self->{instance_mode}->{option_results}->{units_cast} eq 'percent') { + $self->{result_values}->{prct} = $cast * 100 / $total if ($total > 0); + $self->{result_values}->{used} = $cast; + } elsif ($self->{instance_mode}->{option_results}->{units_cast} eq 'delta') { + $self->{result_values}->{used} = $cast_diff; + } else { + $self->{result_values}->{used} = $cast; + $self->{result_values}->{total} = $total; } + $self->{result_values}->{cast_going} = $options{extra_options}->{cast_going}; + $self->{result_values}->{cast_test} = $options{extra_options}->{cast_test}; + $self->{result_values}->{display} = $options{new_datas}->{ $self->{instance} . '_display' }; - $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; } @@ -115,12 +191,12 @@ sub custom_traffic_perfdata { } my ($warning, $critical); - if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { - $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1); - $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1); - } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') { - $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}); - $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}); + if ($self->{instance_mode}->{option_results}->{units_traffic} eq 'percent_delta' && defined($self->{result_values}->{speed})) { + $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, total => $self->{result_values}->{speed}, cast_int => 1); + $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, total => $self->{result_values}->{speed}, cast_int => 1); + } elsif ($self->{instance_mode}->{option_results}->{units_traffic} =~ /bps|counter/) { + $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}); + $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}); } if (defined($self->{instance_mode}->{option_results}->{nagvis_perfdata})) { @@ -132,6 +208,19 @@ sub custom_traffic_perfdata { critical => $critical, min => 0, max => $self->{result_values}->{speed} ); + } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'counter') { + my $nlabel = $self->{nlabel}; + $nlabel =~ s/bitspersecond/bits/; + $self->{output}->perfdata_add( + force_new_perfdata => 1, + nlabel => $nlabel, + unit => 'b', + instances => $self->{result_values}->{display}, + value => $self->{result_values}->{traffic_counter}, + warning => $warning, + critical => $critical, + min => 0 + ); } else { $self->{output}->perfdata_add( label => 'traffic_' . $self->{result_values}->{label}, unit => 'b/s', @@ -149,10 +238,12 @@ sub custom_traffic_threshold { my ($self, %options) = @_; my $exit = 'ok'; - if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { + if ($self->{instance_mode}->{option_results}->{units_traffic} eq 'percent_delta' && defined($self->{result_values}->{speed})) { $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_prct}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); - } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') { + } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'bps') { $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_per_seconds}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); + } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'counter') { + $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_counter}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); } return $exit; } @@ -164,7 +255,7 @@ sub custom_traffic_output { 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}) : '-' + defined($self->{result_values}->{traffic_prct}) ? sprintf('%.2f%%', $self->{result_values}->{traffic_prct}) : '-' ); } @@ -176,14 +267,10 @@ sub custom_traffic_calc { $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'; - 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} }); $self->{result_values}->{traffic_per_seconds} = $diff_traffic / $options{delta_time}; + $self->{result_values}->{traffic_counter} = $options{new_datas}->{ $self->{instance} . '_' . $options{extra_options}->{label_ref} }; if (defined($options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}}) && $options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}} > 0) { $self->{result_values}->{traffic_prct} = $self->{result_values}->{traffic_per_seconds} * 100 / $options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}}; @@ -191,7 +278,7 @@ sub custom_traffic_calc { } $self->{result_values}->{label} = $options{extra_options}->{label_ref}; - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{display} = $options{new_datas}->{ $self->{instance} . '_display' }; return 0; } @@ -200,17 +287,19 @@ sub custom_traffic_calc { sub custom_errors_perfdata { my ($self, %options) = @_; - if ($self->{instance_mode}->{option_results}->{units_errors} eq '%') { + if ($self->{instance_mode}->{option_results}->{units_errors} =~ /percent/) { my $nlabel = $self->{nlabel}; $nlabel =~ s/count$/percentage/; $self->{output}->perfdata_add( - label => 'packets_' . $self->{result_values}->{label2} . '_' . $self->{result_values}->{label1}, unit => '%', + label => 'packets_' . $self->{result_values}->{label2} . '_' . $self->{result_values}->{label1}, + unit => '%', nlabel => $nlabel, instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, - value => sprintf("%.2f", $self->{result_values}->{prct}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}), - min => 0, max => 100 + value => sprintf('%.2f', $self->{result_values}->{prct}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), + min => 0, + max => 100 ); } else { $self->{output}->perfdata_add( @@ -218,9 +307,10 @@ sub custom_errors_perfdata { nlabel => $self->{nlabel}, instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, value => $self->{result_values}->{used}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}), - min => 0, max => $self->{result_values}->{total} + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), + min => 0, + max => $self->{result_values}->{total} ); } } @@ -229,7 +319,7 @@ sub custom_errors_threshold { my ($self, %options) = @_; my $exit = 'ok'; - if ($self->{instance_mode}->{option_results}->{units_errors} eq '%') { + if ($self->{instance_mode}->{option_results}->{units_errors} =~ /percent/) { $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' } ]); } else { $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{used}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); @@ -241,9 +331,11 @@ sub custom_errors_output { my ($self, %options) = @_; return sprintf( - 'Packets %s : %.2f%% (%s)', + 'Packets %s : %.2f%% (%s on %s)', $self->{result_values}->{label}, - $self->{result_values}->{prct}, $self->{result_values}->{used} + $self->{result_values}->{prct}, + $self->{result_values}->{used}, + $self->{result_values}->{total} ); } @@ -256,18 +348,28 @@ sub custom_errors_calc { 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'} - + my $errors = $options{new_datas}->{ $self->{instance} . '_' . $options{extra_options}->{label_ref1} . $options{extra_options}->{label_ref2} }; + my $errors_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'}; + my $total_diff = ($options{new_datas}->{$self->{instance} . '_total_' . $options{extra_options}->{label_ref1} . '_packets'} - $options{old_datas}->{$self->{instance} . '_total_' . $options{extra_options}->{label_ref1} . '_packets'}); - if ($total == 0 && !defined($self->{instance_mode}->{option_results}->{no_skipped_counters})) { - $self->{error_msg} = "skipped"; - return -2; + + $self->{result_values}->{prct} = 0; + $self->{result_values}->{used} = $errors_diff; + $self->{result_values}->{total} = $total_diff; + if ($self->{instance_mode}->{option_results}->{units_errors} eq 'percent_delta') { + $self->{result_values}->{prct} = $errors_diff * 100 / $total_diff if ($total_diff > 0); + } elsif ($self->{instance_mode}->{option_results}->{units_errors} eq 'percent') { + $self->{result_values}->{prct} = $errors * 100 / $total if ($total > 0); + $self->{result_values}->{used} = $errors; + } elsif ($self->{instance_mode}->{option_results}->{units_errors} eq 'delta') { + $self->{result_values}->{used} = $errors_diff; + } else { + $self->{result_values}->{used} = $errors; + $self->{result_values}->{total} = $total; } - $self->{result_values}->{prct} = $total == 0 ? 0 : $diff * 100 / $total; - $self->{result_values}->{used} = $diff; - $self->{result_values}->{total} = $total; if (defined($options{extra_options}->{label})) { $self->{result_values}->{label} = $options{extra_options}->{label}; } else { @@ -433,68 +535,56 @@ sub set_counters_cast { push @{$self->{maps_counters}->{int}}, { label => 'in-ucast', filter => 'add_cast', nlabel => 'interface.packets.in.unicast.count', set => { key_values => [ { name => 'iucast', diff => 1 }, { name => 'imcast', diff => 1 }, { name => 'ibcast', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ], - closure_custom_calc => \&custom_cast_calc, closure_custom_calc_extra_options => { label_ref => 'iucast', total_ref1 => 'ibcast', total_ref2 => 'imcast' }, - output_template => 'In Ucast : %.2f %%', output_error_template => 'In Ucast : %s', - 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' } - ] + closure_custom_calc => $self->can('custom_cast_calc'), + closure_custom_calc_extra_options => { cast_going => 'i', cast_test => 'ucast' }, + closure_custom_output => $self->can('custom_cast_output'), output_error_template => 'In Ucast : %s', + closure_custom_perfdata => $self->can('custom_cast_perfdata'), + closure_custom_threshold_check => $self->can('custom_cast_threshold') } }, { label => 'in-bcast', filter => 'add_cast', nlabel => 'interface.packets.in.broadcast.count', set => { key_values => [ { name => 'iucast', diff => 1 }, { name => 'imcast', diff => 1 }, { name => 'ibcast', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ], - closure_custom_calc => \&custom_cast_calc, closure_custom_calc_extra_options => { label_ref => 'ibcast', total_ref1 => 'iucast', total_ref2 => 'imcast' }, - output_template => 'In Bcast : %.2f %%', output_error_template => 'In Bcast : %s', - 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' } - ] + closure_custom_calc => $self->can('custom_cast_calc'), + closure_custom_calc_extra_options => { cast_going => 'i', cast_test => 'bcast' }, + closure_custom_output => $self->can('custom_cast_output'), output_error_template => 'In Bcast : %s', + closure_custom_perfdata => $self->can('custom_cast_perfdata'), + closure_custom_threshold_check => $self->can('custom_cast_threshold') } }, { label => 'in-mcast', filter => 'add_cast', nlabel => 'interface.packets.in.multicast.count', set => { key_values => [ { name => 'iucast', diff => 1 }, { name => 'imcast', diff => 1 }, { name => 'ibcast', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ], - closure_custom_calc => \&custom_cast_calc, closure_custom_calc_extra_options => { label_ref => 'imcast', total_ref1 => 'iucast', total_ref2 => 'ibcast' }, - output_template => 'In Mcast : %.2f %%', output_error_template => 'In Mcast : %s', - 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' } - ] + closure_custom_calc => $self->can('custom_cast_calc'), + closure_custom_calc_extra_options => { cast_going => 'i', cast_test => 'mcast' }, + closure_custom_output => $self->can('custom_cast_output'), output_error_template => 'In Mcast : %s', + closure_custom_perfdata => $self->can('custom_cast_perfdata'), + closure_custom_threshold_check => $self->can('custom_cast_threshold') } }, { label => 'out-ucast', filter => 'add_cast', nlabel => 'interface.packets.out.unicast.count', set => { key_values => [ { name => 'oucast', diff => 1 }, { name => 'omcast', diff => 1 }, { name => 'obcast', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ], - closure_custom_calc => \&custom_cast_calc, closure_custom_calc_extra_options => { label_ref => 'oucast', total_ref1 => 'omcast', total_ref2 => 'obcast' }, - output_template => 'Out Ucast : %.2f %%', output_error_template => 'Out Ucast : %s', - 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' } - ] + closure_custom_calc => $self->can('custom_cast_calc'), + closure_custom_calc_extra_options => { cast_going => 'o', cast_test => 'ucast' }, + closure_custom_output => $self->can('custom_cast_output'), output_error_template => 'Out Ucast : %s', + closure_custom_perfdata => $self->can('custom_cast_perfdata'), + closure_custom_threshold_check => $self->can('custom_cast_threshold') } }, { label => 'out-bcast', filter => 'add_cast', nlabel => 'interface.packets.out.broadcast.count', set => { key_values => [ { name => 'oucast', diff => 1 }, { name => 'omcast', diff => 1 }, { name => 'obcast', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ], - closure_custom_calc => \&custom_cast_calc, closure_custom_calc_extra_options => { label_ref => 'obcast', total_ref1 => 'omcast', total_ref2 => 'oucast' }, - output_template => 'Out Bcast : %.2f %%', output_error_template => 'Out Bcast : %s', - 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' } - ] + closure_custom_calc => $self->can('custom_cast_calc'), + closure_custom_calc_extra_options => { cast_going => 'o', cast_test => 'bcast' }, + closure_custom_output => $self->can('custom_cast_output'), output_error_template => 'Out Bcast : %s', + closure_custom_perfdata => $self->can('custom_cast_perfdata'), + closure_custom_threshold_check => $self->can('custom_cast_threshold') } }, { label => 'out-mcast', filter => 'add_cast', nlabel => 'interface.packets.out.multicast.count', set => { key_values => [ { name => 'oucast', diff => 1 }, { name => 'omcast', diff => 1 }, { name => 'obcast', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ], - closure_custom_calc => \&custom_cast_calc, closure_custom_calc_extra_options => { label_ref => 'omcast', total_ref1 => 'oucast', total_ref2 => 'obcast' }, - output_template => 'Out Mcast : %.2f %%', output_error_template => 'Out Mcast : %s', - 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' } - ] + closure_custom_calc => $self->can('custom_cast_calc'), + closure_custom_calc_extra_options => { cast_going => 'o', cast_test => 'mcast' }, + closure_custom_output => $self->can('custom_cast_output'), output_error_template => 'Out Mcast : %s', + closure_custom_perfdata => $self->can('custom_cast_perfdata'), + closure_custom_threshold_check => $self->can('custom_cast_threshold') } } ; @@ -791,12 +881,13 @@ sub new { 'global-admin-down-rule:s' => { name => 'global_admin_down_rule', default => $self->default_global_admin_down_rule() }, 'global-oper-down-rule:s' => { name => 'global_oper_down_rule', default => $self->default_global_oper_down_rule() }, 'interface:s' => { name => 'interface' }, - 'units-traffic:s' => { name => 'units_traffic', default => '%' }, - 'units-errors:s' => { name => 'units_errors', default => '%' }, + 'units-traffic:s' => { name => 'units_traffic', default => 'percent_delta' }, + 'units-errors:s' => { name => 'units_errors', default => 'percent_delta' }, + 'units-cast:s' => { name => 'units_cast', default => 'percent_delta' }, 'speed:s' => { name => 'speed' }, 'speed-in:s' => { name => 'speed_in' }, 'speed-out:s' => { name => 'speed_out' }, - 'no-skipped-counters' => { name => 'no_skipped_counters' }, + 'no-skipped-counters' => { name => 'no_skipped_counters' }, # legacy 'display-transform-src:s' => { name => 'display_transform_src' }, 'display-transform-dst:s' => { name => 'display_transform_dst' }, 'show-cache' => { name => 'show_cache' }, @@ -847,16 +938,35 @@ sub check_options { $self->check_oids_label(); $self->{statefile_cache}->check_options(%options); - - if (defined($self->{option_results}->{add_traffic}) && - (!defined($self->{option_results}->{units_traffic}) || $self->{option_results}->{units_traffic} !~ /^(%|b\/s)$/)) { - $self->{output}->add_option_msg(short_msg => 'Wrong option --units-traffic.'); - $self->{output}->option_exit(); + if (defined($self->{option_results}->{add_traffic})) { + $self->{option_results}->{units_traffic} = 'percent_delta' + if (!defined($self->{option_results}->{units_traffic}) || + $self->{option_results}->{units_traffic} eq '' || + $self->{option_results}->{units_traffic} eq '%'); + $self->{option_results}->{units_traffic} = 'bps' if ($self->{option_results}->{units_traffic} eq 'absolute'); # compat + if ($self->{option_results}->{units_traffic} !~ /^(?:percent_delta|bps|counter)$/) { + $self->{output}->add_option_msg(short_msg => 'Wrong option --units-traffic.'); + $self->{output}->option_exit(); + } } - if (defined($self->{option_results}->{add_errors}) && - (!defined($self->{option_results}->{units_errors}) || $self->{option_results}->{units_errors} !~ /^(%|absolute|b\/s)$/)) { - $self->{output}->add_option_msg(short_msg => 'Wrong option --units-errors.'); - $self->{output}->option_exit(); + if (defined($self->{option_results}->{add_errors})) { + $self->{option_results}->{units_errors} = 'percent_delta' + if (!defined($self->{option_results}->{units_errors}) || + $self->{option_results}->{units_errors} eq '' || + $self->{option_results}->{units_errors} eq '%'); + $self->{option_results}->{units_errors} = 'delta' if ($self->{option_results}->{units_errors} eq 'absolute'); # compat + if ($self->{option_results}->{units_errors} !~ /^(?:percent|percent_delta|delta|counter)$/) { + $self->{output}->add_option_msg(short_msg => 'Wrong option --units-errors.'); + $self->{output}->option_exit(); + } + } + if (defined($self->{option_results}->{add_cast})) { + $self->{option_results}->{units_cast} = 'percent_delta' + if (!defined($self->{option_results}->{units_cast}) || $self->{option_results}->{units_cast} eq ''); + if ($self->{option_results}->{units_cast} !~ /^(?:percent|percent_delta|delta|counter)$/) { + $self->{output}->add_option_msg(short_msg => 'Wrong option --units-cast.'); + $self->{output}->option_exit(); + } } $self->{get_speed} = 0; @@ -1483,29 +1593,25 @@ Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{d 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-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. +Thresholds. 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' (%), +'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'). +Units of thresholds for the traffic (Default: 'percent_delta') ('percent_delta', 'bps', 'counter'). =item B<--units-errors> -Units of thresholds for errors/discards (Default: '%') ('%', 'absolute'). +Units of thresholds for errors/discards (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'counter'). + +=item B<--units-cast> + +Units of thresholds for communication types (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'counter'). =item B<--nagvis-perfdata> @@ -1539,10 +1645,6 @@ Syntax: --map-speed-dsl=interface-src-name,interface-dsl-name E.g: --map-speed-dsl=Et0.835,Et0-vdsl2 -=item B<--no-skipped-counters> - -Don't skip counters when no change. - =item B<--force-counters64> Force to use 64 bits counters only. Can be used to improve performance. diff --git a/centreon-plugins/storage/lenovo/iomega/snmp/mode/interfaces.pm b/centreon-plugins/storage/lenovo/iomega/snmp/mode/interfaces.pm index 57a91f69f..6ef4f89b1 100644 --- a/centreon-plugins/storage/lenovo/iomega/snmp/mode/interfaces.pm +++ b/centreon-plugins/storage/lenovo/iomega/snmp/mode/interfaces.pm @@ -98,29 +98,25 @@ Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{d 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-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. +Thresholds. 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' (%), +'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'). +Units of thresholds for the traffic (Default: 'percent_delta') ('percent_delta', 'bps', 'counter'). =item B<--units-errors> -Units of thresholds for errors/discards (Default: '%') ('%', 'absolute'). +Units of thresholds for errors/discards (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'counter'). + +=item B<--units-cast> + +Units of thresholds for communication types (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'counter'). =item B<--nagvis-perfdata> @@ -146,10 +142,6 @@ Set interface speed for incoming traffic (in Mb). 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.