From 29e8cc9fb1dfcd4987ff3af42a675ec18ee8a1b5 Mon Sep 17 00:00:00 2001 From: lchrdn <89968908+lchrdn@users.noreply.github.com> Date: Mon, 7 Nov 2022 16:24:12 +0100 Subject: [PATCH] (plugin) apps::vmware::connector - adding filter on alarm types for alarm-datacenter (#4036) * adding filter to exclude specified alarm types * missing attributes to option * apply suggestion for filters --- .../vmware/connector/mode/alarmdatacenter.pm | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/centreon-plugins/apps/vmware/connector/mode/alarmdatacenter.pm b/centreon-plugins/apps/vmware/connector/mode/alarmdatacenter.pm index 918e89463..6f7172682 100644 --- a/centreon-plugins/apps/vmware/connector/mode/alarmdatacenter.pm +++ b/centreon-plugins/apps/vmware/connector/mode/alarmdatacenter.pm @@ -179,10 +179,12 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'datacenter:s' => { name => 'datacenter' }, - 'filter' => { name => 'filter' }, - 'filter-time:s' => { name => 'filter_time' }, - 'memory' => { name => 'memory' } + 'datacenter:s' => { name => 'datacenter' }, + 'exclude-type:s' => { name => 'exclude_type' }, + 'filter' => { name => 'filter' }, + 'filter-time:s' => { name => 'filter_time' }, + 'filter-type:s' => { name => 'filter_type' }, + 'memory' => { name => 'memory' } }); centreon::plugins::misc::mymodule_load( @@ -223,6 +225,11 @@ sub manage_selection { $self->{datacenter}->{$datacenter_name} = { display => $datacenter_name, alarm => {}, dc_metrics => { 1 => { name => $datacenter_name } } }; foreach (keys %{$response->{data}->{$datacenter_id}->{alarms}}) { + next if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && + $response->{data}->{$datacenter_id}->{alarms}->{$_}->{type} !~ /$self->{option_results}->{filter_type}/); + next if (defined($self->{option_results}->{exclude_type}) && $self->{option_results}->{exclude_type} ne '' && + $response->{data}->{$datacenter_id}->{alarms}->{$_}->{type} =~ /$self->{option_results}->{exclude_type}/); + my $create_time = Date::Parse::str2time($response->{data}->{$datacenter_id}->{alarms}->{$_}->{time}); if (!defined($create_time)) { $self->{output}->output_add(severity => 'UNKNOWN', @@ -263,13 +270,25 @@ Check datacenter alarms (red an yellow). Datacenter to check. If not set, we check all datacenters. +=item B<--exclude-type> + +Exclude alarms of specified type(s). Can be a regex. + +Can be for example: --exclude-type='HostSystem' will not show HostSystem alarms. + =item B<--filter> Datacenter is a regexp. =item B<--filter-time> -Don't check alarm older (value in seconds). +Do not check alarms older than specified time (value in seconds). + +=item B<--filter-type> + +Check only alarms for specified type(s). Can be a regex. + +Can be for example: --filter-type='VirtualMachine' will only show alarms for VirtualMachines. =item B<--memory>