aws cleaning region + aws health service

This commit is contained in:
garnier-quentin 2020-07-20 15:10:46 +02:00
parent 8758a19a02
commit c62568ff60
81 changed files with 295 additions and 217 deletions

View File

@ -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'
);

View File

@ -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)})

View File

@ -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},

View File

@ -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 },

View File

@ -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'
);
}

View File

@ -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;
}

View File

@ -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},

View File

@ -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},

View File

@ -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}}) {

View File

@ -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})) {

View File

@ -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},

View File

@ -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}
);

View File

@ -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__

View File

@ -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__

View File

@ -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'
);

View File

@ -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 {

View File

@ -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}}) {

View File

@ -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}}) {

View File

@ -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}}) {

View File

@ -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;

View File

@ -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},

View File

@ -55,7 +55,6 @@ sub run {
my %asgs;
my $instances = $options{custom}->discovery(
region => $self->{option_results}->{region},
service => 'ec2',
command => 'describe-instances'
);

View File

@ -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}}) {

View File

@ -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},

View File

@ -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}/) {

View File

@ -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/));

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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},

View File

@ -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}++;

View File

@ -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},

View File

@ -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}}) {

View File

@ -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}}) {

View File

@ -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'
);

View File

@ -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}}) {

View File

@ -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}}) {

View File

@ -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}}) {

View File

@ -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}}) {

View File

@ -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}}) {

View File

@ -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}}) {

View File

@ -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}}) {

View File

@ -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}}) {

View File

@ -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}}) {

View File

@ -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}}) {

View File

@ -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}}) {

View File

@ -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}}) {

View File

@ -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},

View File

@ -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'
);

View File

@ -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},

View File

@ -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}}) {

View File

@ -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'
);

View File

@ -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},

View File

@ -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},

View File

@ -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},

View File

@ -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},

View File

@ -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'
);

View File

@ -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},

View File

@ -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
)
);
}

View File

@ -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;

View File

@ -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'
);

View File

@ -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},

View File

@ -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},

View File

@ -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}}) {

View File

@ -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}}) {

View File

@ -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}}) {

View File

@ -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'
);

View File

@ -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},

View File

@ -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}/) {

View File

@ -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 {

View File

@ -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 {

View File

@ -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},

View File

@ -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},

View File

@ -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}}) {

View File

@ -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}}) {

View File

@ -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}}) {

View File

@ -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'
);

View File

@ -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}}) {

View File

@ -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}}) {

View File

@ -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 {

View File

@ -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}}) {