Fix #5497
This commit is contained in:
parent
86cc373531
commit
83cdde9b0e
|
@ -62,6 +62,7 @@ sub new {
|
|||
"filter-name:s" => { name => 'filter_name', },
|
||||
"filter-state:s" => { name => 'filter_state', },
|
||||
"no-loopback" => { name => 'no_loopback', },
|
||||
"skip-novalues" => { name => 'skip_novalues', },
|
||||
});
|
||||
$self->{result} = {};
|
||||
return $self;
|
||||
|
@ -101,6 +102,12 @@ sub manage_selection {
|
|||
$self->{output}->output_add(long_msg => "Skipping interface '" . $interface_name . "': no matching filter state");
|
||||
next;
|
||||
}
|
||||
|
||||
$values =~ /RX bytes:(\S+).*?TX bytes:(\S+)/msi;
|
||||
if (defined($self->{option_results}->{skip_novalues}) && !defined($1)) {
|
||||
$self->{output}->output_add(long_msg => "Skipping interface '" . $interface_name . "': no values");
|
||||
next;
|
||||
}
|
||||
$self->{result}->{$interface_name} = {state => $states};
|
||||
}
|
||||
}
|
||||
|
@ -110,7 +117,7 @@ sub run {
|
|||
|
||||
$self->manage_selection();
|
||||
foreach my $name (sort(keys %{$self->{result}})) {
|
||||
$self->{output}->output_add(long_msg => "'" . $name . "' [state = " . $self->{result}->{$name}->{state} . ']');
|
||||
$self->{output}->output_add(long_msg => "'" . $name . "' [state = '" . $self->{result}->{$name}->{state} . "']");
|
||||
}
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
|
@ -200,6 +207,10 @@ Can be: 'R' (running), 'U' (up).
|
|||
|
||||
Don't display loopback interfaces.
|
||||
|
||||
=item B<--skip-novalues>
|
||||
|
||||
Filter interface without in/out byte values.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -61,7 +61,7 @@ sub new {
|
|||
"command:s" => { name => 'command', default => 'ifconfig' },
|
||||
"command-path:s" => { name => 'command_path', default => '/sbin' },
|
||||
"command-options:s" => { name => 'command_options', default => '-a 2>&1' },
|
||||
"filter-state:s" => { name => 'filter_state', default => 'RU' },
|
||||
"filter-state:s" => { name => 'filter_state', },
|
||||
"warning-in:s" => { name => 'warning_in' },
|
||||
"critical-in:s" => { name => 'critical_in' },
|
||||
"warning-out:s" => { name => 'warning_out' },
|
||||
|
@ -72,6 +72,7 @@ sub new {
|
|||
"regexp-isensitive" => { name => 'use_regexpi' },
|
||||
"speed:s" => { name => 'speed' },
|
||||
"no-loopback" => { name => 'no_loopback', },
|
||||
"skip" => { name => 'skip' },
|
||||
});
|
||||
$self->{result} = {};
|
||||
$self->{hostname} = undef;
|
||||
|
@ -173,6 +174,31 @@ sub run {
|
|||
|
||||
foreach my $name (sort(keys %{$self->{result}})) {
|
||||
|
||||
if ($self->{result}->{$name}->{state} !~ /RU/) {
|
||||
if (!defined($self->{option_results}->{skip})) {
|
||||
$self->{output}->output_add(severity => 'CRITICAL',
|
||||
short_msg => "Interface '" . $name . "' is not up or/and running");
|
||||
} else {
|
||||
# Avoid getting "buffer creation..." alone
|
||||
if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp})) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Interface '" . $name . "' is not up or/and running (normal state)");
|
||||
}
|
||||
$self->{output}->output_add(long_msg => "Skip interface '" . $name . "': not up or/and running.");
|
||||
}
|
||||
next;
|
||||
}
|
||||
|
||||
# Some interface are running but not have bytes in/out
|
||||
if (!defined($self->{result}->{$name}->{in})) {
|
||||
if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp})) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Interface '" . $name . "' is up and running but can't get traffic (no values)");
|
||||
}
|
||||
$self->{output}->output_add(long_msg => "Skip interface '" . $name . "': can't get traffic.");
|
||||
next;
|
||||
}
|
||||
|
||||
$new_datas->{'in_' . $name} = $self->{result}->{$name}->{in} * 8;
|
||||
$new_datas->{'out_' . $name} = $self->{result}->{$name}->{out} * 8;
|
||||
|
||||
|
@ -344,7 +370,11 @@ Allows to use regexp non case-sensitive (with --regexp).
|
|||
|
||||
=item B<--filter-state>
|
||||
|
||||
Filter interfaces type (regexp can be used. Default: 'RU').
|
||||
Filter interfaces type (regexp can be used).
|
||||
|
||||
=item B<--skip>
|
||||
|
||||
Skip errors on interface status (not up and running).
|
||||
|
||||
=item B<--speed>
|
||||
|
||||
|
|
Loading…
Reference in New Issue