enh(snmp_standard): mode interfaces - add option --check-metrics (#3398)

This commit is contained in:
qgarnier 2022-01-12 12:46:55 +01:00 committed by GitHub
parent 34697b1655
commit 48fbb96cf1
16 changed files with 73 additions and 8 deletions

View File

@ -237,6 +237,10 @@ Check interface speed.
Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting). Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting).
=item B<--check-metrics>
If the expression is true, metrics are checked (Default: '%{opstatus} eq "up"').
=item B<--warning-status> =item B<--warning-status>
Set warning threshold for status. Set warning threshold for status.

View File

@ -98,6 +98,10 @@ Check interface speed.
Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting). Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting).
=item B<--check-metrics>
If the expression is true, metrics are checked (Default: '%{opstatus} eq "up"').
=item B<--warning-status> =item B<--warning-status>
Set warning threshold for status. Set warning threshold for status.

View File

@ -316,6 +316,10 @@ Check interface traffic.
Check interface optical. Check interface optical.
=item B<--check-metrics>
If the expression is true, metrics are checked (Default: '%{opstatus} eq "up"').
=item B<--warning-status> =item B<--warning-status>
Set warning threshold for status. Set warning threshold for status.

View File

@ -100,7 +100,7 @@ sub default_critical_status {
return undef; return undef;
} }
sub default_check_status { sub default_check_metrics {
my ($self, %options) = @_; my ($self, %options) = @_;
return '%{opstatus} eq "up" or %{opstatus} eq "inService"'; return '%{opstatus} eq "up" or %{opstatus} eq "inService"';
@ -403,6 +403,10 @@ Check interface traffic.
Check interface errors. Check interface errors.
=item B<--check-metrics>
If the expression is true, metrics are checked (Default: '%{opstatus} eq "up" or %{opstatus} eq "inService"').
=item B<--warning-status> =item B<--warning-status>
Set warning threshold for status. Set warning threshold for status.

View File

@ -291,6 +291,10 @@ Check interface data volume between two checks (not supposed to be graphed, usef
Check interface optical. Check interface optical.
=item B<--check-metrics>
If the expression is true, metrics are checked (Default: '%{opstatus} eq "up"').
=item B<--warning-status> =item B<--warning-status>
Set warning threshold for status. Set warning threshold for status.

View File

@ -162,6 +162,10 @@ Check interface speed.
Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting). Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting).
=item B<--check-metrics>
If the expression is true, metrics are checked (Default: '%{opstatus} eq "up"').
=item B<--warning-status> =item B<--warning-status>
Set warning threshold for status. Set warning threshold for status.

View File

@ -115,6 +115,10 @@ Check interface speed.
Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting). Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting).
=item B<--check-metrics>
If the expression is true, metrics are checked (Default: '%{opstatus} eq "up"').
=item B<--warning-status> =item B<--warning-status>
Set warning threshold for status. Set warning threshold for status.

View File

@ -75,6 +75,10 @@ Check interface speed.
Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting). Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting).
=item B<--check-metrics>
If the expression is true, metrics are checked (Default: '%{opstatus} eq "up"').
=item B<--warning-status> =item B<--warning-status>
Set warning threshold for status. Set warning threshold for status.

View File

@ -174,6 +174,10 @@ Check interface data volume between two checks (not supposed to be graphed, usef
Check power over thernet. Check power over thernet.
=item B<--check-metrics>
If the expression is true, metrics are checked (Default: '%{opstatus} eq "up"').
=item B<--warning-status> =item B<--warning-status>
Set warning threshold for status. Set warning threshold for status.

View File

@ -276,6 +276,10 @@ Check interface data volume between two checks (not supposed to be graphed, usef
Check interface optical metrics. Check interface optical metrics.
=item B<--check-metrics>
If the expression is true, metrics are checked (Default: '%{opstatus} eq "up"').
=item B<--warning-status> =item B<--warning-status>
Set warning threshold for status. Set warning threshold for status.

View File

@ -75,6 +75,10 @@ Check interface speed.
Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting). Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting).
=item B<--check-metrics>
If the expression is true, metrics are checked (Default: '%{opstatus} eq "up"').
=item B<--warning-status> =item B<--warning-status>
Set warning threshold for status. Set warning threshold for status.

View File

@ -75,6 +75,10 @@ Check interface speed.
Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting). Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting).
=item B<--check-metrics>
If the expression is true, metrics are checked (Default: '%{opstatus} eq "up"').
=item B<--warning-status> =item B<--warning-status>
Set warning threshold for status. Set warning threshold for status.

View File

