From f0f038dd7907ed5f1b0cc74e70e70754caa29fc0 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 21 Jul 2020 10:21:12 +0200 Subject: [PATCH] enhance aws health --- cloud/aws/custom/awscli.pm | 27 +++++++++++++-------------- cloud/aws/custom/paws.pm | 2 +- cloud/aws/health/mode/events.pm | 30 ++++++++++++++++++++---------- 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/cloud/aws/custom/awscli.pm b/cloud/aws/custom/awscli.pm index 4c57a2917..dce36fcf5 100644 --- a/cloud/aws/custom/awscli.pm +++ b/cloud/aws/custom/awscli.pm @@ -674,13 +674,11 @@ sub health_describe_events_set_cmd { my $cmd_options = "health describe-events --region $self->{option_results}->{region} --output json"; my ($filter, $filter_append) = ('', ''); - foreach ((['service', 'services'], ['region', 'regions'], ['entity_value', 'entityValues'], ['event_status', 'eventStatusCodes'])) { - next if (!defined($options{ $_->[0] })); + foreach ((['service', 'services'], ['region', 'regions'], ['entity_value', 'entityValues'], ['event_status', 'eventStatusCodes'], ['event_category', 'eventTypeCategories'])) { + next if (!defined($options{ 'filter_' . $_->[0] })); - foreach my $entry (@{$options{ $_->[0] }}) { - $filter .= $filter_append . $_->[1] . '=' . $entry; - $filter_append = ','; - } + $filter .= $filter_append . $_->[1] . '=' . join(',', @{$options{ 'filter_' . $_->[0] }}); + $filter_append = ','; } $cmd_options .= " --filter '$filter'" if ($filter ne ''); @@ -705,12 +703,9 @@ sub health_describe_affected_entities_set_cmd { my $cmd_options = "health describe-affected-entities --region $self->{option_results}->{region} --output json"; - my ($filter, $filter_append) = ('', ''); + my $filter = ''; if (defined($options{filter_event_arns})) { - foreach my $entry (@{$options{filter_event_arns}}) { - $filter .= $filter_append . 'eventArns=' . $entry; - $filter_append = ','; - } + $filter = 'eventArns=' . join(',', @{$options{filter_event_arns}}); } $cmd_options .= " --filter '$filter'" if ($filter ne ''); @@ -722,10 +717,14 @@ sub health_describe_affected_entities_set_cmd { sub health_describe_affected_entities { my ($self, %options) = @_; - my $cmd_options = $self->health_describe_affected_entities_set_cmd(%options); - my $raw_results = $self->execute(cmd_options => $cmd_options); + my $all_results = []; + while (my @elements = splice(@{$options{filter_event_arns}}, 0, 10)) { + my $cmd_options = $self->health_describe_affected_entities_set_cmd(filter_event_arns => \@elements); + my $raw_results = $self->execute(cmd_options => $cmd_options); + push $all_results, @{$raw_results->{entities}}; + } - return $raw_results->{entities}; + return $all_results; } 1; diff --git a/cloud/aws/custom/paws.pm b/cloud/aws/custom/paws.pm index cac615d56..ceb4af913 100644 --- a/cloud/aws/custom/paws.pm +++ b/cloud/aws/custom/paws.pm @@ -579,7 +579,7 @@ sub health_describe_events { my $lwp_caller = new Paws::Net::LWPCaller(); my $health = Paws->service('Health', caller => $lwp_caller, region => $self->{option_results}->{region}); my $health_options = { Filter => {} }; - foreach ((['service', 'Services'], ['region', 'Regions'], ['entity_value', 'EntityValues'], ['event_status', 'EventStatusCodes'])) { + foreach ((['service', 'Services'], ['region', 'Regions'], ['entity_value', 'EntityValues'], ['event_status', 'EventStatusCodes'], ['event_category', 'EventTypeCategories'])) { next if (!defined($options{ $_->[0] })); $health_options->{Filter}->{ $_->[1] } = $_->[0]; } diff --git a/cloud/aws/health/mode/events.pm b/cloud/aws/health/mode/events.pm index 146afd632..49d0b89a6 100644 --- a/cloud/aws/health/mode/events.pm +++ b/cloud/aws/health/mode/events.pm @@ -35,8 +35,7 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'global', cb_prefix_output => 'prefix_global_output', type => 0 }, - + { name => 'global', cb_prefix_output => 'prefix_global_output', type => 0 } ]; $self->{maps_counters}->{global} = [ @@ -56,7 +55,7 @@ sub set_counters { ] } }, - { label => 'closed', nlabel => 'events.closed.count', set => { + { label => 'closed', nlabel => 'events.closed.count', set => { key_values => [ { name => 'closed' } ], output_template => 'closed: %s', perfdatas => [ @@ -81,10 +80,12 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'filter-service:s@' => { name => 'filter_service' }, - 'filter-region:s@' => { name => 'filter_region' }, - 'filter-entity-value:s@' => { name => 'filter_entity_value' }, - 'filter-event-status:s@' => { name => 'filter_event_status' } + 'filter-service:s@' => { name => 'filter_service' }, + 'filter-region:s@' => { name => 'filter_region' }, + 'filter-entity-value:s@' => { name => 'filter_entity_value' }, + 'filter-event-status:s@' => { name => 'filter_event_status' }, + 'filter-event-category:s@' => { name => 'filter_event_category' }, + 'display-affected-entities' => { name => 'display_affected_entities' } }); return $self; @@ -95,7 +96,7 @@ sub check_options { $self->SUPER::check_options(%options); $self->{filter_options} = {}; - foreach (('service', 'region', 'entity_value', 'event_status')) { + foreach (('service', 'region', 'entity_value', 'event_status', 'event_category')) { $self->{filter_options}->{'filter_' . $_} = undef; if (defined($self->{option_results}->{'filter_' . $_})) { foreach my $option (@{$self->{option_results}->{'filter_' . $_}}) { @@ -126,8 +127,8 @@ sub manage_selection { my $affected_entities; my @event_arns = sort { $events->{$b}->{startTime} cmp $events->{$a}->{startTime} } keys %$events; - if (scalar(@event_arns) > 0) { - $affected_entities = $options{custom}->health_describe_affected_entities(filter_event_arns => \@event_arns); + if (scalar(@event_arns) > 0 && defined($self->{option_results}->{display_affected_entities})) { + $affected_entities = $options{custom}->health_describe_affected_entities(filter_event_arns => [@event_arns]); } foreach (@event_arns) { @@ -186,6 +187,15 @@ Example: --filter-entity-value=i-34ab692e --filter-entity-value=vol-426ab23e Filter result by event status (multiple option). Example: --filter-event-status=open --filter-event-status=closed +=item B<--filter-event-category> + +Filter result by event category (multiple option). +Example: --filter-event-category=issue + +=item B<--display-affected-entities> + +Display affected entities by the event. + =item B<--warning-*> B<--critical-*> Thresholds.