mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-09-25 02:37:57 +02:00
wip: cloudwatch logs + indent
This commit is contained in:
parent
e0f26e73a0
commit
bd27affe20
@ -30,16 +30,19 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold)
|
|||||||
|
|
||||||
sub custom_status_output {
|
sub custom_status_output {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $msg = sprintf("alarm [name: %s] [state: %s] [metric: %s] [reason: %s] %s", $self->{result_values}->{alarm_name},
|
my $msg = sprintf(
|
||||||
|
'alarm [name: %s] [state: %s] [metric: %s] [reason: %s] %s',
|
||||||
|
$self->{result_values}->{alarm_name},
|
||||||
$self->{result_values}->{state_value}, $self->{result_values}->{metric_name},
|
$self->{result_values}->{state_value}, $self->{result_values}->{metric_name},
|
||||||
$self->{result_values}->{state_reason}, centreon::plugins::misc::change_seconds(value => $self->{result_values}->{last_update}));
|
$self->{result_values}->{state_reason}, centreon::plugins::misc::change_seconds(value => $self->{result_values}->{last_update})
|
||||||
|
);
|
||||||
return $msg;
|
return $msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub custom_status_calc {
|
sub custom_status_calc {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{result_values}->{alarm_name} = $options{new_datas}->{$self->{instance} . '_AlarmName'};
|
$self->{result_values}->{alarm_name} = $options{new_datas}->{$self->{instance} . '_AlarmName'};
|
||||||
$self->{result_values}->{state_value} = $options{new_datas}->{$self->{instance} . '_StateValue'};
|
$self->{result_values}->{state_value} = $options{new_datas}->{$self->{instance} . '_StateValue'};
|
||||||
$self->{result_values}->{metric_name} = $options{new_datas}->{$self->{instance} . '_MetricName'};
|
$self->{result_values}->{metric_name} = $options{new_datas}->{$self->{instance} . '_MetricName'};
|
||||||
@ -51,13 +54,13 @@ sub custom_status_calc {
|
|||||||
|
|
||||||
sub set_counters {
|
sub set_counters {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{maps_counters_type} = [
|
$self->{maps_counters_type} = [
|
||||||
{ name => 'alarms', type => 2, message_multiple => '0 problem(s) detected', display_counter_problem => { label => 'alerts', min => 0 },
|
{ name => 'alarms', type => 2, message_multiple => '0 problem(s) detected', display_counter_problem => { label => 'alerts', min => 0 },
|
||||||
group => [ { name => 'alarm', skipped_code => { -11 => 1 } } ]
|
group => [ { name => 'alarm', skipped_code => { -11 => 1 } } ]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
$self->{maps_counters}->{alarm} = [
|
$self->{maps_counters}->{alarm} = [
|
||||||
{ label => 'status', threshold => 0, set => {
|
{ label => 'status', threshold => 0, set => {
|
||||||
key_values => [ { name => 'AlarmName' }, { name => 'StateValue' }, { name => 'MetricName' }, { name => 'StateReason' }, { name => 'LastUpdate' } ],
|
key_values => [ { name => 'AlarmName' }, { name => 'StateValue' }, { name => 'MetricName' }, { name => 'StateReason' }, { name => 'LastUpdate' } ],
|
||||||
@ -74,17 +77,18 @@ sub new {
|
|||||||
my ($class, %options) = @_;
|
my ($class, %options) = @_;
|
||||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$options{options}->add_options(arguments =>
|
$options{options}->add_options(arguments => {
|
||||||
{
|
'filter-alarm-name:s' => { name => 'filter_alarm_name' },
|
||||||
"filter-alarm-name:s" => { name => 'filter_alarm_name' },
|
'warning-status:s' => { name => 'warning_status', default => '%{state_value} =~ /INSUFFICIENT_DATA/i' },
|
||||||
"warning-status:s" => { name => 'warning_status', default => '%{state_value} =~ /INSUFFICIENT_DATA/i' },
|
'critical-status:s' => { name => 'critical_status', default => '%{state_value} =~ /ALARM/i' },
|
||||||
"critical-status:s" => { name => 'critical_status', default => '%{state_value} =~ /ALARM/i' },
|
'memory' => { name => 'memory' },
|
||||||
"memory" => { name => 'memory' },
|
});
|
||||||
});
|
|
||||||
|
centreon::plugins::misc::mymodule_load(
|
||||||
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Date::Parse',
|
output => $self->{output}, module => 'Date::Parse',
|
||||||
error_msg => "Cannot load module 'Date::Parse'.");
|
error_msg => "Cannot load module 'Date::Parse'."
|
||||||
|
);
|
||||||
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
|
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
@ -94,7 +98,6 @@ sub check_options {
|
|||||||
$self->SUPER::check_options(%options);
|
$self->SUPER::check_options(%options);
|
||||||
|
|
||||||
$self->change_macros(macros => ['warning_status', 'critical_status']);
|
$self->change_macros(macros => ['warning_status', 'critical_status']);
|
||||||
|
|
||||||
if (defined($self->{option_results}->{memory})) {
|
if (defined($self->{option_results}->{memory})) {
|
||||||
$self->{statefile_cache}->check_options(%options);
|
$self->{statefile_cache}->check_options(%options);
|
||||||
}
|
}
|
||||||
@ -107,43 +110,45 @@ sub manage_selection {
|
|||||||
my $alarm_results = $options{custom}->cloudwatch_get_alarms(
|
my $alarm_results = $options{custom}->cloudwatch_get_alarms(
|
||||||
region => $self->{option_results}->{region},
|
region => $self->{option_results}->{region},
|
||||||
);
|
);
|
||||||
|
|
||||||
my $last_time;
|
my $last_time;
|
||||||
if (defined($self->{option_results}->{memory})) {
|
if (defined($self->{option_results}->{memory})) {
|
||||||
$self->{statefile_cache}->read(statefile => 'cache_aws_' . $self->{mode} . '_' . $self->{option_results}->{region});
|
$self->{statefile_cache}->read(statefile => 'cache_aws_' . $self->{mode} . '_' . $self->{option_results}->{region});
|
||||||
$last_time = $self->{statefile_cache}->get(name => 'last_time');
|
$last_time = $self->{statefile_cache}->get(name => 'last_time');
|
||||||
}
|
}
|
||||||
|
|
||||||
my ($i, $current_time) = (1, time());
|
my ($i, $current_time) = (1, time());
|
||||||
foreach my $alarm (@{$alarm_results}) {
|
foreach my $alarm (@{$alarm_results}) {
|
||||||
my $create_time = Date::Parse::str2time($alarm->{StateUpdatedTimestamp});
|
my $create_time = Date::Parse::str2time($alarm->{StateUpdatedTimestamp});
|
||||||
if (!defined($create_time)) {
|
if (!defined($create_time)) {
|
||||||
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
|
$self->{manager}->{output}->output_add(
|
||||||
short_msg => "Can't Parse date '" . $alarm->{StateUpdatedTimestamp} . "'");
|
severity => 'UNKNOWN',
|
||||||
|
short_msg => "Can't Parse date '" . $alarm->{StateUpdatedTimestamp} . "'"
|
||||||
|
);
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
next if (defined($self->{option_results}->{memory}) && defined($last_time) && $last_time > $create_time);
|
next if (defined($self->{option_results}->{memory}) && defined($last_time) && $last_time > $create_time);
|
||||||
if (defined($self->{option_results}->{filter_alarm_name}) && $self->{option_results}->{filter_alarm_name} ne '' &&
|
if (defined($self->{option_results}->{filter_alarm_name}) && $self->{option_results}->{filter_alarm_name} ne '' &&
|
||||||
$alarm->{AlarmName} !~ /$self->{option_results}->{filter_alarm_name}/) {
|
$alarm->{AlarmName} !~ /$self->{option_results}->{filter_alarm_name}/) {
|
||||||
$self->{output}->output_add(long_msg => "skipping '" . $alarm->{AlarmName} . "': no matching filter.", debug => 1);
|
$self->{output}->output_add(long_msg => "skipping '" . $alarm->{AlarmName} . "': no matching filter.", debug => 1);
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $diff_time = $current_time - $create_time;
|
my $diff_time = $current_time - $create_time;
|
||||||
|
|
||||||
$self->{alarms}->{global}->{alarm}->{$i} = {
|
$self->{alarms}->{global}->{alarm}->{$i} = {
|
||||||
%$alarm,
|
%$alarm,
|
||||||
LastUpdate => $diff_time,
|
LastUpdate => $diff_time,
|
||||||
};
|
};
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined($self->{option_results}->{memory})) {
|
if (defined($self->{option_results}->{memory})) {
|
||||||
$self->{statefile_cache}->write(data => { last_time => $current_time });
|
$self->{statefile_cache}->write(data => { last_time => $current_time });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
__END__
|
__END__
|
||||||
|
@ -28,20 +28,24 @@ use warnings;
|
|||||||
sub custom_metric_perfdata {
|
sub custom_metric_perfdata {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{output}->perfdata_add(label => $self->{result_values}->{perf_label},
|
$self->{output}->perfdata_add(
|
||||||
value => $self->{result_values}->{value},
|
label => $self->{result_values}->{perf_label},
|
||||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-metric'),
|
value => $self->{result_values}->{value},
|
||||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-metric'),
|
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-metric'),
|
||||||
);
|
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-metric'),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub custom_metric_threshold {
|
sub custom_metric_threshold {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{value},
|
my $exit = $self->{perfdata}->threshold_check(
|
||||||
threshold => [ { label => 'critical-metric', exit_litteral => 'critical' },
|
value => $self->{result_values}->{value},
|
||||||
{ label => 'warning-metric', exit_litteral => 'warning' } ]);
|
threshold => [
|
||||||
|
{ label => 'critical-metric', exit_litteral => 'critical' },
|
||||||
|
{ label => 'warning-metric', exit_litteral => 'warning' }
|
||||||
|
]
|
||||||
|
);
|
||||||
return $exit;
|
return $exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,14 +90,13 @@ sub new {
|
|||||||
my ($class, %options) = @_;
|
my ($class, %options) = @_;
|
||||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$options{options}->add_options(arguments =>
|
$options{options}->add_options(arguments => {
|
||||||
{
|
'namespace:s' => { name => 'namespace' },
|
||||||
"namespace:s" => { name => 'namespace' },
|
'dimension:s%' => { name => 'dimension' },
|
||||||
"dimension:s%" => { name => 'dimension' },
|
'metric:s@' => { name => 'metric' },
|
||||||
"metric:s@" => { name => 'metric' },
|
});
|
||||||
});
|
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +108,7 @@ sub check_options {
|
|||||||
$self->{output}->add_option_msg(short_msg => "Need to specify --namespace option.");
|
$self->{output}->add_option_msg(short_msg => "Need to specify --namespace option.");
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{aws_metrics} = [];
|
$self->{aws_metrics} = [];
|
||||||
if (defined($self->{option_results}->{metric})) {
|
if (defined($self->{option_results}->{metric})) {
|
||||||
$self->{aws_metrics} = [@{$self->{option_results}->{metric}}];
|
$self->{aws_metrics} = [@{$self->{option_results}->{metric}}];
|
||||||
@ -114,7 +117,7 @@ sub check_options {
|
|||||||
$self->{output}->add_option_msg(short_msg => "Need to specify --metric option.");
|
$self->{output}->add_option_msg(short_msg => "Need to specify --metric option.");
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{dimension_name} = '';
|
$self->{dimension_name} = '';
|
||||||
my $append = '';
|
my $append = '';
|
||||||
$self->{aws_dimensions} = [];
|
$self->{aws_dimensions} = [];
|
||||||
@ -132,7 +135,7 @@ sub check_options {
|
|||||||
|
|
||||||
$self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 600;
|
$self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 600;
|
||||||
$self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 60;
|
$self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 60;
|
||||||
|
|
||||||
$self->{aws_statistics} = ['Average'];
|
$self->{aws_statistics} = ['Average'];
|
||||||
if (defined($self->{option_results}->{statistic})) {
|
if (defined($self->{option_results}->{statistic})) {
|
||||||
$self->{aws_statistics} = [];
|
$self->{aws_statistics} = [];
|
||||||
@ -142,7 +145,7 @@ sub check_options {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach my $metric_name ($self->{aws_metrics}) {
|
foreach my $metric_name ($self->{aws_metrics}) {
|
||||||
foreach my $statistic ($self->{aws_statistics}) {
|
foreach my $statistic ($self->{aws_statistics}) {
|
||||||
my $entry = { label => lc($metric_name) . '-' . $statistic, set => {
|
my $entry = { label => lc($metric_name) . '-' . $statistic, set => {
|
||||||
@ -161,7 +164,7 @@ sub check_options {
|
|||||||
|
|
||||||
sub manage_selection {
|
sub manage_selection {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $metric_results = $options{custom}->cloudwatch_get_metrics(
|
my $metric_results = $options{custom}->cloudwatch_get_metrics(
|
||||||
region => $self->{option_results}->{region},
|
region => $self->{option_results}->{region},
|
||||||
namespace => $self->{option_results}->{namespace},
|
namespace => $self->{option_results}->{namespace},
|
||||||
@ -171,7 +174,7 @@ sub manage_selection {
|
|||||||
timeframe => $self->{aws_timeframe},
|
timeframe => $self->{aws_timeframe},
|
||||||
period => $self->{aws_period},
|
period => $self->{aws_period},
|
||||||
);
|
);
|
||||||
|
|
||||||
$self->{metrics} = {};
|
$self->{metrics} = {};
|
||||||
foreach my $label (keys %{$metric_results}) {
|
foreach my $label (keys %{$metric_results}) {
|
||||||
foreach my $stat (('minimum', 'maximum', 'average', 'sum')) {
|
foreach my $stat (('minimum', 'maximum', 'average', 'sum')) {
|
||||||
|
@ -29,12 +29,11 @@ sub new {
|
|||||||
my ($class, %options) = @_;
|
my ($class, %options) = @_;
|
||||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$options{options}->add_options(arguments =>
|
$options{options}->add_options(arguments => {
|
||||||
{
|
'namespace:s' => { name => 'namespace' },
|
||||||
"namespace:s" => { name => 'namespace' },
|
'metric:s' => { name => 'metric' },
|
||||||
"metric:s" => { name => 'metric' },
|
});
|
||||||
});
|
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
@ -47,21 +46,23 @@ sub check_options {
|
|||||||
sub manage_selection {
|
sub manage_selection {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{metrics} = $options{custom}->cloudwatch_list_metrics(region => $self->{option_results}->{region},
|
$self->{metrics} = $options{custom}->cloudwatch_list_metrics(
|
||||||
namespace => $self->{option_results}->{namespace},
|
region => $self->{option_results}->{region},
|
||||||
metric => $self->{option_results}->{metric});
|
namespace => $self->{option_results}->{namespace},
|
||||||
|
metric => $self->{option_results}->{metric}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_dimensions_str {
|
sub get_dimensions_str {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $dimensions = '';
|
my $dimensions = '';
|
||||||
my $append = '';
|
my $append = '';
|
||||||
foreach (@{$options{dimensions}}) {
|
foreach (@{$options{dimensions}}) {
|
||||||
$dimensions .= $append . "Name=$_->{Name},Value=$_->{Value}";
|
$dimensions .= $append . "Name=$_->{Name},Value=$_->{Value}";
|
||||||
$append = ',';
|
$append = ',';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $dimensions;
|
return $dimensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,16 +74,18 @@ sub run {
|
|||||||
$self->{output}->output_add(long_msg => sprintf("[Namespace = %s][Dimensions = %s][Metric = %s]",
|
$self->{output}->output_add(long_msg => sprintf("[Namespace = %s][Dimensions = %s][Metric = %s]",
|
||||||
$_->{Namespace}, $self->get_dimensions_str(dimensions => $_->{Dimensions}), $_->{MetricName}));
|
$_->{Namespace}, $self->get_dimensions_str(dimensions => $_->{Dimensions}), $_->{MetricName}));
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{output}->output_add(severity => 'OK',
|
$self->{output}->output_add(
|
||||||
short_msg => 'List metrics:');
|
severity => 'OK',
|
||||||
|
short_msg => 'List metrics:'
|
||||||
|
);
|
||||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||||
$self->{output}->exit();
|
$self->{output}->exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
sub disco_format {
|
sub disco_format {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{output}->add_disco_format(elements => ['namespace', 'metric', 'dimensions']);
|
$self->{output}->add_disco_format(elements => ['namespace', 'metric', 'dimensions']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
103
cloud/aws/cloudwatchlogs/mode/listgroups.pm
Normal file
103
cloud/aws/cloudwatchlogs/mode/listgroups.pm
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
#
|
||||||
|
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||||
|
#
|
||||||
|
# Centreon is a full-fledged industry-strength solution that meets
|
||||||
|
# the needs in IT infrastructure and application monitoring for
|
||||||
|
# service performance.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
package cloud::aws::cloudwatchlogs::mode::listgroups;
|
||||||
|
|
||||||
|
use base qw(centreon::plugins::mode);
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
sub new {
|
||||||
|
my ($class, %options) = @_;
|
||||||
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||||
|
bless $self, $class;
|
||||||
|
|
||||||
|
$options{options}->add_options(arguments => {
|
||||||
|
});
|
||||||
|
|
||||||
|
return $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub check_options {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
$self->SUPER::init(%options);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub manage_selection {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
return $options{custom}->cloudwatchlogs_describe_log_groups(
|
||||||
|
region => $self->{option_results}->{region}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub run {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $log_groups = $self->manage_selection(%options);
|
||||||
|
foreach (@$log_groups) {
|
||||||
|
$self->{output}->output_add(
|
||||||
|
long_msg => sprintf(
|
||||||
|
'[group name = %s]',
|
||||||
|
$_->{logGroupName}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->{output}->output_add(
|
||||||
|
severity => 'OK',
|
||||||
|
short_msg => 'List log groups:'
|
||||||
|
);
|
||||||
|
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||||
|
$self->{output}->exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
sub disco_format {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
$self->{output}->add_disco_format(elements => ['group_name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub disco_show {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $log_groups = $self->manage_selection(%options);
|
||||||
|
foreach (@$log_groups) {
|
||||||
|
$self->{output}->add_disco_entry(
|
||||||
|
group_name => $_->{logGroupName}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
__END__
|
||||||
|
|
||||||
|
=head1 MODE
|
||||||
|
|
||||||
|
List cloudwatch logs groups.
|
||||||
|
|
||||||
|
=over 8
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
50
cloud/aws/cloudwatchlogs/plugin.pm
Normal file
50
cloud/aws/cloudwatchlogs/plugin.pm
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#
|
||||||
|
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||||
|
#
|
||||||
|
# Centreon is a full-fledged industry-strength solution that meets
|
||||||
|
# the needs in IT infrastructure and application monitoring for
|
||||||
|
# service performance.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
package cloud::aws::cloudwatchlogs::plugin;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use base qw(centreon::plugins::script_custom);
|
||||||
|
|
||||||
|
sub new {
|
||||||
|
my ( $class, %options ) = @_;
|
||||||
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||||
|
bless $self, $class;
|
||||||
|
|
||||||
|
$self->{version} = '0.1';
|
||||||
|
%{ $self->{modes} } = (
|
||||||
|
'list-groups' => 'cloud::aws::cloudwatchlogs::mode::listgroups',
|
||||||
|
);
|
||||||
|
|
||||||
|
$self->{custom_modes}{paws} = 'cloud::aws::custom::paws';
|
||||||
|
$self->{custom_modes}{awscli} = 'cloud::aws::custom::awscli';
|
||||||
|
return $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
__END__
|
||||||
|
|
||||||
|
=head1 PLUGIN DESCRIPTION
|
||||||
|
|
||||||
|
Check Amazon CloudWatchLogs.
|
||||||
|
|
||||||
|
=cut
|
@ -38,7 +38,7 @@ sub new {
|
|||||||
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
|
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
|
||||||
$options{output}->option_exit();
|
$options{output}->option_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!defined($options{noptions})) {
|
if (!defined($options{noptions})) {
|
||||||
$options{options}->add_options(arguments => {
|
$options{options}->add_options(arguments => {
|
||||||
'aws-secret-key:s' => { name => 'aws_secret_key' },
|
'aws-secret-key:s' => { name => 'aws_secret_key' },
|
||||||
@ -62,7 +62,7 @@ sub new {
|
|||||||
|
|
||||||
$self->{output} = $options{output};
|
$self->{output} = $options{output};
|
||||||
$self->{mode} = $options{mode};
|
$self->{mode} = $options{mode};
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,12 +127,12 @@ sub check_options {
|
|||||||
|
|
||||||
sub execute {
|
sub execute {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $cmd_options = $options{cmd_options};
|
my $cmd_options = $options{cmd_options};
|
||||||
$cmd_options .= " --debug" if ($self->{output}->is_debug());
|
$cmd_options .= " --debug" if ($self->{output}->is_debug());
|
||||||
|
|
||||||
$self->{output}->output_add(long_msg => "Command line: '" . $self->{option_results}->{command} . " " . $cmd_options . "'", debug => 1);
|
$self->{output}->output_add(long_msg => "Command line: '" . $self->{option_results}->{command} . " " . $cmd_options . "'", debug => 1);
|
||||||
|
|
||||||
my ($response) = centreon::plugins::misc::execute(
|
my ($response) = centreon::plugins::misc::execute(
|
||||||
output => $self->{output},
|
output => $self->{output},
|
||||||
options => $self->{option_results},
|
options => $self->{option_results},
|
||||||
@ -159,7 +159,7 @@ sub execute {
|
|||||||
|
|
||||||
sub cloudwatch_get_metrics_set_cmd {
|
sub cloudwatch_get_metrics_set_cmd {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
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 $options{region} --namespace $options{namespace}" .
|
||||||
@ -175,7 +175,7 @@ sub cloudwatch_get_metrics_set_cmd {
|
|||||||
|
|
||||||
sub cloudwatch_get_metrics {
|
sub cloudwatch_get_metrics {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $metric_results = {};
|
my $metric_results = {};
|
||||||
my $start_time = DateTime->now->subtract(seconds => $options{timeframe})->iso8601;
|
my $start_time = DateTime->now->subtract(seconds => $options{timeframe})->iso8601;
|
||||||
my $end_time = DateTime->now->iso8601;
|
my $end_time = DateTime->now->iso8601;
|
||||||
@ -203,23 +203,23 @@ sub cloudwatch_get_metrics {
|
|||||||
$metric_results->{$raw_results->{Label}}->{sum} = 0 if (!defined($metric_results->{$raw_results->{Label}}->{sum}));
|
$metric_results->{$raw_results->{Label}}->{sum} = 0 if (!defined($metric_results->{$raw_results->{Label}}->{sum}));
|
||||||
$metric_results->{$raw_results->{Label}}->{sum} += $point->{Sum};
|
$metric_results->{$raw_results->{Label}}->{sum} += $point->{Sum};
|
||||||
}
|
}
|
||||||
|
|
||||||
$metric_results->{$raw_results->{Label}}->{points}++;
|
$metric_results->{$raw_results->{Label}}->{points}++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined($metric_results->{$raw_results->{Label}}->{average})) {
|
if (defined($metric_results->{$raw_results->{Label}}->{average})) {
|
||||||
$metric_results->{$raw_results->{Label}}->{average} /= $metric_results->{$raw_results->{Label}}->{points};
|
$metric_results->{$raw_results->{Label}}->{average} /= $metric_results->{$raw_results->{Label}}->{points};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $metric_results;
|
return $metric_results;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub discovery_set_cmd {
|
sub discovery_set_cmd {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
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 $options{region} --output json";
|
||||||
$cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne '');
|
$cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne '');
|
||||||
|
|
||||||
@ -228,7 +228,7 @@ sub discovery_set_cmd {
|
|||||||
|
|
||||||
sub discovery {
|
sub discovery {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $cmd_options = $self->discovery_set_cmd(%options);
|
my $cmd_options = $self->discovery_set_cmd(%options);
|
||||||
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
||||||
|
|
||||||
@ -237,7 +237,7 @@ sub discovery {
|
|||||||
|
|
||||||
sub cloudwatch_get_alarms_set_cmd {
|
sub cloudwatch_get_alarms_set_cmd {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
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 $options{region} --output json";
|
||||||
@ -251,7 +251,7 @@ sub cloudwatch_get_alarms {
|
|||||||
|
|
||||||
my $cmd_options = $self->cloudwatch_get_alarms_set_cmd(%options);
|
my $cmd_options = $self->cloudwatch_get_alarms_set_cmd(%options);
|
||||||
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
||||||
|
|
||||||
my $alarm_results = [];
|
my $alarm_results = [];
|
||||||
foreach my $alarm (@{$raw_results->{MetricAlarms}}) {
|
foreach my $alarm (@{$raw_results->{MetricAlarms}}) {
|
||||||
push @$alarm_results, {
|
push @$alarm_results, {
|
||||||
@ -262,17 +262,18 @@ sub cloudwatch_get_alarms {
|
|||||||
StateUpdatedTimestamp => $alarm->{StateUpdatedTimestamp},
|
StateUpdatedTimestamp => $alarm->{StateUpdatedTimestamp},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return $alarm_results;
|
return $alarm_results;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub cloudwatch_list_metrics_set_cmd {
|
sub cloudwatch_list_metrics_set_cmd {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
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 $options{region} --output json";
|
||||||
$cmd_options .= " --namespace $options{namespace}" if defined($options{namespace});
|
$cmd_options .= " --namespace $options{namespace}" if (defined($options{namespace}));
|
||||||
$cmd_options .= " --metric-name $options{metric}" if defined($options{metric});
|
$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 '');
|
$cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne '');
|
||||||
|
|
||||||
return $cmd_options;
|
return $cmd_options;
|
||||||
@ -283,13 +284,60 @@ sub cloudwatch_list_metrics {
|
|||||||
|
|
||||||
my $cmd_options = $self->cloudwatch_list_metrics_set_cmd(%options);
|
my $cmd_options = $self->cloudwatch_list_metrics_set_cmd(%options);
|
||||||
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
||||||
|
|
||||||
return $raw_results->{Metrics};
|
return $raw_results->{Metrics};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub cloudwatchlogs_describe_log_groups_set_cmd {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
||||||
|
|
||||||
|
my $cmd_options = "logs describe-log-groups --region $options{region} --output json";
|
||||||
|
$cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne '');
|
||||||
|
|
||||||
|
return $cmd_options;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub cloudwatchlogs_describe_log_groups {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $cmd_options = $self->cloudwatchlogs_describe_log_groups_set_cmd(%options);
|
||||||
|
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
||||||
|
|
||||||
|
return $raw_results->{logGroups};
|
||||||
|
}
|
||||||
|
|
||||||
|
sub cloudwatchlogs_filter_log_events_set_cmd {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
||||||
|
|
||||||
|
my $cmd_options = "logs filter-log-events --region $options{region} --output json --log-group-name '$options{group_name}'";
|
||||||
|
$cmd_options .= " --start-time $options{start_time}" if (defined($options{start_time}));
|
||||||
|
if (defined($options{stream_names})) {
|
||||||
|
$cmd_options .= " --log-stream-names";
|
||||||
|
foreach (@{$options{stream_names}}) {
|
||||||
|
$cmd_options .= " '$_'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne '');
|
||||||
|
|
||||||
|
return $cmd_options;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub cloudwatchlogs_filter_log_events {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $cmd_options = $self->cloudwatchlogs_filter_log_events_set_cmd(%options);
|
||||||
|
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
||||||
|
|
||||||
|
return $raw_results->{events};
|
||||||
|
}
|
||||||
|
|
||||||
sub ec2_get_instances_status_set_cmd {
|
sub ec2_get_instances_status_set_cmd {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
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 $options{region} --output json";
|
||||||
@ -303,7 +351,7 @@ sub ec2_get_instances_status {
|
|||||||
|
|
||||||
my $cmd_options = $self->ec2_get_instances_status_set_cmd(%options);
|
my $cmd_options = $self->ec2_get_instances_status_set_cmd(%options);
|
||||||
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
||||||
|
|
||||||
my $instance_results = {};
|
my $instance_results = {};
|
||||||
foreach (@{$raw_results->{InstanceStatuses}}) {
|
foreach (@{$raw_results->{InstanceStatuses}}) {
|
||||||
$instance_results->{$_->{InstanceId}} = {
|
$instance_results->{$_->{InstanceId}} = {
|
||||||
@ -311,13 +359,13 @@ sub ec2_get_instances_status {
|
|||||||
status => => $_->{InstanceStatus}->{Status}
|
status => => $_->{InstanceStatus}->{Status}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return $instance_results;
|
return $instance_results;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub ec2_list_resources_set_cmd {
|
sub ec2_list_resources_set_cmd {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
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 $options{region} --output json";
|
||||||
@ -331,7 +379,7 @@ sub ec2_list_resources {
|
|||||||
|
|
||||||
my $cmd_options = $self->ec2_list_resources_set_cmd(%options);
|
my $cmd_options = $self->ec2_list_resources_set_cmd(%options);
|
||||||
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
||||||
|
|
||||||
my $resource_results = [];
|
my $resource_results = [];
|
||||||
foreach my $reservation (@{$raw_results->{Reservations}}) {
|
foreach my $reservation (@{$raw_results->{Reservations}}) {
|
||||||
foreach my $instance (@{$reservation->{Instances}}) {
|
foreach my $instance (@{$reservation->{Instances}}) {
|
||||||
@ -360,13 +408,13 @@ sub ec2_list_resources {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $resource_results;
|
return $resource_results;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub asg_get_resources_set_cmd {
|
sub asg_get_resources_set_cmd {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
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 $options{region} --output json";
|
||||||
@ -380,13 +428,13 @@ sub asg_get_resources {
|
|||||||
|
|
||||||
my $cmd_options = $self->asg_get_resources_set_cmd(%options);
|
my $cmd_options = $self->asg_get_resources_set_cmd(%options);
|
||||||
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
||||||
|
|
||||||
return \@{$raw_results->{AutoScalingGroups}};
|
return \@{$raw_results->{AutoScalingGroups}};
|
||||||
}
|
}
|
||||||
|
|
||||||
sub rds_get_instances_status_set_cmd {
|
sub rds_get_instances_status_set_cmd {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
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 $options{region} --output json";
|
||||||
@ -400,18 +448,18 @@ sub rds_get_instances_status {
|
|||||||
|
|
||||||
my $cmd_options = $self->rds_get_instances_status_set_cmd(%options);
|
my $cmd_options = $self->rds_get_instances_status_set_cmd(%options);
|
||||||
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
||||||
|
|
||||||
my $instance_results = {};
|
my $instance_results = {};
|
||||||
foreach (@{$raw_results->{DBInstances}}) {
|
foreach (@{$raw_results->{DBInstances}}) {
|
||||||
$instance_results->{$_->{DBInstanceIdentifier}} = { state => $_->{DBInstanceStatus} };
|
$instance_results->{$_->{DBInstanceIdentifier}} = { state => $_->{DBInstanceStatus} };
|
||||||
}
|
}
|
||||||
|
|
||||||
return $instance_results;
|
return $instance_results;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub rds_list_instances_set_cmd {
|
sub rds_list_instances_set_cmd {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
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 $options{region} --output json";
|
||||||
@ -425,7 +473,7 @@ sub rds_list_instances {
|
|||||||
|
|
||||||
my $cmd_options = $self->rds_list_instances_set_cmd(%options);
|
my $cmd_options = $self->rds_list_instances_set_cmd(%options);
|
||||||
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
||||||
|
|
||||||
my $instance_results = [];
|
my $instance_results = [];
|
||||||
foreach my $instance (@{$raw_results->{DBInstances}}) {
|
foreach my $instance (@{$raw_results->{DBInstances}}) {
|
||||||
push @{$instance_results}, {
|
push @{$instance_results}, {
|
||||||
@ -436,13 +484,13 @@ sub rds_list_instances {
|
|||||||
DBInstanceStatus => $instance->{DBInstanceStatus},
|
DBInstanceStatus => $instance->{DBInstanceStatus},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return $instance_results;
|
return $instance_results;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub rds_list_clusters_set_cmd {
|
sub rds_list_clusters_set_cmd {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
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 $options{region} --output json";
|
||||||
@ -456,7 +504,7 @@ sub rds_list_clusters {
|
|||||||
|
|
||||||
my $cmd_options = $self->rds_list_clusters_set_cmd(%options);
|
my $cmd_options = $self->rds_list_clusters_set_cmd(%options);
|
||||||
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
||||||
|
|
||||||
my $cluster_results = [];
|
my $cluster_results = [];
|
||||||
foreach my $cluster (@{$raw_results->{DBClusters}}) {
|
foreach my $cluster (@{$raw_results->{DBClusters}}) {
|
||||||
push @{$cluster_results}, {
|
push @{$cluster_results}, {
|
||||||
@ -466,7 +514,7 @@ sub rds_list_clusters {
|
|||||||
Status => $cluster->{Status},
|
Status => $cluster->{Status},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return $cluster_results;
|
return $cluster_results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,6 +232,58 @@ sub cloudwatch_list_metrics {
|
|||||||
return $metric_results;
|
return $metric_results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub cloudwatchlogs_describe_log_groups {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
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_options = ();
|
||||||
|
while ((my $list_log_groups = $cw->DescribeLogGroups(%cw_options))) {
|
||||||
|
foreach (@{$list_log_groups->{logGroups}}) {
|
||||||
|
push @$log_groups_results, $_;
|
||||||
|
}
|
||||||
|
|
||||||
|
last if (!defined($list_log_groups->{NextToken}));
|
||||||
|
$cw_options{NextToken} = $list_log_groups->{NextToken};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if ($@) {
|
||||||
|
$self->{output}->add_option_msg(short_msg => "error: $@");
|
||||||
|
$self->{output}->option_exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $log_groups_results;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub cloudwatchlogs_filter_log_events {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
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_options = ();
|
||||||
|
$cw_options{StartTime} = $options{start_time} if (defined($options{start_time}));
|
||||||
|
$cw_options{LogStreamNames} = [@{$options{LogStreamNames}}] if (defined($options{LogStreamNames}));
|
||||||
|
while ((my $list_log_groups = $cw->FilterLogEvents(%cw_options))) {
|
||||||
|
foreach (@{$list_log_groups->{logGroups}}) {
|
||||||
|
push @$log_groups_results, $_;
|
||||||
|
}
|
||||||
|
|
||||||
|
last if (!defined($list_log_groups->{NextToken}));
|
||||||
|
$cw_options{NextToken} = $list_log_groups->{NextToken};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if ($@) {
|
||||||
|
$self->{output}->add_option_msg(short_msg => "error: $@");
|
||||||
|
$self->{output}->option_exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $log_groups_results;
|
||||||
|
}
|
||||||
|
|
||||||
sub ec2_get_instances_status {
|
sub ec2_get_instances_status {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user