Skip to content

Commit 3cf69d8

Browse files
authored
enh(network::f5::bigip::snmp) Mode(trunks): check return unknown status if no trunk is configured (#6120)
Refs: CTOR-2013
1 parent 3b3d151 commit 3cf69d8

2 files changed

Lines changed: 44 additions & 30 deletions

File tree

src/network/f5/bigip/snmp/mode/trunks.pm

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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);
2525
use strict;
2626
use warnings;
2727
use 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

3032
sub 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

451446
1;

tests/network/f5/bigip/snmp/trunks.robot

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,29 @@ trunks ${tc}
2424

2525
Ctn Verify Command Without Connector Output ${command} ${expected_result}
2626

27-
Examples: tc extra_options expected_result --
28-
... 1 ${EMPTY} OK: Trunk 'Anonymized 234' status is 'up', traffic in: Buffer creation, traffic out: Buffer creation, packets in error: Buffer creation, packets out error: Buffer creation, packets in drop: Buffer creation, packets out drop: Buffer creation
29-
... 2 --filter-name='Anonymized 234' OK: Trunk 'Anonymized 234' status is 'up', traffic in: Buffer creation, traffic out: Buffer creation, packets in error: Buffer creation, packets out error: Buffer creation, packets in drop: Buffer creation, packets out drop: Buffer creation
30-
... 3 --warning-status='\\\%{status} eq "up"' WARNING: Trunk 'Anonymized 234' status is 'up' | 'Anonymized 234#trunk.traffic.in.bitspersecond'=0.00b/s;;;0;20000000000 'Anonymized 234#trunk.traffic.out.bitspersecond'=0.00b/s;;;0;20000000000 'Anonymized 234#trunk.packets.in.error.percentage'=0.00%;;;0;100
31-
... 4 --critical-status='\\\%{status} eq "up"' CRITICAL: Trunk 'Anonymized 234' status is 'up' | 'Anonymized 234#trunk.traffic.in.bitspersecond'=0.00b/s;;;0;20000000000 'Anonymized 234#trunk.traffic.out.bitspersecond'=0.00b/s;;;0;20000000000 'Anonymized 234#trunk.packets.in.error.percentage'=0.00%;;;0;100
32-
... 5 --unknown-status='\\\%{status} eq "up"' UNKNOWN: Trunk 'Anonymized 234' status is 'up' | 'Anonymized 234#trunk.traffic.in.bitspersecond'=0.00b/s;;;0;20000000000 'Anonymized 234#trunk.traffic.out.bitspersecond'=0.00b/s;;;0;20000000000 'Anonymized 234#trunk.packets.in.error.percentage'=0.00%;;;0;100
33-
... 6 --warning-packets-error-in=50 --critical-packets-error-in=100 OK: Trunk 'Anonymized 234' status is 'up', traffic in: 0.00b/s (0.00%), traffic out: 0.00b/s (0.00%), packets in error: 0.00%, packets out error: 0.00%,
27+
Examples:
28+
... tc
29+
... extra_options
30+
... expected_result
31+
... --
32+
... 1
33+
... ${EMPTY}
34+
... OK: Trunk 'Anonymized 234' status is 'up', traffic in: Buffer creation, traffic out: Buffer creation, packets in error: Buffer creation, packets out error: Buffer creation, packets in drop: Buffer creation, packets out drop: Buffer creation
35+
... 2
36+
... --filter-name='Anonymized 234'
37+
... OK: Trunk 'Anonymized 234' status is 'up', traffic in: Buffer creation, traffic out: Buffer creation, packets in error: Buffer creation, packets out error: Buffer creation, packets in drop: Buffer creation, packets out drop: Buffer creation
38+
... 3
39+
... --warning-status='\\\%{status} eq "up"'
40+
... WARNING: Trunk 'Anonymized 234' status is 'up' | 'Anonymized 234#trunk.traffic.in.bitspersecond'=0.00b/s;;;0;20000000000 'Anonymized 234#trunk.traffic.out.bitspersecond'=0.00b/s;;;0;20000000000 'Anonymized 234#trunk.packets.in.error.percentage'=0.00%;;;0;100
41+
... 4
42+
... --critical-status='\\\%{status} eq "up"'
43+
... CRITICAL: Trunk 'Anonymized 234' status is 'up' | 'Anonymized 234#trunk.traffic.in.bitspersecond'=0.00b/s;;;0;20000000000 'Anonymized 234#trunk.traffic.out.bitspersecond'=0.00b/s;;;0;20000000000 'Anonymized 234#trunk.packets.in.error.percentage'=0.00%;;;0;100
44+
... 5
45+
... --unknown-status='\\\%{status} eq "up"'
46+
... UNKNOWN: Trunk 'Anonymized 234' status is 'up' | 'Anonymized 234#trunk.traffic.in.bitspersecond'=0.00b/s;;;0;20000000000 'Anonymized 234#trunk.traffic.out.bitspersecond'=0.00b/s;;;0;20000000000 'Anonymized 234#trunk.packets.in.error.percentage'=0.00%;;;0;100
47+
... 6
48+
... --warning-packets-error-in=50 --critical-packets-error-in=100
49+
... OK: Trunk 'Anonymized 234' status is 'up', traffic in: 0.00b/s (0.00%), traffic out: 0.00b/s (0.00%), packets in error: 0.00%, packets out error: 0.00%,
50+
... 7
51+
... --snmp-community=network/f5/bigip/snmp/cpu
52+
... UNKNOWN: No trunk found.

0 commit comments

Comments
 (0)