11#
2- # Copyright 2024 Centreon (http://www.centreon.com/)
2+ # Copyright 2026-Present Centreon (http://www.centreon.com/)
33#
44# Centreon is a full-fledged industry-strength solution that meets
55# the needs in IT infrastructure and application monitoring for
@@ -25,21 +25,23 @@ use base qw(centreon::plugins::templates::counter);
2525use strict;
2626use warnings;
2727use centreon::plugins::templates::catalog_functions qw( catalog_status_threshold_ng) ;
28- use Digest::MD5 qw( md5_hex) ;
28+ use centreon::plugins::constants qw/ :counters :values/ ;
29+ use Digest::SHA qw( sha256_hex) ;
30+ use centreon::plugins::misc qw/ is_excluded/ ;
2931
3032sub custom_traffic_perfdata {
3133 my ($self , %options ) = @_ ;
3234
3335 my ($warning , $critical );
34- if ($self -> {instance_mode }-> {option_results }-> {units_traffic } eq ' %' && defined ( $self -> {result_values }-> {speed }) && $self -> { result_values } -> { speed } > 0 ) {
36+ if ($self -> {instance_mode }-> {option_results }-> {units_traffic } eq ' %' && $self -> {result_values }-> {speed }) {
3537 $warning = $self -> {perfdata }-> get_perfdata_for_output(label => ' warning-' . $self -> {thlabel }, total => $self -> {result_values }-> {speed }, cast_int => 1);
3638 $critical = $self -> {perfdata }-> get_perfdata_for_output(label => ' critical-' . $self -> {thlabel }, total => $self -> {result_values }-> {speed }, cast_int => 1);
3739 } elsif ($self -> {instance_mode }-> {option_results }-> {units_traffic } eq ' b/s' ) {
3840 $warning = $self -> {perfdata }-> get_perfdata_for_output(label => ' warning-' . $self -> {thlabel });
3941 $critical = $self -> {perfdata }-> get_perfdata_for_output(label => ' critical-' . $self -> {thlabel });
4042 }
4143
42- my $speed = $self -> {result_values }-> {speed } > 0 ? $self -> { result_values } -> { speed } : undef ;
44+ my $speed = $self -> {result_values }-> {speed } || undef ;
4345
4446 $self -> {output }-> perfdata_add(
4547 nlabel => $self -> {nlabel },
@@ -56,7 +58,7 @@ sub custom_traffic_threshold {
5658 my ($self , %options ) = @_ ;
5759
5860 my $exit = ' ok' ;
59- if ($self -> {instance_mode }-> {option_results }-> {units_traffic } eq ' %' && defined ( $self -> {result_values }-> {speed }) && $self -> { result_values } -> { speed } > 0 ) {
61+ if ($self -> {instance_mode }-> {option_results }-> {units_traffic } eq ' %' && $self -> {result_values }-> {speed }) {
6062 $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' } ]);
6163 } elsif ($self -> {instance_mode }-> {option_results }-> {units_traffic } eq ' b/s' ) {
6264 $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' } ]);
@@ -81,7 +83,7 @@ sub custom_traffic_calc {
8183
8284 if (!defined ($options {old_datas }-> {$self -> {instance } . ' _' . $options {extra_options }-> {label_ref }})) {
8385 $self -> {error_msg } = " buffer creation" ;
84- return -2 ;
86+ return NOT_PROCESSED ;
8587 }
8688
8789 my $diff_traffic = ($options {new_datas }-> {$self -> {instance } . ' _' . $options {extra_options }-> {label_ref }} - $options {old_datas }-> {$self -> {instance } . ' _' . $options {extra_options }-> {label_ref }});
@@ -218,17 +220,17 @@ sub set_counters {
218220
219221 $self -> {maps_counters_type } = [
220222 {
221- name => ' trunks' , type => 3 , cb_prefix_output => ' prefix_trunk_output' , cb_long_output => ' port_trunk_output' , indent_long_output => ' ' , message_multiple => ' All trunks are ok' ,
223+ name => ' trunks' , type => COUNTER_TYPE_MULTIPLE , cb_prefix_output => ' prefix_trunk_output' , cb_long_output => ' port_trunk_output' , indent_long_output => ' ' , message_multiple => ' All trunks are ok' ,
222224 group => [
223- { name => ' trunk_global' , type => 0, skipped_code => { - 10 => 1 } },
224- { name => ' interfaces' , display_long => 1, cb_prefix_output => ' prefix_interface_output' , message_multiple => ' All interfaces are ok' , type => 1, skipped_code => { - 10 => 1 } }
225+ { name => ' trunk_global' , type => 0, skipped_code => { NO_VALUE() => 1 } },
226+ { name => ' interfaces' , display_long => 1, cb_prefix_output => ' prefix_interface_output' , message_multiple => ' All interfaces are ok' , type => 1, skipped_code => { NO_VALUE() => 1 } }
225227 ]
226228 }
227229 ];
228230
229231 $self -> {maps_counters }-> {trunk_global } = [
230232 {
231- label => ' status' , type => 2 , critical_default => ' %{status} =~ /uninitialized|down/' ,
233+ label => ' status' , type => COUNTER_KIND_TEXT , critical_default => ' %{status} =~ /uninitialized|down/' ,
232234 set => {
233235 key_values => [ { name => ' status' }, { name => ' display' } ],
234236 output_template => " status is '%s '" , output_error_template => ' status: %s' ,
@@ -317,7 +319,7 @@ sub new {
317319 bless $self , $class ;
318320
319321 $options {options }-> add_options(arguments => {
320- ' filter-name:s' => { name => ' filter_name' },
322+ ' filter-name:s' => { name => ' filter_name' , default => ' ' },
321323 ' units-traffic:s' => { name => ' units_traffic' , default => ' %' },
322324 ' speed:s' => { name => ' speed' },
323325 ' add-interfaces' => { name => ' add_interfaces' }
@@ -400,18 +402,14 @@ sub manage_selection {
400402 }
401403
402404 my $oid_sysTrunkName = ' .1.3.6.1.4.1.3375.2.1.2.12.1.2.1.1' ;
403- my $snmp_result = $options {snmp }-> get_table(oid => $oid_sysTrunkName , nothing_quit => 1 );
405+ my $snmp_result = $options {snmp }-> get_table(oid => $oid_sysTrunkName , nothing_quit => 0 );
404406
405407 $self -> {trunks } = {};
406408 foreach (keys %$snmp_result ) {
407409 / ^$oid_sysTrunkName \. (.*)$ / ;
408410 my $instance = $1 ;
409411
410- if (defined ($self -> {option_results }-> {filter_name }) && $self -> {option_results }-> {filter_name } ne ' ' &&
411- $snmp_result -> {$_ } !~ / $self ->{option_results}->{filter_name}/ ) {
412- $self -> {output }-> output_add(long_msg => " skipping trunk '" . $snmp_result -> {$_ } . " '." , debug => 1);
413- next ;
414- }
412+ next if is_excluded($snmp_result -> {$_ }, $self -> {option_results }-> {filter_name }, undef , output => $self -> {output });
415413
416414 $self -> {trunks }-> { $snmp_result -> {$_ } } = {
417415 display => $snmp_result -> {$_ },
@@ -420,10 +418,8 @@ sub manage_selection {
420418 };
421419 }
422420
423- if (scalar (keys %{$self -> {trunks }}) <= 0) {
424- $self -> {output }-> add_option_msg(short_msg => ' No trunk found.' );
425- $self -> {output }-> option_exit();
426- }
421+ $self -> {output }-> option_exit(short_msg => ' No trunk found.' )
422+ unless keys %{$self -> {trunks }};
427423
428424 $options {snmp }-> load(oids => [
429425 map ($_ -> {oid }, values (%$mapping ))
@@ -444,8 +440,7 @@ sub manage_selection {
444440 $self -> add_interfaces(snmp => $options {snmp }) if (defined ($self -> {option_results }-> {add_interfaces }));
445441
446442 $self -> {cache_name } = ' f5_bipgip_' . $options {snmp }-> get_hostname() . ' _' . $options {snmp }-> get_port() . ' _' . $self -> {mode } . ' _' .
447- (defined ($self -> {option_results }-> {filter_name }) ? md5_hex($self -> {option_results }-> {filter_name }) : md5_hex(' all' )) . ' _' .
448- (defined ($self -> {option_results }-> {filter_counters }) ? md5_hex($self -> {option_results }-> {filter_counters }) : md5_hex(' all' ));
443+ sha256_hex(($self -> {option_results }-> {filter_name } eq ' ' ? ' all' : $self -> {option_results }-> {filter_name }) . ' _' . ($self -> {option_results }-> {filter_counters } // ' all' ));
449444}
450445
4514461;
0 commit comments