This commit is contained in:
garnier-quentin 2020-07-28 11:51:48 +02:00
parent 98ef916667
commit 59d909a1e2
1 changed files with 229 additions and 172 deletions

View File

@ -24,32 +24,9 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
use Digest::MD5 qw(md5_hex); use Digest::MD5 qw(md5_hex);
my $thresholds = {
trunk => [
['up', 'OK'],
['down', 'CRITICAL'],
['disable', 'CRITICAL'],
['uninitialized', 'CRITICAL'],
['loopback', 'OK'],
['unpopulated', 'OK'],
],
};
sub custom_threshold_output {
my ($self, %options) = @_;
return $self->{instance_mode}->get_severity(section => 'trunk', value => $self->{result_values}->{sysTrunkStatus});
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{sysTrunkStatus} = $options{new_datas}->{$self->{instance} . '_sysTrunkStatus'};
return 0;
}
sub custom_traffic_perfdata { sub custom_traffic_perfdata {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -90,10 +67,12 @@ sub custom_traffic_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my ($traffic_value, $traffic_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{traffic_per_seconds}, network => 1); 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)", return sprintf(
ucfirst($self->{result_values}->{label}), $traffic_value . $traffic_unit, "traffic %s: %s/s (%s)",
defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-'); $self->{result_values}->{label},
return $msg; $traffic_value . $traffic_unit,
defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-'
);
} }
sub custom_traffic_calc { sub custom_traffic_calc {
@ -134,18 +113,17 @@ sub custom_errors_perfdata {
sub custom_errors_threshold { sub custom_errors_threshold {
my ($self, %options) = @_; my ($self, %options) = @_;
my $exit = 'ok'; return $self->{perfdata}->threshold_check(value => $self->{result_values}->{errors_prct}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]);
$exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{errors_prct}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]);
return $exit;
} }
sub custom_errors_output { sub custom_errors_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = sprintf("Packets %s Error : %s", return sprintf(
ucfirst($self->{result_values}->{label}), defined($self->{result_values}->{errors_prct}) ? sprintf("%.2f%%", $self->{result_values}->{errors_prct}) : '-'); "packets %s error: %s",
return $msg; $self->{result_values}->{label},
defined($self->{result_values}->{errors_prct}) ? sprintf("%.2f%%", $self->{result_values}->{errors_prct}) : '-'
);
} }
sub custom_errors_calc { sub custom_errors_calc {
@ -184,18 +162,17 @@ sub custom_drops_perfdata {
sub custom_drops_threshold { sub custom_drops_threshold {
my ($self, %options) = @_; my ($self, %options) = @_;
my $exit = 'ok'; return $self->{perfdata}->threshold_check(value => $self->{result_values}->{drops_prct}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]);
$exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{drops_prct}, threshold => [ { label => 'critial-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]);
return $exit;
} }
sub custom_drops_output { sub custom_drops_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = sprintf("Packets %s Drop : %s", return sprintf(
ucfirst($self->{result_values}->{label}), defined($self->{result_values}->{drops_prct}) ? sprintf("%.2f%%", $self->{result_values}->{drops_prct}) : '-'); "packets %s drop: %s",
return $msg; $self->{result_values}->{label},
defined($self->{result_values}->{drops_prct}) ? sprintf("%.2f%%", $self->{result_values}->{drops_prct}) : '-'
);
} }
sub custom_drops_calc { sub custom_drops_calc {
@ -215,28 +192,50 @@ sub custom_drops_calc {
return 0; return 0;
} }
sub port_trunk_output {
my ($self, %options) = @_;
return "checking trunk '" . $options{instance_value}->{display} . "'";
}
sub prefix_trunk_output {
my ($self, %options) = @_;
return "Trunk '" . $options{instance_value}->{display} . "' ";
}
sub prefix_interface_output {
my ($self, %options) = @_;
return "interface '" . $options{instance_value}->{display} . "' ";
}
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'trunks', type => 1, cb_prefix_output => 'prefix_trunks_output', message_multiple => 'All trunks are ok', skipped_code => { -10 => 1 } }, {
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',
group => [
{ name => 'trunk_global', type => 0, skipped_code => { -10 => 1 } },
{ name => 'interfaces', display_long => 1, cb_prefix_output => 'prefix_interface_output', message_multiple => 'All interfaces are ok', type => 1, skipped_code => { -10 => 1 } }
]
}
]; ];
$self->{maps_counters}->{trunks} = [ $self->{maps_counters}->{trunk_global} = [
{ label => 'status', threshold => 0, set => { { label => 'status', threshold => 0, set => {
key_values => [ { name => 'sysTrunkStatus' } ], key_values => [ { name => 'status' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_status_calc'), output_template => "status is '%s'", output_error_template => 'status: %s',
output_template => "status is '%s'", output_error_template => 'Status : %s',
output_use => 'sysTrunkStatus',
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_threshold_output') closure_custom_threshold_check => \&catalog_status_threshold
} }
}, },
{ label => 'traffic-in', set => { { label => 'traffic-in', set => {
key_values => [ { name => 'sysTrunkStatBytesIn', diff => 1 }, { name => 'sysTrunkOperBw', diff => 1 }, { name => 'display' } ], key_values => [ { name => 'sysTrunkStatBytesIn', diff => 1 }, { name => 'sysTrunkOperBw', diff => 1 }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc => $self->can('custom_traffic_calc'),
closure_custom_calc_extra_options => { label_ref => 'sysTrunkStatBytesIn', speed => 'sysTrunkOperBw', label => 'in' }, closure_custom_calc_extra_options => { label_ref => 'sysTrunkStatBytesIn', speed => 'sysTrunkOperBw', label => 'in' },
closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic In : %s', closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'traffic in: %s',
closure_custom_perfdata => $self->can('custom_traffic_perfdata'), 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')
} }
@ -245,7 +244,7 @@ sub set_counters {
key_values => [ { name => 'sysTrunkStatBytesOut', diff => 1 }, { name => 'sysTrunkOperBw', diff => 1 }, { name => 'display' } ], key_values => [ { name => 'sysTrunkStatBytesOut', diff => 1 }, { name => 'sysTrunkOperBw', diff => 1 }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc => $self->can('custom_traffic_calc'),
closure_custom_calc_extra_options => { label_ref => 'sysTrunkStatBytesOut', speed => 'sysTrunkOperBw', label => 'out' }, closure_custom_calc_extra_options => { label_ref => 'sysTrunkStatBytesOut', speed => 'sysTrunkOperBw', label => 'out' },
closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic Out : %s', closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'traffic out: %s',
closure_custom_perfdata => $self->can('custom_traffic_perfdata'), 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')
} }
@ -254,7 +253,7 @@ sub set_counters {
key_values => [ { name => 'sysTrunkStatErrorsIn', diff => 1 }, { name => 'sysTrunkStatPktsIn', diff => 1 }, { name => 'display' } ], key_values => [ { name => 'sysTrunkStatErrorsIn', diff => 1 }, { name => 'sysTrunkStatPktsIn', diff => 1 }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc => $self->can('custom_errors_calc'),
closure_custom_calc_extra_options => { errors => 'sysTrunkStatErrorsIn', packets => 'sysTrunkStatPktsIn', label => 'in' }, closure_custom_calc_extra_options => { errors => 'sysTrunkStatErrorsIn', packets => 'sysTrunkStatPktsIn', label => 'in' },
closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets In Error : %s', closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'packets in error: %s',
closure_custom_perfdata => $self->can('custom_errors_perfdata'), closure_custom_perfdata => $self->can('custom_errors_perfdata'),
closure_custom_threshold_check => $self->can('custom_errors_threshold') closure_custom_threshold_check => $self->can('custom_errors_threshold')
} }
@ -263,7 +262,7 @@ sub set_counters {
key_values => [ { name => 'sysTrunkStatErrorsOut', diff => 1 }, { name => 'sysTrunkStatPktsOut', diff => 1 }, { name => 'display' } ], key_values => [ { name => 'sysTrunkStatErrorsOut', diff => 1 }, { name => 'sysTrunkStatPktsOut', diff => 1 }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc => $self->can('custom_errors_calc'),
closure_custom_calc_extra_options => { errors => 'sysTrunkStatErrorsOut', packets => 'sysTrunkStatPktsOut', label => 'out' }, closure_custom_calc_extra_options => { errors => 'sysTrunkStatErrorsOut', packets => 'sysTrunkStatPktsOut', label => 'out' },
closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets Out Error : %s', closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'packets out error: %s',
closure_custom_perfdata => $self->can('custom_errors_perfdata'), closure_custom_perfdata => $self->can('custom_errors_perfdata'),
closure_custom_threshold_check => $self->can('custom_errors_threshold') closure_custom_threshold_check => $self->can('custom_errors_threshold')
} }
@ -272,7 +271,7 @@ sub set_counters {
key_values => [ { name => 'sysTrunkStatDropsIn', diff => 1 }, { name => 'sysTrunkStatPktsIn', diff => 1 }, { name => 'display' } ], key_values => [ { name => 'sysTrunkStatDropsIn', diff => 1 }, { name => 'sysTrunkStatPktsIn', diff => 1 }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_drops_calc'), closure_custom_calc => $self->can('custom_drops_calc'),
closure_custom_calc_extra_options => { drops => 'sysTrunkStatDropsIn', packets => 'sysTrunkStatPktsIn', label => 'in' }, closure_custom_calc_extra_options => { drops => 'sysTrunkStatDropsIn', packets => 'sysTrunkStatPktsIn', label => 'in' },
closure_custom_output => $self->can('custom_drops_output'), output_error_template => 'Packets In Drop : %s', closure_custom_output => $self->can('custom_drops_output'), output_error_template => 'packets in drop: %s',
closure_custom_perfdata => $self->can('custom_drops_perfdata'), closure_custom_perfdata => $self->can('custom_drops_perfdata'),
closure_custom_threshold_check => $self->can('custom_drops_threshold') closure_custom_threshold_check => $self->can('custom_drops_threshold')
} }
@ -281,18 +280,30 @@ sub set_counters {
key_values => [ { name => 'sysTrunkStatDropsOut', diff => 1 }, { name => 'sysTrunkStatPktsOut', diff => 1 }, { name => 'display' } ], key_values => [ { name => 'sysTrunkStatDropsOut', diff => 1 }, { name => 'sysTrunkStatPktsOut', diff => 1 }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_drops_calc'), closure_custom_calc => $self->can('custom_drops_calc'),
closure_custom_calc_extra_options => { drops => 'sysTrunkStatDropsOut', packets => 'sysTrunkStatPktsOut', label => 'out' }, closure_custom_calc_extra_options => { drops => 'sysTrunkStatDropsOut', packets => 'sysTrunkStatPktsOut', label => 'out' },
closure_custom_output => $self->can('custom_drops_output'), output_error_template => 'Packets Out Drop : %s', closure_custom_output => $self->can('custom_drops_output'), output_error_template => 'packets out drop: %s',
closure_custom_perfdata => $self->can('custom_drops_perfdata'), closure_custom_perfdata => $self->can('custom_drops_perfdata'),
closure_custom_threshold_check => $self->can('custom_drops_threshold') closure_custom_threshold_check => $self->can('custom_drops_threshold')
} }
},
{ label => 'interfaces-total', nlabel => 'trunk.interfaces.total.count', display_ok => 0, set => {
key_values => [ { name => 'total_interfaces' }, { name => 'display' } ],
output_template => 'total interfaces: %s',
perfdatas => [
{ label => 'total_interfaces', template => '%d', min => 0, label_extra_instance => 1 }
]
}
} }
]; ];
}
sub prefix_trunks_output { $self->{maps_counters}->{interfaces} = [
my ($self, %options) = @_; { label => 'interface-status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'display' } ],
return "Trunk '" . $options{instance_value}->{display} . "' "; output_template => "status is '%s'",
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold
}
}
];
} }
sub new { sub new {
@ -302,9 +313,15 @@ sub new {
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' }, 'filter-name:s' => { name => 'filter_name' },
'threshold-overload:s@' => { name => 'threshold_overload' },
'units-traffic:s' => { name => 'units_traffic', default => '%' }, 'units-traffic:s' => { name => 'units_traffic', default => '%' },
'speed:s' => { name => 'speed' }, 'speed:s' => { name => 'speed' },
'unknown-status:s' => { name => 'unknown_status', default => '' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /uninitialized|down/' },
'unknown-interface-status:s' => { name => 'unknown_interface_status', default => '' },
'warning-interface-status:s' => { name => 'warning_interface_status', default => '' },
'critical-interface-status:s' => { name => 'critical_interface_status', default => '' },
'add-interfaces' => { name => 'add_interfaces' }
}); });
return $self; return $self;
@ -314,61 +331,37 @@ sub check_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->SUPER::check_options(%options); $self->SUPER::check_options(%options);
$self->{overload_th} = {}; $self->change_macros(macros => [
foreach my $val (@{$self->{option_results}->{threshold_overload}}) { 'unknown_status', 'warning_status', 'critical_status',
if ($val !~ /^(.*?),(.*?),(.*)$/) { 'unknown_interface_status', 'warning_interface_status', 'critical_interface_status'
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); ]);
$self->{output}->option_exit();
}
my ($section, $status, $filter) = ($1, $2, $3);
if ($self->{output}->is_litteral_status(status => $status) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'.");
$self->{output}->option_exit();
}
$self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section}));
push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status};
}
} }
sub get_severity { my $map_trunk_status = {
my ($self, %options) = @_;
my $status = 'UNKNOWN'; # default
if (defined($self->{overload_th}->{$options{section}})) {
foreach (@{$self->{overload_th}->{$options{section}}}) {
if ($options{value} =~ /$_->{filter}/i) {
$status = $_->{status};
return $status;
}
}
}
foreach (@{$thresholds->{$options{section}}}) {
if ($options{value} =~ /$$_[0]/i) {
$status = $$_[1];
return $status;
}
}
return $status;
}
my %map_trunk_status = (
0 => 'up', 0 => 'up',
1 => 'down', 1 => 'down',
2 => 'disable', 2 => 'disable',
3 => 'uninitialized', 3 => 'uninitialized',
4 => 'loopback', 4 => 'loopback',
5 => 'unpopulated', 5 => 'unpopulated'
); };
my $map_interface_status = {
my $mapping_sysTrunk = { 1 => 'up',
sysTrunkName => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.1.2.1.1' }, 2 => 'down',
sysTrunkStatus => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.1.2.1.2', map => \%map_trunk_status }, 3 => 'testing',
sysTrunkOperBw => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.1.2.1.5' }, 4 => 'unknown',
5 => 'dormant',
6 => 'notPresent',
7 => 'lowerLayerDown'
};
my $mapping_interface = {
display => { oid => '.1.3.6.1.2.1.2.2.1.2' }, # ifDescr
status => { oid => '.1.3.6.1.2.1.2.2.1.8', map => $map_interface_status } # ifOperStatus
}; };
my $oid_sysTrunkTable = '.1.3.6.1.4.1.3375.2.1.2.12.1.2';
my $mapping_sysTrunkStat = { my $mapping = {
status => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.1.2.1.2', map => $map_trunk_status }, # sysTrunkStatus
sysTrunkOperBw => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.1.2.1.5' },
sysTrunkStatPktsIn => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.2.3.1.2' }, sysTrunkStatPktsIn => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.2.3.1.2' },
sysTrunkStatBytesIn => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.2.3.1.3' }, # Bytes sysTrunkStatBytesIn => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.2.3.1.3' }, # Bytes
sysTrunkStatPktsOut => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.2.3.1.4' }, sysTrunkStatPktsOut => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.2.3.1.4' },
@ -376,51 +369,92 @@ my $mapping_sysTrunkStat = {
sysTrunkStatErrorsIn => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.2.3.1.8' }, sysTrunkStatErrorsIn => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.2.3.1.8' },
sysTrunkStatErrorsOut => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.2.3.1.9' }, sysTrunkStatErrorsOut => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.2.3.1.9' },
sysTrunkStatDropsIn => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.2.3.1.10' }, sysTrunkStatDropsIn => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.2.3.1.10' },
sysTrunkStatDropsOut => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.2.3.1.11' }, sysTrunkStatDropsOut => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.2.3.1.11' }
}; };
my $oid_sysTrunkStatTable = '.1.3.6.1.4.1.3375.2.1.2.12.2.3';
sub add_interfaces {
my ($self, %options) = @_;
my $interfaces = $options{snmp}->get_multiple_table(
oids => [ { oid => $mapping_interface->{display}->{oid} }, { oid => $mapping_interface->{status}->{oid} } ],
return_type => 1
);
my $oid_sysTrunkCfgMemberName = '.1.3.6.1.4.1.3375.2.1.2.12.3.2.1.2';
my $snmp_result = $options{snmp}->get_table(oid => $oid_sysTrunkCfgMemberName);
foreach my $trunk_name (keys %{$self->{trunks}}) {
$self->{trunks}->{$trunk_name}->{trunk_global}->{total_interfaces} = 0;
foreach (keys %$snmp_result) {
next if (! /^$oid_sysTrunkCfgMemberName\.$self->{trunks}->{$trunk_name}->{instance}\./);
my $interface_name = $snmp_result->{$_};
foreach my $oid_int (keys %$interfaces) {
next if ($oid_int !~ /^$mapping_interface->{display}->{oid}\.(.*)/);
my $instance = $1;
next if ($interfaces->{$oid_int} ne $snmp_result->{$_});
my $result = $options{snmp}->map_instance(mapping => $mapping_interface, results => $interfaces, instance => $instance);
$self->{trunks}->{$trunk_name}->{interfaces}->{ $result->{display} } = {
%$result
};
$self->{trunks}->{$trunk_name}->{trunk_global}->{total_interfaces}++;
}
}
}
}
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
if ($options{snmp}->is_snmpv1()) { if ($options{snmp}->is_snmpv1()) {
$self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); $self->{output}->add_option_msg(short_msg => 'Need to use SNMP v2c or v3.');
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
my $results = $options{snmp}->get_multiple_table( my $oid_sysTrunkName = '.1.3.6.1.4.1.3375.2.1.2.12.1.2.1.1';
oids => [ my $snmp_result = $options{snmp}->get_table(oid => $oid_sysTrunkName, nothing_quit => 1);
{ oid => $oid_sysTrunkTable, end => $mapping_sysTrunk->{sysTrunkOperBw}->{oid} },
{ oid => $oid_sysTrunkStatTable }
],
nothing_quit => 1
);
$self->{trunks} = {}; $self->{trunks} = {};
foreach my $oid (keys %{$results->{$oid_sysTrunkTable}}) { foreach (keys %$snmp_result) {
next if ($oid !~ /^$mapping_sysTrunk->{sysTrunkName}->{oid}\.(.*)$/); /^$oid_sysTrunkName\.(.*)$/;
my $instance = $1; my $instance = $1;
my $result_sysTrunk = $options{snmp}->map_instance(mapping => $mapping_sysTrunk, results => $results->{$oid_sysTrunkTable}, instance => $instance);
my $result_sysTrunkStat = $options{snmp}->map_instance(mapping => $mapping_sysTrunkStat, results => $results->{$oid_sysTrunkStatTable}, instance => $instance);
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$result_sysTrunk->{sysTrunkName} !~ /$self->{option_results}->{filter_name}/) { $snmp_result->{$_} !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $result_sysTrunk->{sysTrunkName} . "': no matching filter name.", debug => 1); $self->{output}->output_add(long_msg => "skipping trunk '" . $snmp_result->{$_} . "'.", debug => 1);
next; next;
} }
$self->{trunks}->{$result_sysTrunk->{sysTrunkName}} = { $self->{trunks}->{ $snmp_result->{$_} } = {
display => $result_sysTrunk->{sysTrunkName}, display => $snmp_result->{$_},
%$result_sysTrunk, %$result_sysTrunkStat, instance => $instance,
interfaces => {}
}; };
} }
if (scalar(keys %{$self->{trunks}}) <= 0) { if (scalar(keys %{$self->{trunks}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No trunks found."); $self->{output}->add_option_msg(short_msg => 'No trunk found.');
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$self->{cache_name} = "f5_bipgip_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . $options{snmp}->load(oids => [
map($_->{oid}, values(%$mapping))
],
instances => [map($_->{instance}, values(%{$self->{trunks}}))],
instance_regexp => '^(.*)$'
);
$snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
foreach (keys %{$self->{trunks}}) {
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $self->{trunks}->{$_}->{instance});
$self->{trunks}->{$_}->{trunk_global} = {
display => $_,
%$result
};
}
$self->add_interfaces(snmp => $options{snmp}) if (defined($self->{option_results}->{add_interfaces}));
$self->{cache_name} = 'f5_bipgip_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
} }
@ -439,34 +473,57 @@ Check Trunks usage.
Filter by trunks name (regexp can be used). Filter by trunks name (regexp can be used).
=item B<--threshold-overload>
Set to overload default threshold values (syntax: section,status,regexp)
It used before default thresholds (order stays).
Example: --threshold-overload='trunk,CRITICAL,^(?!(up)$)'
=item B<--units-traffic> =item B<--units-traffic>
Units of thresholds for the traffic (Default: '%') ('%', 'b/s'). Units of thresholds for the traffic (Default: '%') ('%', 'b/s').
=item B<--warning-*>
Threshold warning.
Can be: 'traffic-in', 'traffic-out', 'packets-error-in' (%),
'packets-error-out' (%), 'packets-drop-in' (%), 'packets-drop-out' (%)
=item B<--critical-*>
Threshold critical.
Can be: 'traffic-in', 'traffic-out', 'packets-error-in' (%),
'packets-error-out' (%), 'packets-drop-in' (%), 'packets-drop-out' (%)
=item B<--speed> =item B<--speed>
Set trunk speed in Mbps (Default: sysTrunkOperBw). Set trunk speed in Mbps (Default: sysTrunkOperBw).
If not set and sysTrunkOperBw OID value is 0, If not set and sysTrunkOperBw OID value is 0,
percentage thresholds will not be applied on traffic metrics. percentage thresholds will not be applied on traffic metrics.
=item B<--add-interfaces>
Monitor trunk interfaces.
=item B<--unknown-status>
Set unknown threshold for status.
Can used special variables like: %{status}, %{display}
=item B<--warning-status>
Set warning threshold for status.
Can used special variables like: %{status}, %{display}
=item B<--critical-status>
Set critical threshold for status (Default: '%{status} =~ /uninitialized|down/').
Can used special variables like: %{status}, %{display}
=item B<--unknown-interface-status>
Set unknown threshold for status.
Can used special variables like: %{status}, %{display}
=item B<--warning-interface-status>
Set warning threshold for status.
Can used special variables like: %{status}, %{display}
=item B<--critical-interface-status>
Set critical threshold for status.
Can used special variables like: %{status}, %{display}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'traffic-in', 'traffic-out', 'packets-error-in' (%),
'packets-error-out' (%), 'packets-drop-in' (%), 'packets-drop-out' (%),
'total-interfaces'.
=back =back
=cut =cut