@ -173,6 +173,10 @@ Check interface speed.
Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting). Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting).
=item B<--check-metrics>
If the expression is true, metrics are checked (Default: '%{opstatus} eq "up"').
=item B<--warning-status> =item B<--warning-status>
Set warning threshold for status. Set warning threshold for status.

View File

@ -155,7 +155,7 @@ sub set_oids_cast {
$self->{oid_ifHCOutBroadcastPkts} = '.1.3.6.1.4.1.6926.2.1.5.1.11'; $self->{oid_ifHCOutBroadcastPkts} = '.1.3.6.1.4.1.6926.2.1.5.1.11';
} }
sub default_check_status { sub default_check_metrics {
my ($self, %options) = @_; my ($self, %options) = @_;
return '%{opstatus} eq "enabled" and %{linkstatus} eq "true"'; return '%{opstatus} eq "enabled" and %{linkstatus} eq "true"';
@ -456,6 +456,10 @@ Check interface speed.
Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting). Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting).
=item B<--check-metrics>
If the expression is true, metrics are checked (Default: '%{opstatus} eq "enabled" and %{linkstatus} eq "true"').
=item B<--warning-status> =item B<--warning-status>
Set warning threshold for status. Set warning threshold for status.

View File

@ -42,9 +42,10 @@ sub custom_threshold_output {
$status = 'warning'; $status = 'warning';
} }
$self->{instance_mode}->{last_status} = 0; $self->{instance_mode}->{last_status} = 1;
if (eval "$self->{instance_mode}->{check_status}") { if (defined($self->{instance_mode}->{option_results}->{check_metrics}) && $self->{instance_mode}->{option_results}->{check_metrics} ne '' &&
$self->{instance_mode}->{last_status} = 1; !$self->eval(value => $self->{instance_mode}->{option_results}->{check_metrics})) {
$self->{instance_mode}->{last_status} = 0;
} }
return $status; return $status;
@ -798,7 +799,7 @@ sub check_oids_label {
} }
} }
sub default_check_status { sub default_check_metrics {
my ($self, %options) = @_; my ($self, %options) = @_;
return '%{opstatus} eq "up"'; return '%{opstatus} eq "up"';
@ -867,6 +868,7 @@ sub new {
'add-duplex-status' => { name => 'add_duplex_status' }, 'add-duplex-status' => { name => 'add_duplex_status' },
'warning-status:s' => { name => 'warning_status', default => $self->default_warning_status() }, 'warning-status:s' => { name => 'warning_status', default => $self->default_warning_status() },
'critical-status:s' => { name => 'critical_status', default => $self->default_critical_status() }, 'critical-status:s' => { name => 'critical_status', default => $self->default_critical_status() },
'check-metrics:s' => { name => 'check_metrics', default => $self->default_check_metrics() },
'global-admin-up-rule:s' => { name => 'global_admin_up_rule', default => $self->default_global_admin_up_rule() }, 'global-admin-up-rule:s' => { name => 'global_admin_up_rule', default => $self->default_global_admin_up_rule() },
'global-oper-up-rule:s' => { name => 'global_oper_up_rule', default => $self->default_global_oper_up_rule() }, 'global-oper-up-rule:s' => { name => 'global_oper_up_rule', default => $self->default_global_oper_up_rule() },
'global-admin-down-rule:s' => { name => 'global_admin_down_rule', default => $self->default_global_admin_down_rule() }, 'global-admin-down-rule:s' => { name => 'global_admin_down_rule', default => $self->default_global_admin_down_rule() },
@ -984,8 +986,7 @@ sub check_options {
} }
$self->change_macros(macros => ['warning_status', 'critical_status']); $self->change_macros(macros => ['warning_status', 'critical_status']);
$self->{check_status} = $self->default_check_status(); $self->{option_results}->{check_metrics} =~ s/%\{(.*?)\}/\$values->{$1}/g;
$self->{check_status} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g;
} }
sub get_display_value { sub get_display_value {
@ -1571,6 +1572,10 @@ Check interface speed.
Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting). Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting).
=item B<--check-metrics>
If the expression is true, metrics are checked (Default: '%{opstatus} eq "up"').
=item B<--warning-status> =item B<--warning-status>
Set warning threshold for status. Set warning threshold for status.

View File

@ -88,6 +88,10 @@ Check interface speed.
Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting). Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting).
=item B<--check-metrics>
If the expression is true, metrics are checked (Default: '%{opstatus} eq "up"').
=item B<--warning-status> =item B<--warning-status>
Set warning threshold for status. Set warning threshold for status.