From c62568ff60e25034fc8611a219d7bd1467ead7f2 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 20 Jul 2020 15:10:46 +0200 Subject: [PATCH] aws cleaning region + aws health service --- cloud/aws/apigateway/mode/discovery.pm | 3 +- cloud/aws/apigateway/mode/latency.pm | 2 +- cloud/aws/apigateway/mode/requests.pm | 1 - cloud/aws/billing/mode/estimatedcharges.pm | 1 - cloud/aws/billing/mode/listservices.pm | 3 - cloud/aws/billing/plugin.pm | 17 ++- cloud/aws/cloudfront/mode/errors.pm | 1 - cloud/aws/cloudfront/mode/requests.pm | 1 - cloud/aws/cloudfront/mode/throughput.pm | 3 +- cloud/aws/cloudwatch/mode/getalarms.pm | 4 +- cloud/aws/cloudwatch/mode/getmetrics.pm | 1 - cloud/aws/cloudwatch/mode/listmetrics.pm | 1 - cloud/aws/custom/awscli.pm | 85 +++++++++-- cloud/aws/custom/paws.pm | 134 +++++++++++++++--- cloud/aws/ebs/mode/discovery.pm | 1 - cloud/aws/ebs/mode/listvolumes.pm | 2 +- cloud/aws/ebs/mode/volumeio.pm | 3 +- cloud/aws/ebs/mode/volumeiops.pm | 3 +- cloud/aws/ebs/mode/volumetime.pm | 3 +- cloud/aws/ec2/mode/asgstatus.pm | 8 +- cloud/aws/ec2/mode/cpu.pm | 1 - cloud/aws/ec2/mode/discovery.pm | 1 - .../ec2/mode/discoveryspotfleetrequests.pm | 2 - cloud/aws/ec2/mode/diskio.pm | 1 - cloud/aws/ec2/mode/instancesstatus.pm | 10 +- cloud/aws/ec2/mode/instancestypes.pm | 15 +- cloud/aws/ec2/mode/listasg.pm | 2 +- cloud/aws/ec2/mode/listinstances.pm | 2 +- cloud/aws/ec2/mode/listspotfleetrequests.pm | 2 +- cloud/aws/ec2/mode/network.pm | 1 - cloud/aws/ec2/mode/spotactiveinstances.pm | 10 +- cloud/aws/ec2/mode/status.pm | 1 - cloud/aws/efs/mode/connections.pm | 3 +- cloud/aws/efs/mode/datausage.pm | 3 +- cloud/aws/efs/mode/discovery.pm | 1 - .../aws/elasticache/mode/commandsmemcached.pm | 3 +- cloud/aws/elasticache/mode/commandsredis.pm | 3 +- cloud/aws/elasticache/mode/connections.pm | 3 +- cloud/aws/elasticache/mode/cpu.pm | 15 +- cloud/aws/elasticache/mode/evictions.pm | 3 +- cloud/aws/elasticache/mode/items.pm | 3 +- cloud/aws/elasticache/mode/network.pm | 3 +- cloud/aws/elasticache/mode/replication.pm | 3 +- .../aws/elasticache/mode/requestsmemcached.pm | 3 +- cloud/aws/elasticache/mode/requestsredis.pm | 3 +- cloud/aws/elasticache/mode/usagememcached.pm | 3 +- cloud/aws/elasticache/mode/usageredis.pm | 3 +- cloud/aws/elb/application/mode/connections.pm | 1 - cloud/aws/elb/application/mode/discovery.pm | 1 - cloud/aws/elb/application/mode/httpcodes.pm | 1 - .../aws/elb/application/mode/targetshealth.pm | 3 +- cloud/aws/elb/classic/mode/discovery.pm | 1 - cloud/aws/elb/classic/mode/httpcodes.pm | 1 - cloud/aws/elb/classic/mode/performances.pm | 1 - cloud/aws/elb/classic/mode/queues.pm | 1 - cloud/aws/elb/classic/mode/targetshealth.pm | 1 - cloud/aws/elb/network/mode/discovery.pm | 1 - cloud/aws/elb/network/mode/targetshealth.pm | 1 - cloud/aws/health/mode/events.pm | 37 ++++- cloud/aws/health/plugin.pm | 5 + cloud/aws/kinesis/mode/discovery.pm | 1 - cloud/aws/kinesis/mode/recordsstats.pm | 1 - cloud/aws/kinesis/mode/streams.pm | 1 - cloud/aws/lambda/mode/invocations.pm | 3 +- cloud/aws/rds/mode/connections.pm | 3 +- cloud/aws/rds/mode/cpu.pm | 3 +- cloud/aws/rds/mode/discovery.pm | 1 - cloud/aws/rds/mode/diskio.pm | 1 - cloud/aws/rds/mode/instancestatus.pm | 20 +-- cloud/aws/rds/mode/listclusters.pm | 2 +- cloud/aws/rds/mode/listinstances.pm | 2 +- cloud/aws/rds/mode/network.pm | 1 - cloud/aws/rds/mode/queries.pm | 1 - cloud/aws/rds/mode/transactions.pm | 3 +- cloud/aws/rds/mode/volume.pm | 3 +- cloud/aws/s3/mode/bucketsize.pm | 3 +- cloud/aws/s3/mode/discovery.pm | 1 - cloud/aws/s3/mode/objects.pm | 3 +- cloud/aws/s3/mode/requests.pm | 19 +-- cloud/aws/vpn/mode/listvpn.pm | 2 +- cloud/aws/vpn/mode/traffic.pm | 3 +- 81 files changed, 295 insertions(+), 217 deletions(-) diff --git a/cloud/aws/apigateway/mode/discovery.pm b/cloud/aws/apigateway/mode/discovery.pm index 88e8eff9f..5be89cd34 100644 --- a/cloud/aws/apigateway/mode/discovery.pm +++ b/cloud/aws/apigateway/mode/discovery.pm @@ -32,7 +32,7 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "prettify" => { name => 'prettify' }, + "prettify" => { name => 'prettify' } }); return $self; @@ -52,7 +52,6 @@ sub run { $disco_stats->{start_time} = time(); my $apis = $options{custom}->discovery( - region => $self->{option_results}->{region}, service => 'apigateway', command => 'get-rest-apis' ); diff --git a/cloud/aws/apigateway/mode/latency.pm b/cloud/aws/apigateway/mode/latency.pm index cd03b83ef..1728fb9e3 100644 --- a/cloud/aws/apigateway/mode/latency.pm +++ b/cloud/aws/apigateway/mode/latency.pm @@ -140,7 +140,6 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/ApiGateway', dimensions => [ { Name => 'ApiName', Value => $instance } ], metrics => $self->{aws_metrics}, @@ -148,6 +147,7 @@ sub manage_selection { timeframe => $self->{aws_timeframe}, period => $self->{aws_period}, ); + foreach my $metric (@{$self->{aws_metrics}}) { foreach my $statistic (@{$self->{aws_statistics}}) { next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) diff --git a/cloud/aws/apigateway/mode/requests.pm b/cloud/aws/apigateway/mode/requests.pm index b95cd685b..f479797ee 100644 --- a/cloud/aws/apigateway/mode/requests.pm +++ b/cloud/aws/apigateway/mode/requests.pm @@ -141,7 +141,6 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/ApiGateway', dimensions => [ { Name => 'ApiName', Value => $instance } ], metrics => $self->{aws_metrics}, diff --git a/cloud/aws/billing/mode/estimatedcharges.pm b/cloud/aws/billing/mode/estimatedcharges.pm index 1e7c1cf5b..a913442f7 100644 --- a/cloud/aws/billing/mode/estimatedcharges.pm +++ b/cloud/aws/billing/mode/estimatedcharges.pm @@ -88,7 +88,6 @@ sub manage_selection { foreach my $service (@{$self->{option_results}->{service}}) { my $metric_results = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/Billing', dimensions => [ { Name => 'ServiceName', Value => $service }, diff --git a/cloud/aws/billing/mode/listservices.pm b/cloud/aws/billing/mode/listservices.pm index 04a770468..78512be53 100644 --- a/cloud/aws/billing/mode/listservices.pm +++ b/cloud/aws/billing/mode/listservices.pm @@ -38,15 +38,12 @@ sub new { sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - - $self->{aws_region} = defined($self->{option_results}->{region}) ? $self->{option_results}->{region} : 'us-east-1'; } sub manage_selection { my ($self, %options) = @_; $self->{dimensions} = $options{custom}->cloudwatch_list_metrics( - region => $self->{aws_region}, namespace => 'AWS/Billing' ); } diff --git a/cloud/aws/billing/plugin.pm b/cloud/aws/billing/plugin.pm index 136a75e3a..5d30dd417 100644 --- a/cloud/aws/billing/plugin.pm +++ b/cloud/aws/billing/plugin.pm @@ -30,13 +30,18 @@ sub new { bless $self, $class; $self->{version} = '0.1'; - %{ $self->{modes} } = ( - 'estimated-charges' => 'cloud::aws::billing::mode::estimatedcharges', - 'list-services' => 'cloud::aws::billing::mode::listservices', - ); + $self->{modes} = { + 'estimated-charges' => 'cloud::aws::billing::mode::estimatedcharges', + 'list-services' => 'cloud::aws::billing::mode::listservices' + }; - $self->{custom_modes}{paws} = 'cloud::aws::custom::paws'; - $self->{custom_modes}{awscli} = 'cloud::aws::custom::awscli'; + $self->{customdefault} = { + paws => { region => 'us-east-1' }, + awscli => { region => 'us-east-1' } + }; + + $self->{custom_modes}->{paws} = 'cloud::aws::custom::paws'; + $self->{custom_modes}->{awscli} = 'cloud::aws::custom::awscli'; return $self; } diff --git a/cloud/aws/cloudfront/mode/errors.pm b/cloud/aws/cloudfront/mode/errors.pm index 319a35e1a..9f442a082 100644 --- a/cloud/aws/cloudfront/mode/errors.pm +++ b/cloud/aws/cloudfront/mode/errors.pm @@ -145,7 +145,6 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/CloudFront', dimensions => [ { Name => 'Region', Value => 'Global' }, { Name => 'DistributionId', Value => $instance } ], metrics => $self->{aws_metrics}, diff --git a/cloud/aws/cloudfront/mode/requests.pm b/cloud/aws/cloudfront/mode/requests.pm index 452448982..042ad67c3 100644 --- a/cloud/aws/cloudfront/mode/requests.pm +++ b/cloud/aws/cloudfront/mode/requests.pm @@ -185,7 +185,6 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/CloudFront', dimensions => [ { Name => 'Region', Value => 'Global' }, { Name => 'DistributionId', Value => $instance } ], metrics => $self->{aws_metrics}, diff --git a/cloud/aws/cloudfront/mode/throughput.pm b/cloud/aws/cloudfront/mode/throughput.pm index bddb22638..07e626fe2 100644 --- a/cloud/aws/cloudfront/mode/throughput.pm +++ b/cloud/aws/cloudfront/mode/throughput.pm @@ -199,13 +199,12 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/CloudFront', dimensions => [ { Name => 'Region', Value => 'Global' }, { Name => 'DistributionId', Value => $instance } ], metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/cloudwatch/mode/getalarms.pm b/cloud/aws/cloudwatch/mode/getalarms.pm index 25b975fb8..640c50269 100644 --- a/cloud/aws/cloudwatch/mode/getalarms.pm +++ b/cloud/aws/cloudwatch/mode/getalarms.pm @@ -107,9 +107,7 @@ sub manage_selection { my ($self, %options) = @_; $self->{alarms}->{global} = { alarm => {} }; - my $alarm_results = $options{custom}->cloudwatch_get_alarms( - region => $self->{option_results}->{region}, - ); + my $alarm_results = $options{custom}->cloudwatch_get_alarms(); my $last_time; if (defined($self->{option_results}->{memory})) { diff --git a/cloud/aws/cloudwatch/mode/getmetrics.pm b/cloud/aws/cloudwatch/mode/getmetrics.pm index 7af2ec2e9..7f7e48a20 100644 --- a/cloud/aws/cloudwatch/mode/getmetrics.pm +++ b/cloud/aws/cloudwatch/mode/getmetrics.pm @@ -166,7 +166,6 @@ sub manage_selection { my ($self, %options) = @_; my $metric_results = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => $self->{option_results}->{namespace}, dimensions => $self->{aws_dimensions}, metrics => $self->{aws_metrics}, diff --git a/cloud/aws/cloudwatch/mode/listmetrics.pm b/cloud/aws/cloudwatch/mode/listmetrics.pm index a9b4e3fd7..a022d028b 100644 --- a/cloud/aws/cloudwatch/mode/listmetrics.pm +++ b/cloud/aws/cloudwatch/mode/listmetrics.pm @@ -47,7 +47,6 @@ sub manage_selection { my ($self, %options) = @_; $self->{metrics} = $options{custom}->cloudwatch_list_metrics( - region => $self->{option_results}->{region}, namespace => $self->{option_results}->{namespace}, metric => $self->{option_results}->{metric} ); diff --git a/cloud/aws/custom/awscli.pm b/cloud/aws/custom/awscli.pm index d77bc9ef6..4c57a2917 100644 --- a/cloud/aws/custom/awscli.pm +++ b/cloud/aws/custom/awscli.pm @@ -62,6 +62,7 @@ sub new { $options{options}->add_help(package => __PACKAGE__, sections => 'AWSCLI OPTIONS', once => 1); $self->{output} = $options{output}; + $self->{custommode_name} = $options{custommode_name}; return $self; } @@ -78,7 +79,31 @@ sub set_options { $self->{option_results} = $options{option_results}; } -sub set_defaults {} +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{custommode_name}) { + if (ref($options{default}->{$_}) eq 'ARRAY') { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + + if (ref($options{default}->{$_}) eq 'HASH') { + foreach my $opt (keys %{$options{default}->{$_}}) { + if (!defined($self->{option_results}->{$opt})) { + $self->{option_results}->{$opt} = $options{default}->{$_}->{$opt}; + } + } + } + } + } +} sub check_options { my ($self, %options) = @_; @@ -157,7 +182,7 @@ sub cloudwatch_get_metrics_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "cloudwatch get-metric-statistics --region $options{region} --namespace $options{namespace}" . + my $cmd_options = "cloudwatch get-metric-statistics --region $self->{option_results}->{region} --namespace $options{namespace}" . " --metric-name '$options{metric_name}' --start-time $options{start_time} --end-time $options{end_time}" . " --period $options{period} --statistics " . join(' ', @{$options{statistics}}) . " --output json --dimensions"; foreach my $entry (@{$options{dimensions}}) { @@ -215,7 +240,7 @@ sub discovery_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = $options{service} . " " . $options{command} . " --region $options{region} --output json"; + my $cmd_options = $options{service} . " " . $options{command} . " --region $self->{option_results}->{region} --output json"; $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); return $cmd_options; @@ -235,7 +260,7 @@ sub cloudwatch_get_alarms_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "cloudwatch describe-alarms --region $options{region} --output json"; + my $cmd_options = "cloudwatch describe-alarms --region $self->{option_results}->{region} --output json"; $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); return $cmd_options; @@ -266,7 +291,7 @@ sub cloudwatch_list_metrics_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "cloudwatch list-metrics --region $options{region} --output json"; + my $cmd_options = "cloudwatch list-metrics --region $self->{option_results}->{region} --output json"; $cmd_options .= " --namespace $options{namespace}" if (defined($options{namespace})); $cmd_options .= " --metric-name $options{metric}" if (defined($options{metric})); $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); @@ -335,7 +360,7 @@ sub ebs_list_volumes_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "ec2 describe-volumes --no-dry-run --region $options{region} --output json"; + my $cmd_options = "ec2 describe-volumes --no-dry-run --region $self->{option_results}->{region} --output json"; $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); return $cmd_options; @@ -371,7 +396,7 @@ sub ec2_get_instances_status_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "ec2 describe-instance-status --include-all-instances --no-dry-run --region $options{region} --output json"; + my $cmd_options = "ec2 describe-instance-status --include-all-instances --no-dry-run --region $self->{option_results}->{region} --output json"; $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); return $cmd_options; @@ -399,7 +424,7 @@ sub ec2spot_get_active_instances_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "ec2 describe-spot-fleet-instances --no-dry-run --region $options{region} --output json"; + my $cmd_options = "ec2 describe-spot-fleet-instances --no-dry-run --region $self->{option_results}->{region} --output json"; $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); $cmd_options .= " --spot-fleet-request-id " . $options{spot_fleet_request_id}; @@ -429,7 +454,7 @@ sub ec2spot_list_fleet_requests_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "ec2 describe-spot-fleet-requests --no-dry-run --region $options{region} --output json"; + my $cmd_options = "ec2 describe-spot-fleet-requests --no-dry-run --region $self->{option_results}->{region} --output json"; $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); return $cmd_options; @@ -458,7 +483,7 @@ sub ec2_list_resources_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "ec2 describe-instances --no-dry-run --region $options{region} --output json"; + my $cmd_options = "ec2 describe-instances --no-dry-run --region $self->{option_results}->{region} --output json"; $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); return $cmd_options; @@ -506,7 +531,7 @@ sub asg_get_resources_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "autoscaling describe-auto-scaling-groups --region $options{region} --output json"; + my $cmd_options = "autoscaling describe-auto-scaling-groups --region $self->{option_results}->{region} --output json"; $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); return $cmd_options; @@ -526,7 +551,7 @@ sub rds_get_instances_status_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "rds describe-db-instances --region $options{region} --output json"; + my $cmd_options = "rds describe-db-instances --region $self->{option_results}->{region} --output json"; $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); return $cmd_options; @@ -551,7 +576,7 @@ sub rds_list_instances_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "rds describe-db-instances --region $options{region} --output json"; + my $cmd_options = "rds describe-db-instances --region $self->{option_results}->{region} --output json"; $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); return $cmd_options; @@ -582,7 +607,7 @@ sub rds_list_clusters_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "rds describe-db-clusters --region $options{region} --output json"; + my $cmd_options = "rds describe-db-clusters --region $self->{option_results}->{region} --output json"; $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); return $cmd_options; @@ -612,7 +637,7 @@ sub vpn_list_connections_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "ec2 describe-vpn-connections --region $options{region} --output json"; + my $cmd_options = "ec2 describe-vpn-connections --region $self->{option_results}->{region} --output json"; $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); return $cmd_options; @@ -673,6 +698,36 @@ sub health_describe_events { return $raw_results->{events}; } +sub health_describe_affected_entities_set_cmd { + my ($self, %options) = @_; + + return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); + + my $cmd_options = "health describe-affected-entities --region $self->{option_results}->{region} --output json"; + + my ($filter, $filter_append) = ('', ''); + if (defined($options{filter_event_arns})) { + foreach my $entry (@{$options{filter_event_arns}}) { + $filter .= $filter_append . 'eventArns=' . $entry; + $filter_append = ','; + } + } + + $cmd_options .= " --filter '$filter'" if ($filter ne ''); + $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); + + return $cmd_options; +} + +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); + + return $raw_results->{entities}; +} + 1; __END__ diff --git a/cloud/aws/custom/paws.pm b/cloud/aws/custom/paws.pm index d3e953ecb..cac615d56 100644 --- a/cloud/aws/custom/paws.pm +++ b/cloud/aws/custom/paws.pm @@ -56,6 +56,7 @@ sub new { $options{options}->add_help(package => __PACKAGE__, sections => 'PAWS OPTIONS', once => 1); $self->{output} = $options{output}; + $self->{custommode_name} = $options{custommode_name}; return $self; } @@ -72,7 +73,31 @@ sub set_options { $self->{option_results} = $options{option_results}; } -sub set_defaults {} +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{custommode_name}) { + if (ref($options{default}->{$_}) eq 'ARRAY') { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + + if (ref($options{default}->{$_}) eq 'HASH') { + foreach my $opt (keys %{$options{default}->{$_}}) { + if (!defined($self->{option_results}->{$opt})) { + $self->{option_results}->{$opt} = $options{default}->{$_}->{$opt}; + } + } + } + } + } +} sub check_options { my ($self, %options) = @_; @@ -93,7 +118,7 @@ sub check_options { } if (!defined($self->{option_results}->{region}) || $self->{option_results}->{region} eq '') { - $self->{output}->add_option_msg(short_msg => "Need to specify --region option."); + $self->{output}->add_option_msg(short_msg => 'Need to specify --region option.'); $self->{output}->option_exit(); } @@ -115,7 +140,7 @@ sub cloudwatch_get_metrics { my $metric_results = {}; eval { my $lwp_caller = new Paws::Net::LWPCaller(); - my $cw = Paws->service('CloudWatch', caller => $lwp_caller, region => $options{region}); + my $cw = Paws->service('CloudWatch', caller => $lwp_caller, region => $self->{option_results}->{region}); my $start_time = DateTime->now->subtract(seconds => $options{timeframe})->iso8601; my $end_time = DateTime->now->iso8601; @@ -173,7 +198,7 @@ sub cloudwatch_get_alarms { my $alarm_results = []; eval { my $lwp_caller = new Paws::Net::LWPCaller(); - my $cw = Paws->service('CloudWatch', caller => $lwp_caller, region => $options{region}); + my $cw = Paws->service('CloudWatch', caller => $lwp_caller, region => $self->{option_results}->{region}); my $alarms = $cw->DescribeAlarms(); foreach my $alarm (@{$alarms->{MetricAlarms}}) { push @$alarm_results, { @@ -198,7 +223,7 @@ sub cloudwatch_list_metrics { my $metric_results = []; eval { my $lwp_caller = new Paws::Net::LWPCaller(); - my $cw = Paws->service('CloudWatch', caller => $lwp_caller, region => $options{region}); + my $cw = Paws->service('CloudWatch', caller => $lwp_caller, region => $self->{option_results}->{region}); my %cw_options = (); $cw_options{Namespace} = $options{namespace} if (defined($options{namespace})); $cw_options{MetricName} = $options{metric} if (defined($options{metric})); @@ -233,7 +258,7 @@ sub cloudwatchlogs_describe_log_groups { my $log_groups_results = []; eval { my $lwp_caller = new Paws::Net::LWPCaller(); - my $cw = Paws->service('CloudWatchLogs', caller => $lwp_caller, region => $options{region}); + my $cw = Paws->service('CloudWatchLogs', caller => $lwp_caller, region => $self->{option_results}->{region}); my %cw_options = (); while ((my $list_log_groups = $cw->DescribeLogGroups(%cw_options))) { foreach (@{$list_log_groups->{logGroups}}) { @@ -258,7 +283,7 @@ sub cloudwatchlogs_filter_log_events { my $log_groups_results = []; eval { my $lwp_caller = new Paws::Net::LWPCaller(); - my $cw = Paws->service('CloudWatchLogs', caller => $lwp_caller, region => $options{region}); + my $cw = Paws->service('CloudWatchLogs', caller => $lwp_caller, region => $self->{option_results}->{region}); my %cw_options = (); $cw_options{StartTime} = $options{start_time} if (defined($options{start_time})); $cw_options{LogStreamNames} = [@{$options{LogStreamNames}}] if (defined($options{LogStreamNames})); @@ -285,7 +310,7 @@ sub ebs_list_volumes { my $volume_results = []; eval { my $lwp_caller = new Paws::Net::LWPCaller(); - my $ebsvolume = Paws->service('EC2', caller => $lwp_caller, region => $options{region}); + my $ebsvolume = Paws->service('EC2', caller => $lwp_caller, region => $self->{option_results}->{region}); my $ebsvolume_requests = $ebsvolume->DescribeVolumes(DryRun => 0); foreach my $request (@{$ebsvolume_requests->{Volumes}}) { my @name_tags; @@ -316,7 +341,7 @@ sub ec2_get_instances_status { my $instance_results = {}; eval { my $lwp_caller = new Paws::Net::LWPCaller(); - my $ec2 = Paws->service('EC2', caller => $lwp_caller, region => $options{region}); + my $ec2 = Paws->service('EC2', caller => $lwp_caller, region => $self->{option_results}->{region}); my $instances = $ec2->DescribeInstanceStatus(DryRun => 0, IncludeAllInstances => 1); foreach (@{$instances->{InstanceStatuses}}) { @@ -340,7 +365,7 @@ sub ec2spot_get_active_instances { my $instance_results = {}; eval { my $lwp_caller = new Paws::Net::LWPCaller(); - my $ec2 = Paws->service('EC2', caller => $lwp_caller, region => $options{region}); + my $ec2 = Paws->service('EC2', caller => $lwp_caller, region => $self->{option_results}->{region}); my $instances = $ec2->DescribeSpotFleetInstances('SpotFleetRequestId' => $options{spot_fleet_request_id}, DryRun => 0, IncludeAllInstances => 1); foreach (@{$instances->{ActiveInstances}}) { @@ -364,7 +389,7 @@ sub ec2spot_list_fleet_requests { my $resource_results = []; eval { my $lwp_caller = new Paws::Net::LWPCaller(); - my $ec2spot = Paws->service('EC2', caller => $lwp_caller, region => $options{region}); + my $ec2spot = Paws->service('EC2', caller => $lwp_caller, region => $self->{option_results}->{region}); my $spot_fleet_requests = $ec2spot->DescribeSpotFleetRequests(DryRun => 0); foreach (@{$spot_fleet_requests->{SpotFleetRequestConfigs}}) { @@ -389,7 +414,7 @@ sub ec2_list_resources { my $resource_results = []; eval { my $lwp_caller = new Paws::Net::LWPCaller(); - my $ec2 = Paws->service('EC2', caller => $lwp_caller, region => $options{region}); + my $ec2 = Paws->service('EC2', caller => $lwp_caller, region => $self->{option_results}->{region}); my $list_instances = $ec2->DescribeInstances(DryRun => 0); foreach my $reservation (@{$list_instances->{Reservations}}) { @@ -433,7 +458,7 @@ sub asg_get_resources { my $autoscaling_groups = {}; eval { my $lwp_caller = new Paws::Net::LWPCaller(); - my $asg = Paws->service('AutoScaling', caller => $lwp_caller, region => $options{region}); + my $asg = Paws->service('AutoScaling', caller => $lwp_caller, region => $self->{option_results}->{region}); $autoscaling_groups = $asg->DescribeAutoScalingGroups(); }; if ($@) { @@ -450,7 +475,7 @@ sub rds_get_instances_status { my $instance_results = {}; eval { my $lwp_caller = new Paws::Net::LWPCaller(); - my $rds = Paws->service('RDS', caller => $lwp_caller, region => $options{region}); + my $rds = Paws->service('RDS', caller => $lwp_caller, region => $self->{option_results}->{region}); my $instances = $rds->DescribeDBInstances(); foreach (@{$instances->{DBInstances}}) { $instance_results->{$_->{DBInstanceIdentifier}} = { state => $_->{DBInstanceStatus} }; @@ -470,7 +495,7 @@ sub rds_list_instances { my $instance_results = []; eval { my $lwp_caller = new Paws::Net::LWPCaller(); - my $rds = Paws->service('RDS', caller => $lwp_caller, region => $options{region}); + my $rds = Paws->service('RDS', caller => $lwp_caller, region => $self->{option_results}->{region}); my $list_instances = $rds->DescribeDBInstances(); foreach my $instance (@{$list_instances->{DBInstances}}) { @@ -497,7 +522,7 @@ sub rds_list_clusters { my $cluster_results = []; eval { my $lwp_caller = new Paws::Net::LWPCaller(); - my $rds = Paws->service('RDS', caller => $lwp_caller, region => $options{region}); + my $rds = Paws->service('RDS', caller => $lwp_caller, region => $self->{option_results}->{region}); my $list_clusters = $rds->DescribeDBClusters(); foreach my $cluster (@{$list_clusters->{DBClusters}}) { @@ -522,7 +547,7 @@ sub vpn_list_connections { my $connections_results = []; eval { my $lwp_caller = new Paws::Net::LWPCaller(); - my $vpn = Paws->service('EC2', caller => $lwp_caller, region => $options{region}); + my $vpn = Paws->service('EC2', caller => $lwp_caller, region => $self->{option_results}->{region}); my $list_vpn = $vpn->DescribeVpnConnections(); foreach my $connection (@{$list_vpn->{VpnConnections}}) { my @name_tags; @@ -546,6 +571,81 @@ sub vpn_list_connections { return $connections_results; } +sub health_describe_events { + my ($self, %options) = @_; + + my $event_results = []; + eval { + 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'])) { + next if (!defined($options{ $_->[0] })); + $health_options->{Filter}->{ $_->[1] } = $_->[0]; + } + + while ((my $events = $health->DescribeEvents(%$health_options))) { + foreach (@{$events->{Events}}) { + push @$event_results, { + arn => $_->{Arn}, + service => $_->{Service}, + eventTypeCode => $_->{EventTypeCode}, + eventTypeCategory => $_->{EventTypeCategory}, + region => $_->{Region}, + startTime => $_->{StartTime}, + lastUpdatedTime => $_->{LastUpdatedTime}, + statusCode => $_->{StatusCode} + }; + } + + last if (!defined($events->{NextToken})); + $health_options->{NextToken} = $events->{NextToken}; + } + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "error: $@"); + $self->{output}->option_exit(); + } + + return $event_results; +} + +sub health_describe_affected_entities { + my ($self, %options) = @_; + + my $entities_results = []; + eval { + my $lwp_caller = new Paws::Net::LWPCaller(); + my $health = Paws->service('Health', caller => $lwp_caller, region => $self->{option_results}->{region}); + my $health_options = { Filter => {} }; + if (defined($options{filter_event_arns})) { + $health_options->{Filter}->{EventArns} = $options{filter_event_arns}; + } + + while ((my $entities = $health->DescribeAffectedEntities(%$health_options))) { + foreach (@{$entities->{Entities}}) { + push @$entities_results, { + entityArn => $_->{EntityArn}, + eventArn => $_->{EventArn}, + entityValue => $_->{EntityValue}, + awsAccountId => $_->{AwsAccountId}, + lastUpdatedTime => $_->{LastUpdatedTime}, + statusCode => $_->{StatusCode} + }; + } + + last if (!defined($entities->{NextToken})); + $health_options->{NextToken} = $entities->{NextToken}; + } + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "error: $@"); + $self->{output}->option_exit(); + } + + return $entities_results; +} + 1; __END__ diff --git a/cloud/aws/ebs/mode/discovery.pm b/cloud/aws/ebs/mode/discovery.pm index 186e29ee0..72b680da3 100644 --- a/cloud/aws/ebs/mode/discovery.pm +++ b/cloud/aws/ebs/mode/discovery.pm @@ -52,7 +52,6 @@ sub run { $disco_stats->{start_time} = time(); my $volumes = $options{custom}->discovery( - region => $self->{option_results}->{region}, service => 'ec2', command => 'describe-volumes' ); diff --git a/cloud/aws/ebs/mode/listvolumes.pm b/cloud/aws/ebs/mode/listvolumes.pm index 63106d7cb..0317b9c9c 100644 --- a/cloud/aws/ebs/mode/listvolumes.pm +++ b/cloud/aws/ebs/mode/listvolumes.pm @@ -43,7 +43,7 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - $self->{volume} = $options{custom}->ebs_list_volumes(region => $self->{option_results}->{region}); + $self->{volume} = $options{custom}->ebs_list_volumes(); } sub run { diff --git a/cloud/aws/ebs/mode/volumeio.pm b/cloud/aws/ebs/mode/volumeio.pm index e0b1cba48..845f92761 100644 --- a/cloud/aws/ebs/mode/volumeio.pm +++ b/cloud/aws/ebs/mode/volumeio.pm @@ -209,13 +209,12 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/EBS', dimensions => [ { Name => 'VolumeId', Value => $instance } ], metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/ebs/mode/volumeiops.pm b/cloud/aws/ebs/mode/volumeiops.pm index ea08aeb76..0c84fe89a 100644 --- a/cloud/aws/ebs/mode/volumeiops.pm +++ b/cloud/aws/ebs/mode/volumeiops.pm @@ -237,13 +237,12 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/EBS', dimensions => [ { Name => 'VolumeId', Value => $instance } ], metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/ebs/mode/volumetime.pm b/cloud/aws/ebs/mode/volumetime.pm index 283fe4d3e..dba6c9fd2 100644 --- a/cloud/aws/ebs/mode/volumetime.pm +++ b/cloud/aws/ebs/mode/volumetime.pm @@ -207,13 +207,12 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/EBS', dimensions => [ { Name => 'VolumeId', Value => $instance } ], metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/ec2/mode/asgstatus.pm b/cloud/aws/ec2/mode/asgstatus.pm index d84bc4c22..0ddbd1d17 100644 --- a/cloud/aws/ec2/mode/asgstatus.pm +++ b/cloud/aws/ec2/mode/asgstatus.pm @@ -120,7 +120,6 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "region:s" => { name => 'region' }, "filter-asg:s" => { name => 'filter_asg', default => '' }, "warning-instances:s" => { name => 'warning_instances', default => '' }, "critical-instances:s" => { name => 'critical_instances', @@ -134,11 +133,6 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - if (!defined($self->{option_results}->{region}) || $self->{option_results}->{region} eq '') { - $self->{output}->add_option_msg(short_msg => "Need to specify --region option."); - $self->{output}->option_exit(); - } - $self->change_macros(macros => ['warning_instances', 'critical_instances']); } @@ -147,7 +141,7 @@ sub manage_selection { $self->{aws_autoscaling_groups} = {}; - my $result = $options{custom}->asg_get_resources(region => $self->{option_results}->{region}); + my $result = $options{custom}->asg_get_resources(); foreach my $asg (@{$result}) { my $instance_count = 0; diff --git a/cloud/aws/ec2/mode/cpu.pm b/cloud/aws/ec2/mode/cpu.pm index 09e44c44b..cff2511d7 100644 --- a/cloud/aws/ec2/mode/cpu.pm +++ b/cloud/aws/ec2/mode/cpu.pm @@ -171,7 +171,6 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/EC2', dimensions => [ { Name => $map_type{$self->{option_results}->{type}}, Value => $instance } ], metrics => $self->{aws_metrics}, diff --git a/cloud/aws/ec2/mode/discovery.pm b/cloud/aws/ec2/mode/discovery.pm index a6c43047e..6fd7655b9 100644 --- a/cloud/aws/ec2/mode/discovery.pm +++ b/cloud/aws/ec2/mode/discovery.pm @@ -55,7 +55,6 @@ sub run { my %asgs; my $instances = $options{custom}->discovery( - region => $self->{option_results}->{region}, service => 'ec2', command => 'describe-instances' ); diff --git a/cloud/aws/ec2/mode/discoveryspotfleetrequests.pm b/cloud/aws/ec2/mode/discoveryspotfleetrequests.pm index 64eeaf6f7..0c4219d56 100644 --- a/cloud/aws/ec2/mode/discoveryspotfleetrequests.pm +++ b/cloud/aws/ec2/mode/discoveryspotfleetrequests.pm @@ -55,10 +55,8 @@ sub run { my %asgs; my $spot_fleet_requests = $options{custom}->discovery( - region => $self->{option_results}->{region}, service => 'ec2', command => 'describe-spot-fleet-requests' - ); foreach my $fleet_request (@{$spot_fleet_requests->{SpotFleetRequestConfigs}}) { diff --git a/cloud/aws/ec2/mode/diskio.pm b/cloud/aws/ec2/mode/diskio.pm index 15986d91b..7d246eb77 100644 --- a/cloud/aws/ec2/mode/diskio.pm +++ b/cloud/aws/ec2/mode/diskio.pm @@ -241,7 +241,6 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/EC2', dimensions => [ { Name => $map_type{$self->{option_results}->{type}}, Value => $instance } ], metrics => $self->{aws_metrics}, diff --git a/cloud/aws/ec2/mode/instancesstatus.pm b/cloud/aws/ec2/mode/instancesstatus.pm index ad595f569..1450094cb 100644 --- a/cloud/aws/ec2/mode/instancesstatus.pm +++ b/cloud/aws/ec2/mode/instancesstatus.pm @@ -120,10 +120,9 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "region:s" => { name => 'region' }, "filter-instanceid:s" => { name => 'filter_instanceid' }, "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '' } }); return $self; @@ -133,11 +132,6 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - if (!defined($self->{option_results}->{region}) || $self->{option_results}->{region} eq '') { - $self->{output}->add_option_msg(short_msg => "Need to specify --region option."); - $self->{output}->option_exit(); - } - $self->change_macros(macros => ['warning_status', 'critical_status']); } @@ -160,7 +154,7 @@ sub manage_selection { pending => 0, running => 0, 'shutting-down' => 0, terminated => 0, stopping => 0, stopped => 0, }; $self->{aws_instances} = {}; - my $result = $options{custom}->ec2_get_instances_status(region => $self->{option_results}->{region}); + my $result = $options{custom}->ec2_get_instances_status(); foreach my $instance_id (keys %{$result}) { if (defined($self->{option_results}->{filter_instanceid}) && $self->{option_results}->{filter_instanceid} ne '' && $instance_id !~ /$self->{option_results}->{filter_instanceid}/) { diff --git a/cloud/aws/ec2/mode/instancestypes.pm b/cloud/aws/ec2/mode/instancestypes.pm index bf01ce51e..d02c6eb04 100644 --- a/cloud/aws/ec2/mode/instancestypes.pm +++ b/cloud/aws/ec2/mode/instancestypes.pm @@ -151,25 +151,14 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "region:s" => { name => 'region' }, "filter-family:s" => { name => 'filter_family' }, "filter-type:s" => { name => 'filter_type' }, - "running" => { name => 'running' }, + "running" => { name => 'running' } }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - if (!defined($self->{option_results}->{region}) || $self->{option_results}->{region} eq '') { - $self->{output}->add_option_msg(short_msg => "Need to specify --region option."); - $self->{output}->option_exit(); - } -} - sub manage_selection { my ($self, %options) = @_; @@ -189,7 +178,7 @@ sub manage_selection { } } - $self->{instances} = $options{custom}->ec2_list_resources(region => $self->{option_results}->{region}); + $self->{instances} = $options{custom}->ec2_list_resources(); foreach my $instance (@{$self->{instances}}) { next if ($instance->{Type} !~ /instance/ || (defined($self->{option_results}->{running}) && $instance->{State} !~ /running/)); diff --git a/cloud/aws/ec2/mode/listasg.pm b/cloud/aws/ec2/mode/listasg.pm index 354daefe4..80fc53b41 100644 --- a/cloud/aws/ec2/mode/listasg.pm +++ b/cloud/aws/ec2/mode/listasg.pm @@ -43,7 +43,7 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - $self->{instances} = $options{custom}->ec2_list_resources(region => $self->{option_results}->{region}); + $self->{instances} = $options{custom}->ec2_list_resources(); } sub run { diff --git a/cloud/aws/ec2/mode/listinstances.pm b/cloud/aws/ec2/mode/listinstances.pm index 7a12a9e71..b618d3a37 100644 --- a/cloud/aws/ec2/mode/listinstances.pm +++ b/cloud/aws/ec2/mode/listinstances.pm @@ -43,7 +43,7 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - $self->{instances} = $options{custom}->ec2_list_resources(region => $self->{option_results}->{region}); + $self->{instances} = $options{custom}->ec2_list_resources(); } sub run { diff --git a/cloud/aws/ec2/mode/listspotfleetrequests.pm b/cloud/aws/ec2/mode/listspotfleetrequests.pm index 340dc0bd9..113efd90e 100644 --- a/cloud/aws/ec2/mode/listspotfleetrequests.pm +++ b/cloud/aws/ec2/mode/listspotfleetrequests.pm @@ -43,7 +43,7 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - $self->{spot_fleet_requests} = $options{custom}->ec2spot_list_fleet_requests(region => $self->{option_results}->{region}); + $self->{spot_fleet_requests} = $options{custom}->ec2spot_list_fleet_requests(); } sub run { diff --git a/cloud/aws/ec2/mode/network.pm b/cloud/aws/ec2/mode/network.pm index db7cea48e..3551f0529 100644 --- a/cloud/aws/ec2/mode/network.pm +++ b/cloud/aws/ec2/mode/network.pm @@ -241,7 +241,6 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/EC2', dimensions => [ { Name => $map_type{$self->{option_results}->{type}}, Value => $instance } ], metrics => $self->{aws_metrics}, diff --git a/cloud/aws/ec2/mode/spotactiveinstances.pm b/cloud/aws/ec2/mode/spotactiveinstances.pm index f7a626242..44b4d91db 100644 --- a/cloud/aws/ec2/mode/spotactiveinstances.pm +++ b/cloud/aws/ec2/mode/spotactiveinstances.pm @@ -68,8 +68,7 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'region:s' => { name => 'region' }, - 'spot-fleet-request-id:s' => { name => 'spot_fleet_request_id' } + 'spot-fleet-request-id:s' => { name => 'spot_fleet_request_id' } }); return $self; @@ -79,11 +78,6 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - if (!defined($self->{option_results}->{region}) || $self->{option_results}->{region} eq '') { - $self->{output}->add_option_msg(short_msg => "Need to specify --region option."); - $self->{output}->option_exit(); - } - if (!defined($self->{option_results}->{spot_fleet_request_id}) || $self->{option_results}->{spot_fleet_request_id} eq '') { $self->{output}->add_option_msg(short_msg => "Need to specify --spot-fleet-request-id option."); $self->{output}->option_exit(); @@ -95,7 +89,7 @@ sub manage_selection { my ($self, %options) = @_; $self->{global} = { active => 0, healthy => 0, unhealthy => 0 }; - $self->{instances} = $options{custom}->ec2spot_get_active_instances_status(region => $self->{option_results}->{region}, spot_fleet_request_id => $self->{option_results}->{spot_fleet_request_id}); + $self->{instances} = $options{custom}->ec2spot_get_active_instances_status(spot_fleet_request_id => $self->{option_results}->{spot_fleet_request_id}); foreach my $instance_id (keys %{$self->{instances}}) { $self->{global}->{active}++; diff --git a/cloud/aws/ec2/mode/status.pm b/cloud/aws/ec2/mode/status.pm index 54cc29194..dcfac9f34 100644 --- a/cloud/aws/ec2/mode/status.pm +++ b/cloud/aws/ec2/mode/status.pm @@ -158,7 +158,6 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/EC2', dimensions => [ { Name => $map_type{$self->{option_results}->{type}}, Value => $instance } ], metrics => $self->{aws_metrics}, diff --git a/cloud/aws/efs/mode/connections.pm b/cloud/aws/efs/mode/connections.pm index f812f247c..8b2a4567d 100644 --- a/cloud/aws/efs/mode/connections.pm +++ b/cloud/aws/efs/mode/connections.pm @@ -168,13 +168,12 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/EFS', dimensions => [ { Name => 'FileSystemId', Value => $instance } ], metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/efs/mode/datausage.pm b/cloud/aws/efs/mode/datausage.pm index dd5171618..cf25b7521 100644 --- a/cloud/aws/efs/mode/datausage.pm +++ b/cloud/aws/efs/mode/datausage.pm @@ -237,13 +237,12 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/EFS', dimensions => [ { Name => "FileSystemId", Value => $instance } ], metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/efs/mode/discovery.pm b/cloud/aws/efs/mode/discovery.pm index fc575bcaf..db06ea247 100644 --- a/cloud/aws/efs/mode/discovery.pm +++ b/cloud/aws/efs/mode/discovery.pm @@ -52,7 +52,6 @@ sub run { $disco_stats->{start_time} = time(); my $fs_instances = $options{custom}->discovery( - region => $self->{option_results}->{region}, service => 'efs', command => 'describe-file-systems' ); diff --git a/cloud/aws/elasticache/mode/commandsmemcached.pm b/cloud/aws/elasticache/mode/commandsmemcached.pm index 06c829979..0ff0f63b8 100644 --- a/cloud/aws/elasticache/mode/commandsmemcached.pm +++ b/cloud/aws/elasticache/mode/commandsmemcached.pm @@ -167,13 +167,12 @@ sub manage_selection { push @{$self->{aws_dimensions}}, { Name => 'CacheNodeId', Value => $self->{option_results}->{node_id} }; } $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/ElastiCache', dimensions => $self->{aws_dimensions}, metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/elasticache/mode/commandsredis.pm b/cloud/aws/elasticache/mode/commandsredis.pm index 9c14d5b78..8b9be9650 100644 --- a/cloud/aws/elasticache/mode/commandsredis.pm +++ b/cloud/aws/elasticache/mode/commandsredis.pm @@ -169,13 +169,12 @@ sub manage_selection { push @{$self->{aws_dimensions}}, { Name => 'CacheNodeId', Value => $self->{option_results}->{node_id} }; } $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/ElastiCache', dimensions => $self->{aws_dimensions}, metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/elasticache/mode/connections.pm b/cloud/aws/elasticache/mode/connections.pm index b26c771b5..d0d4bd0b9 100644 --- a/cloud/aws/elasticache/mode/connections.pm +++ b/cloud/aws/elasticache/mode/connections.pm @@ -179,13 +179,12 @@ sub manage_selection { push @{$self->{aws_dimensions}}, { Name => 'CacheNodeId', Value => $self->{option_results}->{node_id} }; } $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/ElastiCache', dimensions => $self->{aws_dimensions}, metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/elasticache/mode/cpu.pm b/cloud/aws/elasticache/mode/cpu.pm index d011a190b..73b7e06a8 100644 --- a/cloud/aws/elasticache/mode/cpu.pm +++ b/cloud/aws/elasticache/mode/cpu.pm @@ -64,13 +64,11 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "region:s" => { name => 'region' }, - "name:s@" => { name => 'name' }, - "node-id:s" => { name => 'node_id' }, - }); - + $options{options}->add_options(arguments => { + "name:s@" => { name => 'name' }, + "node-id:s" => { name => 'node_id' }, + }); + return $self; } @@ -115,13 +113,12 @@ sub manage_selection { push @{$self->{aws_dimensions}}, { Name => 'CacheNodeId', Value => $self->{option_results}->{node_id} }; } $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/ElastiCache', dimensions => $self->{aws_dimensions}, metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/elasticache/mode/evictions.pm b/cloud/aws/elasticache/mode/evictions.pm index 1a72ef395..c580b97e9 100644 --- a/cloud/aws/elasticache/mode/evictions.pm +++ b/cloud/aws/elasticache/mode/evictions.pm @@ -167,13 +167,12 @@ sub manage_selection { push @{$self->{aws_dimensions}}, { Name => 'CacheNodeId', Value => $self->{option_results}->{node_id} }; } $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/ElastiCache', dimensions => $self->{aws_dimensions}, metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/elasticache/mode/items.pm b/cloud/aws/elasticache/mode/items.pm index 110b0bdd8..3ae1a85e2 100644 --- a/cloud/aws/elasticache/mode/items.pm +++ b/cloud/aws/elasticache/mode/items.pm @@ -179,13 +179,12 @@ sub manage_selection { push @{$self->{aws_dimensions}}, { Name => 'CacheNodeId', Value => $self->{option_results}->{node_id} }; } $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/ElastiCache', dimensions => $self->{aws_dimensions}, metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/elasticache/mode/network.pm b/cloud/aws/elasticache/mode/network.pm index 5d5e755a3..66f7a7da9 100644 --- a/cloud/aws/elasticache/mode/network.pm +++ b/cloud/aws/elasticache/mode/network.pm @@ -169,13 +169,12 @@ sub manage_selection { push @{$self->{aws_dimensions}}, { Name => 'CacheNodeId', Value => $self->{option_results}->{node_id} }; } $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/ElastiCache', dimensions => $self->{aws_dimensions}, metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/elasticache/mode/replication.pm b/cloud/aws/elasticache/mode/replication.pm index 8077dbfec..2d38a350f 100644 --- a/cloud/aws/elasticache/mode/replication.pm +++ b/cloud/aws/elasticache/mode/replication.pm @@ -184,13 +184,12 @@ sub manage_selection { push @{$self->{aws_dimensions}}, { Name => 'CacheNodeId', Value => $self->{option_results}->{node_id} }; } $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/ElastiCache', dimensions => $self->{aws_dimensions}, metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/elasticache/mode/requestsmemcached.pm b/cloud/aws/elasticache/mode/requestsmemcached.pm index e2c41846f..0bbe28933 100644 --- a/cloud/aws/elasticache/mode/requestsmemcached.pm +++ b/cloud/aws/elasticache/mode/requestsmemcached.pm @@ -169,13 +169,12 @@ sub manage_selection { push @{$self->{aws_dimensions}}, { Name => 'CacheNodeId', Value => $self->{option_results}->{node_id} }; } $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/ElastiCache', dimensions => $self->{aws_dimensions}, metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/elasticache/mode/requestsredis.pm b/cloud/aws/elasticache/mode/requestsredis.pm index c8c2b8eda..abdd51712 100644 --- a/cloud/aws/elasticache/mode/requestsredis.pm +++ b/cloud/aws/elasticache/mode/requestsredis.pm @@ -167,13 +167,12 @@ sub manage_selection { push @{$self->{aws_dimensions}}, { Name => 'CacheNodeId', Value => $self->{option_results}->{node_id} }; } $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/ElastiCache', dimensions => $self->{aws_dimensions}, metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/elasticache/mode/usagememcached.pm b/cloud/aws/elasticache/mode/usagememcached.pm index 5ec41f09f..be20b4935 100644 --- a/cloud/aws/elasticache/mode/usagememcached.pm +++ b/cloud/aws/elasticache/mode/usagememcached.pm @@ -120,13 +120,12 @@ sub manage_selection { push @{$self->{aws_dimensions}}, { Name => 'CacheNodeId', Value => $self->{option_results}->{node_id} }; } $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/ElastiCache', dimensions => $self->{aws_dimensions}, metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/elasticache/mode/usageredis.pm b/cloud/aws/elasticache/mode/usageredis.pm index cb9ba8faa..9073bf231 100644 --- a/cloud/aws/elasticache/mode/usageredis.pm +++ b/cloud/aws/elasticache/mode/usageredis.pm @@ -120,13 +120,12 @@ sub manage_selection { push @{$self->{aws_dimensions}}, { Name => 'CacheNodeId', Value => $self->{option_results}->{node_id} }; } $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/ElastiCache', dimensions => $self->{aws_dimensions}, metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/elb/application/mode/connections.pm b/cloud/aws/elb/application/mode/connections.pm index 0147f4451..80c3e5e66 100644 --- a/cloud/aws/elb/application/mode/connections.pm +++ b/cloud/aws/elb/application/mode/connections.pm @@ -171,7 +171,6 @@ sub manage_selection { push @{$self->{aws_dimensions}}, { Name => 'AvailabilityZone', Value => $self->{option_results}->{availability_zone} }; } $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/ApplicationELB', dimensions => $self->{aws_dimensions}, metrics => $self->{aws_metrics}, diff --git a/cloud/aws/elb/application/mode/discovery.pm b/cloud/aws/elb/application/mode/discovery.pm index eefd51dc9..3a8b94481 100644 --- a/cloud/aws/elb/application/mode/discovery.pm +++ b/cloud/aws/elb/application/mode/discovery.pm @@ -52,7 +52,6 @@ sub run { $disco_stats->{start_time} = time(); my $load_balancers = $options{custom}->discovery( - region => $self->{option_results}->{region}, service => 'elbv2', command => 'describe-load-balancers' ); diff --git a/cloud/aws/elb/application/mode/httpcodes.pm b/cloud/aws/elb/application/mode/httpcodes.pm index 77989d102..a16b4d505 100644 --- a/cloud/aws/elb/application/mode/httpcodes.pm +++ b/cloud/aws/elb/application/mode/httpcodes.pm @@ -185,7 +185,6 @@ sub manage_selection { push @{$self->{aws_dimensions}}, { Name => 'AvailabilityZone', Value => $self->{option_results}->{availability_zone} }; } $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/ApplicationELB', dimensions => $self->{aws_dimensions}, metrics => $self->{aws_metrics}, diff --git a/cloud/aws/elb/application/mode/targetshealth.pm b/cloud/aws/elb/application/mode/targetshealth.pm index e2c55ae99..f2f8fbf02 100644 --- a/cloud/aws/elb/application/mode/targetshealth.pm +++ b/cloud/aws/elb/application/mode/targetshealth.pm @@ -161,13 +161,12 @@ sub manage_selection { push @{$self->{aws_dimensions}}, { Name => 'AvailabilityZone', Value => $self->{option_results}->{availability_zone} }; } $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/ApplicationELB', dimensions => $self->{aws_dimensions}, metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/elb/classic/mode/discovery.pm b/cloud/aws/elb/classic/mode/discovery.pm index 7148823f9..0c96d8033 100644 --- a/cloud/aws/elb/classic/mode/discovery.pm +++ b/cloud/aws/elb/classic/mode/discovery.pm @@ -52,7 +52,6 @@ sub run { $disco_stats->{start_time} = time(); my $load_balancers = $options{custom}->discovery( - region => $self->{option_results}->{region}, service => 'elb', command => 'describe-load-balancers' ); diff --git a/cloud/aws/elb/classic/mode/httpcodes.pm b/cloud/aws/elb/classic/mode/httpcodes.pm index 4b4bda977..de59eca37 100644 --- a/cloud/aws/elb/classic/mode/httpcodes.pm +++ b/cloud/aws/elb/classic/mode/httpcodes.pm @@ -201,7 +201,6 @@ sub manage_selection { push @{$self->{aws_dimensions}}, { Name => 'AvailabilityZone', Value => $self->{option_results}->{availability_zone} }; } $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/ELB', dimensions => $self->{aws_dimensions}, metrics => $self->{aws_metrics}, diff --git a/cloud/aws/elb/classic/mode/performances.pm b/cloud/aws/elb/classic/mode/performances.pm index 7d3d3452d..4c6c92701 100644 --- a/cloud/aws/elb/classic/mode/performances.pm +++ b/cloud/aws/elb/classic/mode/performances.pm @@ -176,7 +176,6 @@ sub manage_selection { push @{$self->{aws_dimensions}}, { Name => 'AvailabilityZone', Value => $self->{option_results}->{availability_zone} }; } $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/ELB', dimensions => $self->{aws_dimensions}, metrics => $self->{aws_metrics}, diff --git a/cloud/aws/elb/classic/mode/queues.pm b/cloud/aws/elb/classic/mode/queues.pm index de6fee464..6d44ec91f 100644 --- a/cloud/aws/elb/classic/mode/queues.pm +++ b/cloud/aws/elb/classic/mode/queues.pm @@ -177,7 +177,6 @@ sub manage_selection { push @{$self->{aws_dimensions}}, { Name => 'AvailabilityZone', Value => $self->{option_results}->{availability_zone} }; } $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/ELB', dimensions => $self->{aws_dimensions}, metrics => $self->{aws_metrics}, diff --git a/cloud/aws/elb/classic/mode/targetshealth.pm b/cloud/aws/elb/classic/mode/targetshealth.pm index 4c9b4f5ba..b4ef4e12d 100644 --- a/cloud/aws/elb/classic/mode/targetshealth.pm +++ b/cloud/aws/elb/classic/mode/targetshealth.pm @@ -177,7 +177,6 @@ sub manage_selection { push @{$self->{aws_dimensions}}, { Name => 'AvailabilityZone', Value => $self->{option_results}->{availability_zone} }; } $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/ELB', dimensions => $self->{aws_dimensions}, metrics => $self->{aws_metrics}, diff --git a/cloud/aws/elb/network/mode/discovery.pm b/cloud/aws/elb/network/mode/discovery.pm index 4ec7a4a2a..90956df51 100644 --- a/cloud/aws/elb/network/mode/discovery.pm +++ b/cloud/aws/elb/network/mode/discovery.pm @@ -52,7 +52,6 @@ sub run { $disco_stats->{start_time} = time(); my $load_balancers = $options{custom}->discovery( - region => $self->{option_results}->{region}, service => 'elbv2', command => 'describe-load-balancers' ); diff --git a/cloud/aws/elb/network/mode/targetshealth.pm b/cloud/aws/elb/network/mode/targetshealth.pm index 8a9734588..526d30dbb 100644 --- a/cloud/aws/elb/network/mode/targetshealth.pm +++ b/cloud/aws/elb/network/mode/targetshealth.pm @@ -156,7 +156,6 @@ sub manage_selection { push @{$self->{aws_dimensions}}, { Name => 'AvailabilityZone', Value => $self->{option_results}->{availability_zone} }; } $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/ApplicationELB', dimensions => $self->{aws_dimensions}, metrics => $self->{aws_metrics}, diff --git a/cloud/aws/health/mode/events.pm b/cloud/aws/health/mode/events.pm index ab85e37ff..146afd632 100644 --- a/cloud/aws/health/mode/events.pm +++ b/cloud/aws/health/mode/events.pm @@ -99,7 +99,7 @@ sub check_options { $self->{filter_options}->{'filter_' . $_} = undef; if (defined($self->{option_results}->{'filter_' . $_})) { foreach my $option (@{$self->{option_results}->{'filter_' . $_}}) { - next if ($options eq ''); + next if ($option eq ''); $self->{filter_options}->{'filter_' . $_} = [] if (!defined($self->{'filter_' . $_})); push @{$self->{filter_options}->{'filter_' . $_}}, $option; @@ -116,18 +116,41 @@ sub manage_selection { ); $self->{global} = { total => 0, open => 0, closed => 0, upcoming => 0 }; + my $events = {}; foreach my $entry (@$results) { $self->{global}->{ lc($entry->{statusCode}) }++; $self->{global}->{total}++; + $events->{ $entry->{arn} } = $entry; + } + + 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); + } + + foreach (@event_arns) { + my $entity = ''; + if (defined($affected_entities)) { + $entity = '[affected entity: -]'; + foreach my $affected (@$affected_entities) { + if ($events->{$_}->{arn} eq $affected->{eventArn}) { + $entity = '[affected entity: ' . $affected->{entityValue} . ']'; + last; + } + } + } + $self->{output}->output_add(long_msg => sprintf( - '[service: %s][region: %s][status: %s][type: %s][start: %s]', - $entry->{service}, - $entry->{region}, - $entry->{statusCode}, - $entry->{eventTypeCode}, - $entry->{startTime} + '[service: %s][region: %s][status: %s][type: %s][start: %s]%s', + $events->{$_}->{service}, + $events->{$_}->{region}, + $events->{$_}->{statusCode}, + $events->{$_}->{eventTypeCode}, + $events->{$_}->{startTime}, + $entity ) ); } diff --git a/cloud/aws/health/plugin.pm b/cloud/aws/health/plugin.pm index e1252dd3f..a99bab51f 100644 --- a/cloud/aws/health/plugin.pm +++ b/cloud/aws/health/plugin.pm @@ -34,6 +34,11 @@ sub new { 'events' => 'cloud::aws::health::mode::events' }; + $self->{customdefault} = { + paws => { region => 'us-east-1' }, + awscli => { region => 'us-east-1' } + }; + $self->{custom_modes}->{paws} = 'cloud::aws::custom::paws'; $self->{custom_modes}->{awscli} = 'cloud::aws::custom::awscli'; return $self; diff --git a/cloud/aws/kinesis/mode/discovery.pm b/cloud/aws/kinesis/mode/discovery.pm index 5e68e9539..a89a5adf4 100644 --- a/cloud/aws/kinesis/mode/discovery.pm +++ b/cloud/aws/kinesis/mode/discovery.pm @@ -52,7 +52,6 @@ sub run { $disco_stats->{start_time} = time(); my $streams = $options{custom}->discovery( - region => $self->{option_results}->{region}, service => 'kinesis', command => 'list-streams' ); diff --git a/cloud/aws/kinesis/mode/recordsstats.pm b/cloud/aws/kinesis/mode/recordsstats.pm index 7744334eb..0ad59afa6 100644 --- a/cloud/aws/kinesis/mode/recordsstats.pm +++ b/cloud/aws/kinesis/mode/recordsstats.pm @@ -180,7 +180,6 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/Kinesis', dimensions => [ { Name => 'StreamName', Value => $instance } ], metrics => $self->{aws_metrics}, diff --git a/cloud/aws/kinesis/mode/streams.pm b/cloud/aws/kinesis/mode/streams.pm index 8a00ebae2..820dfd729 100644 --- a/cloud/aws/kinesis/mode/streams.pm +++ b/cloud/aws/kinesis/mode/streams.pm @@ -156,7 +156,6 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/Kinesis', dimensions => [ { Name => 'StreamName', Value => $instance } ], metrics => $self->{aws_metrics}, diff --git a/cloud/aws/lambda/mode/invocations.pm b/cloud/aws/lambda/mode/invocations.pm index 586485997..49507a00e 100644 --- a/cloud/aws/lambda/mode/invocations.pm +++ b/cloud/aws/lambda/mode/invocations.pm @@ -160,13 +160,12 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/Lambda', dimensions => [ { Name => 'FunctionName', Value => $instance } ], metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/rds/mode/connections.pm b/cloud/aws/rds/mode/connections.pm index 3a7ed2d4a..448c2e024 100644 --- a/cloud/aws/rds/mode/connections.pm +++ b/cloud/aws/rds/mode/connections.pm @@ -126,13 +126,12 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/RDS', dimensions => [ { Name => $map_type{$self->{option_results}->{type}}, Value => $instance } ], metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/rds/mode/cpu.pm b/cloud/aws/rds/mode/cpu.pm index a4681964f..a61dc45c1 100644 --- a/cloud/aws/rds/mode/cpu.pm +++ b/cloud/aws/rds/mode/cpu.pm @@ -138,13 +138,12 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/RDS', dimensions => [ { Name => $map_type{$self->{option_results}->{type}}, Value => $instance } ], metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/rds/mode/discovery.pm b/cloud/aws/rds/mode/discovery.pm index 360e55dbf..6fa2b84bd 100644 --- a/cloud/aws/rds/mode/discovery.pm +++ b/cloud/aws/rds/mode/discovery.pm @@ -52,7 +52,6 @@ sub run { $disco_stats->{start_time} = time(); my $db_instances = $options{custom}->discovery( - region => $self->{option_results}->{region}, service => 'rds', command => 'describe-db-instances' ); diff --git a/cloud/aws/rds/mode/diskio.pm b/cloud/aws/rds/mode/diskio.pm index 86fb0e9af..45b1b188e 100644 --- a/cloud/aws/rds/mode/diskio.pm +++ b/cloud/aws/rds/mode/diskio.pm @@ -164,7 +164,6 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/RDS', dimensions => [ { Name => $map_type{$self->{option_results}->{type}}, Value => $instance } ], metrics => $self->{aws_metrics}, diff --git a/cloud/aws/rds/mode/instancestatus.pm b/cloud/aws/rds/mode/instancestatus.pm index e2fc227a6..8aa73a329 100644 --- a/cloud/aws/rds/mode/instancestatus.pm +++ b/cloud/aws/rds/mode/instancestatus.pm @@ -118,13 +118,12 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-instanceid:s" => { name => 'filter_instanceid' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, - }); - + $options{options}->add_options(arguments => { + "filter-instanceid:s" => { name => 'filter_instanceid' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '' }, + }); + return $self; } @@ -132,11 +131,6 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - if (!defined($self->{option_results}->{region}) || $self->{option_results}->{region} eq '') { - $self->{output}->add_option_msg(short_msg => "Need to specify --region option."); - $self->{output}->option_exit(); - } - $self->change_macros(macros => ['warning_status', 'critical_status']); } @@ -159,7 +153,7 @@ sub manage_selection { available => 0, 'backing-up' => 0, failed => 0, maintenance => 0, stopped => 0, 'storage-full' => 0, }; $self->{aws_instances} = {}; - my $result = $options{custom}->rds_get_instances_status(region => $self->{option_results}->{region}); + my $result = $options{custom}->rds_get_instances_status(); foreach my $instance_id (keys %{$result}) { if (defined($self->{option_results}->{filter_instanceid}) && $self->{option_results}->{filter_instanceid} ne '' && $instance_id !~ /$self->{option_results}->{filter_instanceid}/) { diff --git a/cloud/aws/rds/mode/listclusters.pm b/cloud/aws/rds/mode/listclusters.pm index 2acff06ec..8920fe038 100644 --- a/cloud/aws/rds/mode/listclusters.pm +++ b/cloud/aws/rds/mode/listclusters.pm @@ -45,7 +45,7 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - $self->{instances} = $options{custom}->rds_list_clusters(region => $self->{option_results}->{region}); + $self->{instances} = $options{custom}->rds_list_clusters(); } sub run { diff --git a/cloud/aws/rds/mode/listinstances.pm b/cloud/aws/rds/mode/listinstances.pm index 522e64cae..00ba8a65c 100644 --- a/cloud/aws/rds/mode/listinstances.pm +++ b/cloud/aws/rds/mode/listinstances.pm @@ -45,7 +45,7 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - $self->{instances} = $options{custom}->rds_list_instances(region => $self->{option_results}->{region}); + $self->{instances} = $options{custom}->rds_list_instances(); } sub run { diff --git a/cloud/aws/rds/mode/network.pm b/cloud/aws/rds/mode/network.pm index 0612c7096..a487c00e0 100644 --- a/cloud/aws/rds/mode/network.pm +++ b/cloud/aws/rds/mode/network.pm @@ -127,7 +127,6 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/RDS', dimensions => [ { Name => $map_type{$self->{option_results}->{type}}, Value => $instance } ], metrics => $self->{aws_metrics}, diff --git a/cloud/aws/rds/mode/queries.pm b/cloud/aws/rds/mode/queries.pm index dd4e9de2c..088ce8e51 100644 --- a/cloud/aws/rds/mode/queries.pm +++ b/cloud/aws/rds/mode/queries.pm @@ -140,7 +140,6 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/RDS', dimensions => [ { Name => $map_type{$self->{option_results}->{type}}, Value => $instance } ], metrics => $self->{aws_metrics}, diff --git a/cloud/aws/rds/mode/transactions.pm b/cloud/aws/rds/mode/transactions.pm index d78956dfc..ae5c1312c 100644 --- a/cloud/aws/rds/mode/transactions.pm +++ b/cloud/aws/rds/mode/transactions.pm @@ -138,13 +138,12 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/RDS', dimensions => [ { Name => $map_type{$self->{option_results}->{type}}, Value => $instance } ], metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/rds/mode/volume.pm b/cloud/aws/rds/mode/volume.pm index dfe3e3214..8f15cfaf5 100644 --- a/cloud/aws/rds/mode/volume.pm +++ b/cloud/aws/rds/mode/volume.pm @@ -187,13 +187,12 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/RDS', dimensions => [ { Name => $map_type{$self->{option_results}->{type}}, Value => $instance } , { Name => 'EngineName', Value => 'aurora' } ], metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/s3/mode/bucketsize.pm b/cloud/aws/s3/mode/bucketsize.pm index ac679e550..500fcdcc4 100644 --- a/cloud/aws/s3/mode/bucketsize.pm +++ b/cloud/aws/s3/mode/bucketsize.pm @@ -124,13 +124,12 @@ sub manage_selection { foreach my $instance (@{$self->{aws_instance}}) { foreach my $storage_type (@{$self->{aws_storage_type}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/S3', dimensions => [ {Name => 'StorageType', Value => $storage_type }, { Name => 'BucketName', Value => $instance } ], metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/s3/mode/discovery.pm b/cloud/aws/s3/mode/discovery.pm index 41f169f06..87fa02110 100644 --- a/cloud/aws/s3/mode/discovery.pm +++ b/cloud/aws/s3/mode/discovery.pm @@ -52,7 +52,6 @@ sub run { $disco_stats->{start_time} = time(); my $buckets = $options{custom}->discovery( - region => $self->{option_results}->{region}, service => 's3api', command => 'list-buckets' ); diff --git a/cloud/aws/s3/mode/objects.pm b/cloud/aws/s3/mode/objects.pm index 0912e66e5..b7f6a0a13 100644 --- a/cloud/aws/s3/mode/objects.pm +++ b/cloud/aws/s3/mode/objects.pm @@ -109,13 +109,12 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/S3', dimensions => [ {Name => 'StorageType', Value => 'AllStorageTypes' }, { Name => 'BucketName', Value => $instance } ], metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/s3/mode/requests.pm b/cloud/aws/s3/mode/requests.pm index 1c400b798..cdca62c39 100644 --- a/cloud/aws/s3/mode/requests.pm +++ b/cloud/aws/s3/mode/requests.pm @@ -59,12 +59,11 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "name:s@" => { name => 'name' }, - "filter-metric:s" => { name => 'filter_metric' }, - }); - + $options{options}->add_options(arguments => { + 'name:s@' => { name => 'name' }, + 'filter-metric:s' => { name => 'filter_metric' } + }); + return $self; } @@ -72,11 +71,6 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - if (!defined($self->{option_results}->{region}) || $self->{option_results}->{region} eq '') { - $self->{output}->add_option_msg(short_msg => "Need to specify --region option."); - $self->{output}->option_exit(); - } - if (!defined($self->{option_results}->{name}) || $self->{option_results}->{name} eq '') { $self->{output}->add_option_msg(short_msg => "Need to specify --name option."); $self->{output}->option_exit(); @@ -108,13 +102,12 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/S3', dimensions => [ { Name => 'BucketName', Value => $instance } ], metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) { diff --git a/cloud/aws/vpn/mode/listvpn.pm b/cloud/aws/vpn/mode/listvpn.pm index 6499d94e9..2fdb08b63 100644 --- a/cloud/aws/vpn/mode/listvpn.pm +++ b/cloud/aws/vpn/mode/listvpn.pm @@ -43,7 +43,7 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - $self->{connection} = $options{custom}->vpn_list_connections(region => $self->{option_results}->{region}); + $self->{connection} = $options{custom}->vpn_list_connections(); } sub run { diff --git a/cloud/aws/vpn/mode/traffic.pm b/cloud/aws/vpn/mode/traffic.pm index db56097a3..ceca71923 100644 --- a/cloud/aws/vpn/mode/traffic.pm +++ b/cloud/aws/vpn/mode/traffic.pm @@ -246,13 +246,12 @@ sub manage_selection { my %metric_results; foreach my $instance (@{$self->{aws_instance}}) { $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, namespace => 'AWS/VPN', dimensions => [ { Name => 'VpnId', Value => $instance } ], metrics => $self->{aws_metrics}, statistics => $self->{aws_statistics}, timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, + period => $self->{aws_period} ); foreach my $metric (@{$self->{aws_metrics}}) {