From fdc958161387c7787025dfe365a9cb25fc7b9693 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 26 May 2020 09:44:48 +0200 Subject: [PATCH] add filter by id --- .../iplabel/datametrie/restapi/mode/kpi.pm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/monitoring/iplabel/datametrie/restapi/mode/kpi.pm b/apps/monitoring/iplabel/datametrie/restapi/mode/kpi.pm index 5a828d2b1..b8b9160bd 100644 --- a/apps/monitoring/iplabel/datametrie/restapi/mode/kpi.pm +++ b/apps/monitoring/iplabel/datametrie/restapi/mode/kpi.pm @@ -80,7 +80,8 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $options{options}->add_options(arguments => { + $options{options}->add_options(arguments => { + 'filter-id:s' => { name => 'filter_id' }, 'filter-name:s' => { name => 'filter_name' }, 'unknown-status:s' => { name => 'unknown_status', default => '' }, 'warning-status:s' => { name => 'warning_status', default => '' }, @@ -120,6 +121,11 @@ sub manage_selection { $self->{output}->output_add(long_msg => "skipping monitor '" . $_->{MONITOR_NAME} . "': no matching filter.", debug => 1); next; } + if (defined($self->{option_results}->{filter_id}) && $self->{option_results}->{filter_id} ne '' && + $_->{MONITOR_ID} !~ /$self->{option_results}->{filter_id}/) { + $self->{output}->output_add(long_msg => "skipping monitor '" . $_->{MONITOR_NAME} . "': no matching filter.", debug => 1); + next; + } my $start_date = POSIX::strftime('%d/%m/%Y %H:%M:%S', gmtime($time - ($_->{PERIODICITY} * 60 * 2))); my $kpi_detail = $options{custom}->request_api( @@ -162,9 +168,13 @@ Check KPI. Only display some counters (regexp can be used). Example: --filter-counters='status' +=item B<--filter-id> + +Filter by monitor id (can be a regexp). + =item B<--filter-name> -Filter monitor name (can be a regexp). +Filter by monitor name (can be a regexp). =item B<--unknown-status>