Support the use of a regexp to filter interface IDs (#4956)
Co-authored-by: ykacherCentreon <ykacher@centreon.com>
This commit is contained in:
parent
8561043088
commit
48a70e481d
|
@ -934,6 +934,7 @@ sub new {
|
|||
'add-global' => { name => 'add_global' },
|
||||
'add-status' => { name => 'add_status' },
|
||||
'add-duplex-status' => { name => 'add_duplex_status' },
|
||||
'regex-id' => { name => 'regex_id' },
|
||||
'warning-status:s' => { name => 'warning_status', default => $self->default_warning_status() },
|
||||
'critical-status:s' => { name => 'critical_status', default => $self->default_critical_status() },
|
||||
'check-metrics:s' => { name => 'check_metrics', default => $self->default_check_metrics() },
|
||||
|
@ -1207,9 +1208,15 @@ sub get_selection {
|
|||
my $all_ids = $self->{statefile_cache}->get(name => 'all_ids');
|
||||
if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{interface})
|
||||
&& $self->{no_interfaceid_options} == 0) {
|
||||
foreach (@{$all_ids}) {
|
||||
if ($self->{option_results}->{interface} =~ /(^|\s|,)$_(\s*,|$)/) {
|
||||
$self->add_selected_interface(id => $_);
|
||||
|
||||
for my $id (@{$all_ids}) {
|
||||
|
||||
if (defined($self->{option_results}->{regex_id}) # with option regex_id
|
||||
and $id =~ /$self->{option_results}->{interface}/ # id must match the regex
|
||||
or !defined($self->{option_results}->{regex_id}) # without the option
|
||||
and $self->{option_results}->{interface} =~ /(^|\s|,)$id(\s*,|$)/ # the id must be part of the list
|
||||
) {
|
||||
$self->add_selected_interface(id => $id);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -1683,15 +1690,20 @@ Units of thresholds for communication types (default: 'percent_delta') ('percent
|
|||
|
||||
=item B<--nagvis-perfdata>
|
||||
|
||||
Display traffic perfdata to be compatible with nagvis widget.
|
||||
Display traffic perfdata to be compatible with NagVis widget.
|
||||
|
||||
=item B<--interface>
|
||||
|
||||
Set the interface (number expected) example: 1,2,... (empty means 'check all interfaces').
|
||||
Define the interface filter on IDs (OID indexes, e.g.: 1,2,...). If empty, all interfaces will be monitored.
|
||||
To filter on interface names, see --name.
|
||||
|
||||
=item B<--name>
|
||||
|
||||
Allows you to define the interface (in option --interface) by name instead of OID index. The name matching mode supports regular expressions.
|
||||
With this option, the interfaces will be filtered by name (given in option --interface) instead of OID index. The name matching mode supports regular expressions.
|
||||
|
||||
=item B<--regex-id>
|
||||
|
||||
With this option, interface IDs will be filtered using the --interface parameter as a regular expression instead of a list of IDs.
|
||||
|
||||
=item B<--speed>
|
||||
|
||||
|
@ -1707,7 +1719,7 @@ Set interface speed for outgoing traffic (in Mb).
|
|||
|
||||
=item B<--map-speed-dsl>
|
||||
|
||||
Get interface speed configuration for interface type 'adsl' and 'vdsl2'.
|
||||
Get interface speed configuration for interfaces of type 'ADSL' and 'VDSL2'.
|
||||
|
||||
Syntax: --map-speed-dsl=interface-src-name,interface-dsl-name
|
||||
|
||||
|
@ -1719,7 +1731,7 @@ Force to use 64 bits counters only. Can be used to improve performance.
|
|||
|
||||
=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.
|
||||
Force to use 32-bits counters (even with SNMP versions 2c and 3). To use when 64 bits counters are buggy.
|
||||
|
||||
=item B<--reload-cache-time>
|
||||
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
*** Settings ***
|
||||
Documentation Network Interfaces
|
||||
|
||||
Library OperatingSystem
|
||||
Library String
|
||||
Library Examples
|
||||
|
||||
Test Timeout 120s
|
||||
|
||||
|
||||
*** Variables ***
|
||||
${CENTREON_PLUGINS} ${CURDIR}${/}..${/}..${/}..${/}src${/}centreon_plugins.pl
|
||||
|
||||
${CMD} perl ${CENTREON_PLUGINS}
|
||||
... --plugin=os::linux::snmp::plugin
|
||||
... --mode=interfaces
|
||||
... --hostname=127.0.0.1
|
||||
... --snmp-port=2024
|
||||
... --snmp-community=network-interfaces
|
||||
... --statefile-dir=/tmp/
|
||||
|
||||
${PERCENT} %
|
||||
|
||||
${COND} ${PERCENT}\{sub\} =~ /exited/ && ${PERCENT}{display} =~ /network/'
|
||||
|
||||
*** Test Cases ***
|
||||
Interfaces by id ${tc}/5
|
||||
[Tags] os linux network interfaces
|
||||
${command} Catenate
|
||||
... ${CMD}
|
||||
... --interface='${filter}'
|
||||
... ${extra_options}
|
||||
|
||||
|
||||
${output} Run ${command}
|
||||
${output} Strip String ${output}
|
||||
Should Be Equal As Strings
|
||||
... ${output}
|
||||
... ${expected_result}
|
||||
... \nWrong output result for command:\n${command}\n\nExpected:\n${expected_result}\nCommand output:\n${output}\n
|
||||
|
||||
Examples: tc filter extra_options expected_result --
|
||||
... 1 1 ${EMPTY} OK: Interface 'lo' Status : up (admin: up)
|
||||
... 2 1,3 --add-traffic OK: All interfaces are ok
|
||||
... 3 1,3 --add-traffic OK: All interfaces are ok | 'traffic_in_lo'=0.00b/s;;;0;10000000 'traffic_out_lo'=0.00b/s;;;0;10000000 'traffic_in_eth1'=0.00b/s;;;0;1000000000 'traffic_out_eth1'=0.00b/s;;;0;1000000000
|
||||
... 4 2,3,4 --add-traffic OK: All interfaces are ok
|
||||
... 5 2,3,4 --add-traffic OK: All interfaces are ok | 'traffic_in_eth0'=0.00b/s;;;0;1000000000 'traffic_out_eth0'=0.00b/s;;;0;1000000000 'traffic_in_eth1'=0.00b/s;;;0;1000000000 'traffic_out_eth1'=0.00b/s;;;0;1000000000 'traffic_in_eth2'=0.00b/s;;;0;1000000000 'traffic_out_eth2'=0.00b/s;;;0;1000000000
|
||||
|
||||
Interfaces by id regexp ${tc}/6
|
||||
[Tags] os linux network interfaces
|
||||
${command} Catenate
|
||||
... ${CMD}
|
||||
... --interface='${filter}'
|
||||
... --regex-id
|
||||
... ${extra_options}
|
||||
|
||||
|
||||
${output} Run ${command}
|
||||
${output} Strip String ${output}
|
||||
Should Be Equal As Strings
|
||||
... ${output}
|
||||
... ${expected_result}
|
||||
... \nWrong output result for command:\n${command}\n\nExpected:\n${expected_result}\nCommand output:\n${output}\n
|
||||
|
||||
Examples: tc filter extra_options expected_result --
|
||||
... 1 ^1$ ${EMPTY} OK: Interface 'lo' Status : up (admin: up)
|
||||
... 2 1 ${EMPTY} OK: Interface 'lo' Status : up (admin: up)
|
||||
... 3 [13] --add-traffic OK: All interfaces are ok
|
||||
... 4 [13] --add-traffic OK: All interfaces are ok | 'traffic_in_lo'=0.00b/s;;;0;10000000 'traffic_out_lo'=0.00b/s;;;0;10000000 'traffic_in_eth1'=0.00b/s;;;0;1000000000 'traffic_out_eth1'=0.00b/s;;;0;1000000000
|
||||
... 5 [234] --add-traffic OK: All interfaces are ok
|
||||
... 6 [234] --add-traffic OK: All interfaces are ok | 'traffic_in_eth0'=0.00b/s;;;0;1000000000 'traffic_out_eth0'=0.00b/s;;;0;1000000000 'traffic_in_eth1'=0.00b/s;;;0;1000000000 'traffic_out_eth1'=0.00b/s;;;0;1000000000 'traffic_in_eth2'=0.00b/s;;;0;1000000000 'traffic_out_eth2'=0.00b/s;;;0;1000000000
|
File diff suppressed because it is too large
Load Diff
|
@ -1,13 +1,37 @@
|
|||
--display-transform-dst
|
||||
--display-transform-src
|
||||
--filter-vdom
|
||||
--force-counters32
|
||||
--force-counters64
|
||||
--map-speed-dsl
|
||||
--nagvis-perfdata
|
||||
--oid-display
|
||||
--oid-extra-display
|
||||
--oid-filter
|
||||
2c
|
||||
ADSL
|
||||
Centreon
|
||||
Datacore
|
||||
deltaps
|
||||
eth
|
||||
Fortigate
|
||||
Fortinet
|
||||
ifAlias
|
||||
ifDesc
|
||||
ifName
|
||||
in-bcast
|
||||
in-mcast
|
||||
in-ucast
|
||||
interface-dsl-name
|
||||
IpAddr
|
||||
license-instances-usage-prct
|
||||
MBean
|
||||
NagVis
|
||||
OID
|
||||
oneaccess-sys-mib
|
||||
out-bcast
|
||||
out-mcast
|
||||
out-ucast
|
||||
perfdata
|
||||
powershell
|
||||
proto
|
||||
|
@ -18,5 +42,8 @@ space-usage-prct
|
|||
SSH
|
||||
SureBackup
|
||||
topic-messages-inflighted
|
||||
total-oper-down
|
||||
total-oper-up
|
||||
VDSL2
|
||||
Veeam
|
||||
WSMAN
|
||||
|
|
Loading…
Reference in New Issue