aws: working progress

This commit is contained in:
qgarnier 2017-12-13 16:25:04 +01:00
parent 5f94624a79
commit 9fa71c2f66
13 changed files with 429 additions and 1306 deletions

View File

@ -1,183 +0,0 @@
#
# Copyright 2017 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::custom::awscli;
use strict;
use warnings;
use JSON;
use centreon::plugins::misc;
sub new {
my ( $class, %options ) = @_;
my $self = {};
bless $self, $class;
# $options{options} = options object
# $options{output} = output object
# $options{exit_value} = integer
# $options{noptions} = integer
if ( !defined( $options{output} ) ) {
print "Class Custom: Need to specify 'output' argument.\n";
exit 3;
}
if ( !defined( $options{options} ) ) {
$options{output}->add_option_msg( short_msg => "Class Custom: Need to specify 'options' argument." );
$options{output}->option_exit();
}
if ( !defined( $options{noptions} ) ) {
$options{options}->add_options( arguments => {
"region:s" => { name => 'region' },
"command:s" => { name => 'command', default => 'aws' },
"command-path:s" => { name => 'command_path' },
"sudo" => { name => 'sudo' },
} );
}
$options{options}->add_help(package => __PACKAGE__, sections => 'AWSCLI OPTIONS', once => 1);
$self->{output} = $options{output};
$self->{mode} = $options{mode};
return $self;
}
# Method to manage multiples
sub set_options {
my ( $self, %options ) = @_;
# options{options_result}
$self->{option_results} = $options{option_results};
}
# Method to manage multiples
sub set_defaults {
my ( $self, %options ) = @_;
# Manage default value
foreach ( keys %{ $options{default} } ) {
if ( $_ eq $self->{mode} ) {
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};
}
}
}
}
}
}
sub check_options {
my ($self, %options) = @_;
return 0;
}
sub execReq {
my ($self, $options) = @_;
my $jsoncontent;
if (!defined($options->{output})) {
$options->{output} = 'json';
}
my $json = JSON->new;
my $json_encoded = $options->{command} . " " . $options->{subcommand};
if (defined($self->{option_results}->{region})) {
$json_encoded = $json_encoded . " --region '". $self->{option_results}->{region} . "'";
}
if (defined($options->{json})) {
$json_encoded = $json_encoded . " --cli-input-json '" . $json->encode( $options->{json} ) . "'";
}
$self->{option_results}->{timeout} = 30;
if ($options->{output} eq 'text') {
$self->{stdout} = centreon::plugins::misc::execute(
output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $json_encoded
);
my @return = split /\n/, $self->{stdout};
$jsoncontent = $json->encode( [@return] );
} else {
$jsoncontent = centreon::plugins::misc::execute(
output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $json_encoded
);
}
if ($? > 0) {
$self->{output}->add_option_msg( short_msg => "Cannot run aws" );
$self->{output}->option_exit();
}
eval { $self->{command_return} = $json->decode($jsoncontent); };
if ($@) {
$self->{output}->add_option_msg( short_msg => "Cannot decode json answer" );
$self->{output}->option_exit();
}
return $self->{command_return};
}
1;
__END__
=head1 NAME
AWS CLI API
=head1 SYNOPSIS
AWS cli API custom mode
=over 8
=item B<--region>
(optional) The region to use (should be configured directly in aws).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
(optional) Command to get information (Default: 'aws').
=item B<--command-path>
(optional) Command path (Default: none).
=back
=head1 DESCRIPTION
B<custom>.
=cut

View File

@ -0,0 +1,179 @@
#
# Copyright 2017 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::custom::paws;
use strict;
use warnings;
use Paws;
use DateTime;
sub new {
my ($class, %options) = @_;
my $self = {};
bless $self, $class;
if (!defined($options{output})) {
print "Class Custom: Need to specify 'output' argument.\n";
exit 3;
}
if (!defined($options{options})) {
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
$options{output}->option_exit();
}
if (!defined($options{noptions})) {
$options{options}->add_options(arguments =>
{
"aws-secret-key:s" => { name => 'aws_secret_key' },
"aws-access-key:s" => { name => 'aws_access_key' },
});
}
$options{options}->add_help(package => __PACKAGE__, sections => 'AWS OPTIONS', once => 1);
$self->{output} = $options{output};
$self->{mode} = $options{mode};
return $self;
}
sub set_options {
my ($self, %options) = @_;
$self->{option_results} = $options{option_results};
}
sub set_defaults {
my ($self, %options) = @_;
foreach (keys %{$options{default}}) {
if ($_ eq $self->{mode}) {
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};
}
}
}
}
}
}
sub check_options {
my ($self, %options) = @_;
if (defined($self->{option_results}->{aws_secret_key}) && $self->{option_results}->{aws_secret_key} ne '') {
$ENV{AWS_SECRET_KEY} = $self->{option_results}->{aws_secret_key};
}
if (defined($self->{option_results}->{aws_access_key}) && $self->{option_results}->{aws_access_key} ne '') {
$ENV{AWS_ACCESS_KEY} = $self->{option_results}->{aws_access_key};
}
return 0;
}
sub cloudwatch_get_metrics {
my ($self, %options) = @_;
my $metric_results = {};
eval {
my $cw = Paws->service('CloudWatch', region => $options{region});
my $start_time = DateTime->now->subtract(seconds => $options{timeframe})->iso8601;
my $end_time = DateTime->now->iso8601;
foreach my $metric_name (@{$options{metrics}}) {
my $metric_result = $cw->GetMetricStatistics(
MetricName => $metric_name,
Namespace => $options{namespace},
Statistics => $options{statistics},
#ExtendedStatistics => ['p100'],
EndTime => $end_time,
StartTime => $start_time,
Period => $options{period},
#Unit => $unit,
Dimensions => $options{dimensions},
);
$metric_results->{$metric_result->{Label}} = { points => 0 };
foreach my $point (@{$metric_result->{Datapoints}}) {
if (defined($point->{Average})) {
$metric_results->{$metric_result->{Label}}->{average} = 0 if (!defined($metric_results->{$metric_result->{Label}}->{average}));
$metric_results->{$metric_result->{Label}}->{average} += $point->{Average};
}
if (defined($point->{Minimum})) {
$metric_results->{$metric_result->{Label}}->{minimum} = $point->{Minimum}
if (!defined($metric_results->{$metric_result->{Label}}->{minimum}) || $point->{Minimum} < $metric_results->{$metric_result->{Label}}->{minimum});
}
if (defined($point->{Maximum})) {
$metric_results->{$metric_result->{Label}}->{maximum} = $point->{Maximum}
if (!defined($metric_results->{$metric_result->{Label}}->{maximum}) || $point->{Maximum} > $metric_results->{$metric_result->{Label}}->{maximum});
}
if (defined($point->{Sum})) {
$metric_results->{$metric_result->{Label}}->{sum} = 0 if (!defined($metric_results->{$metric_result->{Label}}->{sum}));
$metric_results->{$metric_result->{Label}}->{sum} += $point->{Sum};
}
$metric_results->{$metric_result->{Label}}->{points}++;
}
if (defined($metric_results->{$metric_result->{Label}}->{average})) {
$metric_results->{$metric_result->{Label}}->{average} /= $metric_results->{$metric_result->{Label}}->{points};
}
}
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "error: $@");
$self->{output}->option_exit();
}
return $metric_results;
}
1;
__END__
=head1 NAME
Amazon AWS
=head1 SYNOPSIS
Amazon AWS
=head1 AWS OPTIONS
=over 8
=item B<--aws-secret-key>
Set AWS secret key.
=item B<--aws-access-key>
Set AWS access key.
=back
=head1 DESCRIPTION
B<custom>.
=cut

View File

@ -1,296 +0,0 @@
#
# Copyright 2017 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::mode::cloudwatch;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::misc;
use POSIX;
use JSON;
my $CloudwatchMetrics = {
cpu => "cloud::aws::mode::metrics::ec2instancecpu",
traffic => "cloud::aws::mode::metrics::ec2instancenetwork",
cpucreditusage => "cloud::aws::mode::metrics::ec2instancecpucreditusage",
cpucreditbalance => "cloud::aws::mode::metrics::ec2instancecpucreditbalance",
bucketsize => "cloud::aws::mode::metrics::s3bucketsize",
rdscpu => "cloud::aws::mode::metrics::rdsinstancecpu",
};
my $StatisticsType = "Average,Minimum,Maximum,Sum,SampleCount";
my $def_endtime = time();
my $apiRequest = {
'command' => 'cloudwatch',
'subcommand' => 'get-metric-statistics',
};
sub new
{
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '0.1';
$options{options}->add_options(
arguments => {
"metric:s" => {name => 'metric'},
"period:s" => {name => 'period', default => 300},
"starttime:s" => {name => 'starttime'},
"endtime:s" => {name => 'endtime'},
"statistics:s" => {name => 'statistics', default => 'Average'},
"exclude-statistics:s" => {name => 'exclude-statistics'},
"object:s" => {name => 'object'},
"warning:s" => {name => 'warning'},
"critical:s" => {name => 'critical'},
}
);
$self->{result} = {};
return $self;
}
sub check_options
{
my ($self, %options) = @_;
$self->SUPER::init(%options);
$self->{option_results}->{def_endtime} = $def_endtime;
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0)
{
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0)
{
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{metric}))
{
$self->{output}->add_option_msg(
severity => 'UNKNOWN',
short_msg => "Please give a metric to watch (cpu, disk, ...)."
);
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{object}))
{
$self->{output}->add_option_msg(
severity => 'UNKNOWN',
short_msg => "Please give the object to request (instanceid, ...)."
);
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{endtime}))
{
$self->{option_results}->{endtime} = strftime("%FT%H:%M:%S.000Z", gmtime($self->{option_results}->{def_endtime}));
}
if (!defined($self->{option_results}->{starttime}))
{
$self->{option_results}->{starttime} = strftime("%FT%H:%M:%S.000Z", gmtime($self->{option_results}->{def_endtime} - 600));
}
# Getting some parameters
# statistics
if ($self->{option_results}->{statistics} eq 'all')
{
@{$self->{option_results}->{statisticstab}} = split(/,/, $StatisticsType);
}
else
{
@{$self->{option_results}->{statisticstab}} = split(/,/, $self->{option_results}->{statistics});
foreach my $curstate (@{$self->{option_results}->{statisticstab}})
{
if (!grep { /^$curstate$/ } split(/,/, $StatisticsType))
{
$self->{output}->add_option_msg(
severity => 'UNKNOWN',
short_msg => "The statistic $curstate doesn't exist."
);
$self->{output}->option_exit();
}
}
}
# exclusions
if (defined($self->{option_results}->{'exclude-statistics'}))
{
my @excludetab = split(/,/, $self->{option_results}->{'exclude-statistics'});
my %array1 = map { $_ => 1 } @excludetab;
@{$self->{option_results}->{statisticstab}} = grep { not $array1{$_} } @{$self->{option_results}->{statisticstab}};
}
# Force Average statistic
if (!grep $_ eq 'Average', @{$self->{option_results}->{statisticstab}})
{
my $statistics = join(',', @{$self->{option_results}->{statisticstab}});
if (!$statistics eq '')
{
$statistics = $statistics . ',Average';
}
else
{
$statistics = 'Average';
}
@{$self->{option_results}->{statisticstab}} = split(/,/, $statistics);
}
}
sub manage_selection
{
my ($self, $metric) = @_;
my @result;
my @Dimensions = (
{
'Value' => $self->{option_results}->{object},
'Name' => $metric->{ObjectName}
}
);
if (defined($metric->{ExtraDimensions}))
{
push @Dimensions, $metric->{ExtraDimensions};
}
$apiRequest->{json} = {
'StartTime' => $self->{option_results}->{starttime},
'EndTime' => $self->{option_results}->{endtime},
'Period' => $self->{option_results}->{period},
'MetricName' => $metric->{MetricName},
'Unit' => $metric->{Unit},
'Statistics' => $self->{option_results}->{statisticstab},
'Dimensions' => [@Dimensions],
'Namespace' => $metric->{NameSpace}
};
}
sub run
{
my ($self, %options) = @_;
my ($msg, $exit_code, $awsapi);
if ( defined( $CloudwatchMetrics->{ $self->{option_results}->{metric} } ) ) {
centreon::plugins::misc::mymodule_load(output => $options{output}, module => $CloudwatchMetrics->{$self->{option_results}->{metric}},
error_msg => "Cannot load module '" . $CloudwatchMetrics->{$self->{option_results}->{metric}} . "'.");
my $func = $CloudwatchMetrics->{$self->{option_results}->{metric}}->can('cloudwatchCheck');
$func->($self);
} else {
$self->{output}->add_option_msg( short_msg => "Wrong option. Cannot find metric '" . $self->{option_results}->{metric} . "'." );
$self->{output}->option_exit();
}
foreach my $metric (@{$self->{metric}})
{
$self->manage_selection($metric);
$awsapi = $options{custom};
$self->{command_return} = $awsapi->execReq($apiRequest);
$self->{output}->perfdata_add(
label => sprintf($metric->{Labels}->{PerfData}, unit => $metric->{Labels}->{Unit}),
value => sprintf($metric->{Labels}->{Value}, $self->{command_return}->{Datapoints}[0]->{Average}),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
#min => 0,
#max => 100
);
$exit_code = $self->{perfdata}->threshold_check(
value => $self->{command_return}->{Datapoints}[0]->{Average},
threshold => [{label => 'critical', 'exit_litteral' => 'critical'}, {label => 'warning', exit_litteral => 'warning'}]
);
$self->{output}->output_add(long_msg => sprintf($metric->{Labels}->{LongOutput}, $self->{command_return}->{Datapoints}[0]->{Average}));
$self->{output}->output_add(
severity => $exit_code,
short_msg => sprintf($metric->{Labels}->{ShortOutput}, $self->{command_return}->{Datapoints}[0]->{Average})
);
}
$self->{output}->display();
$self->{output}->exit();
}
1;
__END__
=head1 MODE
Get cloudwatch metrics.
This doc is partly based on the official AWS CLI documentation.
=over 8
=item B<--exclude-statistics>
(optional) Statistics to exclude from the query. 'Average' can't be excluded.
=item B<--metric>
Metric to query.
=item B<--period>
(optional) The granularity, in seconds, of the returned datapoints. period must be at least 60 seconds and must be a multiple of 60. The default value is 300.
=item B<--start-time>
(optional) The time stamp to use for determining the first datapoint to return. The value specified is inclusive; results include datapoints with the time stamp specified.
exemple: 2014-04-09T23:18:00
=item B<--end-time>
(optional) The time stamp to use for determining the last datapoint to return. The value specified is exclusive; results will include datapoints up to the time stamp specified.
exemple: 2014-04-09T23:18:00
=item B<--statistics>
(optional) The metric statistics to return. For information about specific statistics returned by GetMetricStatistics, go to statistics in the Amazon CloudWatch Developer Guide.
Valid Values: Average | Sum | SampleCount | Maximum | Minimum
Average is the default and always included.
'all' for all statistics values.
=item B<--object>
Name of the object to request (InstanceId for an EC2 instance, for exemple).
=item B<--warning>
(optional) Threshold warning.
=item B<--critical>
(optional) Threshold critical.
=back
=cut

View File

@ -0,0 +1,246 @@
#
# Copyright 2017 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::mode::cloudwatchgetmetrics;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub custom_metric_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(label => $self->{result_values}->{perf_label},
value => $self->{result_values}->{value},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-metric'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-metric'),
);
}
sub custom_metric_threshold {
my ($self, %options) = @_;
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{value},
threshold => [ { label => 'critical-metric', exit_litteral => 'critical' },
{ label => 'warning-metric', exit_litteral => 'warning' } ]);
return $exit;
}
sub custom_metric_output {
my ($self, %options) = @_;
my $msg = "Metric '" . $self->{result_values}->{display} . "' value is " . $self->{result_values}->{value};
return $msg;
}
sub custom_metric_calc {
my ($self, %options) = @_;
$self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_value'};
$self->{result_values}->{perf_label} = $options{new_datas}->{$self->{instance} . '_perf_label'};
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'metrics', type => 1, message_multiple => 'All metrics are ok' },
];
$self->{maps_counters}->{metrics} = [
{ label => 'metric', set => {
key_values => [ { name => 'value' }, { name => 'perf_label' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_metric_calc'),
closure_custom_output => $self->can('custom_metric_output'),
closure_custom_perfdata => $self->can('custom_metric_perfdata'),
closure_custom_threshold_check => $self->can('custom_metric_threshold'),
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"region:s" => { name => 'region' },
"namespace:s" => { name => 'namespace' },
"dimension:s%" => { name => 'dimension' },
"metric:s@" => { name => 'metric' },
"statistic:s@" => { name => 'statistic' },
"timeframe:s" => { name => 'timeframe', default => 600 },
"period:s" => { name => 'period', default => 60 },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (!defined($self->{option_results}->{region}) || $self->{option_results}->{namespace} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --region option.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{namespace}) || $self->{option_results}->{namespace} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --namespace option.");
$self->{output}->option_exit();
}
$self->{aws_metrics} = [];
if (defined($self->{option_results}->{metric})) {
$self->{aws_metrics} = [@{$self->{option_results}->{metric}}];
}
if (scalar(@{$self->{aws_metrics}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "Need to specify --metric option.");
$self->{output}->option_exit();
}
$self->{dimension_name} = '';
my $append = '';
$self->{aws_dimensions} = [];
if (defined($self->{option_results}->{dimension})) {
foreach (keys %{$self->{option_results}->{dimension}}) {
push @{$self->{aws_dimensions}}, { Name => $_, Value => $self->{option_results}->{dimension}->{$_} };
$self->{dimension_name} .= $append . $_ . '.' . $self->{option_results}->{dimension}->{$_};
$append = '-';
}
}
if ($self->{dimension_name} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --dimension option.");
$self->{output}->option_exit();
}
$self->{aws_statistics} = ['Average'];
if (defined($self->{option_results}->{statistic})) {
$self->{aws_statistics} = [];
foreach my $stat (@{$self->{option_results}->{statistic}}) {
if ($stat ne '') {
push @{$self->{aws_statistics}}, ucfirst(lc($stat));
}
}
}
foreach my $metric_name ($self->{aws_metrics}) {
foreach my $statistic ($self->{aws_statistics}) {
my $entry = { label => lc($metric_name) . '-' . $statistic, set => {
key_values => [ { name => $metric_name . '_' . $statistic }, { name => 'display' } ],
output_template => $metric_name . ' ' . ucfirst($statistic) . ' : %s',
perfdatas => [
{ label => lc($metric_name) . '_' . $statistic, value => $metric_name . '_' . $statistic . '_absolute', template => '%s',
label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
};
push @{$self->{maps_counters}->{dimensions}}, $entry;
}
}
}
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},
statistics => $self->{aws_statistics},
timeframe => $self->{option_results}->{timeframe},
period => $self->{option_results}->{period},
);
$self->{metrics} = {};
foreach my $label (keys %{$metric_results}) {
foreach my $stat (('minimum', 'maximum', 'average', 'sum')) {
next if (!defined($metric_results->{$label}->{$stat}));
$self->{metrics}->{$self->{dimension_name} . '_' . $label . '_' . $stat} = {
display => $self->{dimension_name} . '_' . $label . '_' . $stat,
value => $metric_results->{$label}->{$stat},
perf_label => $label . '_' . $stat,
};
}
}
}
1;
__END__
=head1 MODE
Check cloudwatch metrics (same dimension and namespace).
Example:
perl centreon_plugins.pl --plugin=cloud::aws::plugin --custommode=paws --mode=cloudwatch-get-metrics --region=eu-west-1 --namespace=AWS/EC2 --dimension=InstanceId=i-01622936185e32a45 --metric=CPUUtilization --metric=CPUCreditUsage --statistic=average --statistic=max -period=60 --timeframe=600 --warning-metric= --critical-metric=
=over 8
=item B<--region>
Set the region name (Required).
=item B<--namespace>
Set cloudwatch namespace (Required).
=item B<--dimension>
Set cloudwatch dimensions (Required).
=item B<--metric>
Set cloudwatch metrics (Required).
=item B<--statistic>
Set cloudwatch statistics (Default: 'average').
=item B<--period>
Set period in seconds (Default: 60).
=item B<--timeframe>
Set timeframe in seconds (Default: 600).
=item B<--warning-metric>
Threshold warning.
=item B<--critical-metric>
Threshold critical.
=back
=cut

View File

@ -1,207 +0,0 @@
#
# Copyright 2017 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::mode::instancestate;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::misc;
use Data::Dumper;
use JSON;
my %EC2_instance_states = (
'pending' => 'WARNING',
'running' => 'OK',
'shutting-down' => 'CRITICAL',
'terminated' => 'CRITICAL',
'stopping' => 'CRITICAL',
'stopped' => 'CRITICAL'
);
my $apiRequest = {
'command' => 'ec2',
'subcommand' => 'describe-instance-status',
};
sub new {
my ( $class, %options ) = @_;
my $self = $class->SUPER::new( package => __PACKAGE__, %options );
bless $self, $class;
$self->{version} = '0.1';
$options{options}->add_options(
arguments => {
"state:s" => { name => 'state', default => 'all' },
"no-includeallinstances" => { name => 'includeallinstances' },
"exclude:s" => { name => 'exclude' },
"instanceid:s" => { name => 'instanceid' }
}
);
$self->{result} = {};
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub manage_selection {
my ($self, %options) = @_;
my (@result, $awsapi);
# Getting some parameters
# includeallinstances
if (defined($self->{option_results}->{includeallinstances})) {
$self->{option_results}->{includeallinstances} = JSON::false;
} else {
$self->{option_results}->{includeallinstances} = JSON::true;
}
# states
if ($self->{option_results}->{state} eq 'all') {
@{$self->{option_results}->{statetab} } = keys %EC2_instance_states;
} else {
@{$self->{option_results}->{statetab}} = split /,/, $self->{option_results}->{state};
foreach my $curstate (@{$self->{option_results}->{statetab}}) {
if (!grep { /^$curstate$/ } keys(%EC2_instance_states)) {
$self->{output}->add_option_msg(severity => 'UNKNOWN', short_msg => "The state doesn't exist.");
$self->{output}->option_exit();
}
}
}
# exclusions
if (defined($self->{option_results}->{exclude})) {
my @excludetab = split /,/, $self->{option_results}->{exclude};
my %array1 = map { $_ => 1 } @excludetab;
@{$self->{option_results}->{statetab}} = grep { not $array1{$_} } @{$self->{option_results}->{statetab}};
}
my $states = join(',',@{$self->{option_results}->{statetab}});
# Getting data from AWS
# Building JSON
$apiRequest->{json} = {
'DryRun' => JSON::false,
'IncludeAllInstances' => $self->{option_results}->{includeallinstances},
'Filters' => [
{
'Name' => 'instance-state-name',
'Values' => $self->{option_results}->{statetab},
}],
};
# InstanceIds
if (defined($self->{option_results}->{instanceid})) {
my @InstanceIds = split(/,/, $self->{option_results}->{instanceid});
@{$apiRequest->{json}{InstanceIds}} = @InstanceIds;
}
# Requesting API
$awsapi = $options{custom};
$self->{command_return} = $awsapi->execReq($apiRequest);
# Compute data
$self->{option_results}->{instancecount}->{total} = 0;
foreach my $curstate (@{$self->{option_results}->{statetab}}) {
$self->{option_results}->{instancecount}->{$curstate} = 0;
}
foreach my $l (@{$self->{command_return}->{InstanceStatuses}}) {
$self->{result}->{instance}->{$l->{InstanceId}} = $l->{InstanceState}->{Name};
# long output for each instance
$self->{output}->output_add(long_msg => "'" . $l->{InstanceId} . "' [state = " . $l->{InstanceState}->{Name} . ']');
foreach my $curstate (@{$self->{option_results}->{statetab}}) {
if ($l->{InstanceState}->{Name} eq $curstate) {
$self->{option_results}->{instancecount}->{$curstate}++;
}
}
$self->{option_results}->{instancecount}->{total}++;
}
}
sub run {
my ( $self, %options ) = @_;
my ( $msg, $exit_code );
my $old_status = 'OK';
$self->manage_selection(%options);
# Send formated data to Centreon
# Perf data
$self->{output}->perfdata_add(
label => 'total',
value => $self->{option_results}->{instancecount}->{'total'},
);
foreach my $curstate (@{$self->{option_results}->{statetab}}) {
$self->{output}->perfdata_add(
label => $curstate,
value => $self->{option_results}->{instancecount}->{$curstate},
);
# Most critical state
if ($self->{option_results}->{instancecount}->{$curstate} != 0) {
$exit_code = $EC2_instance_states{$curstate};
$exit_code = $self->{output}->get_most_critical(status => [ $exit_code, $old_status ]);
$old_status = $exit_code;
}
}
# Output message
$self->{output}->output_add(
severity => $exit_code,
short_msg => sprintf("Total instances: %s", $self->{option_results}->{instancecount}->{total})
);
$self->{output}->display();
$self->{output}->exit();
}
1;
__END__
=head1 MODE
Get the state of your EC2 instances (running, stopped, ...)
=over 8
=item B<--state>
(optional) Specific state to query.
=item B<--no-includeallinstances>
(optional) Includes the health status for running instances only.
=item B<--exclude>
(optional) State to exclude from the query.
=back
=cut

View File

@ -1,256 +0,0 @@
#
# Copyright 2017 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::mode::list;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::misc;
use JSON;
my $AWSServices = 'EC2,S3,RDS';
my @Disco_service_tab = ('EC2', 'RDS');
my $EC2_instance_states = 'running,stopped';
my $awsapi;
sub new
{
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '0.1';
$options{options}->add_options(
arguments => {
"service:s" => {name => 'service', default => $AWSServices},
"exclude-service:s" => {name => 'exclude_service'},
"ec2-state:s"=>{name=> 'ec2_state', default => $EC2_instance_states},
"ec2-exclude-state:s" => {name => 'ec2_exclude_state'},
}
);
$self->{result} = {};
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub api_request {
my ($self, %options) = @_;
@{$self->{option_results}->{servicetab}} = split( /,/, $self->{option_results}->{service} );
# exclusions
if (defined($self->{option_results}->{exclude_service})) {
my @excludetab = split /,/, $self->{option_results}->{exclude_service};
my %array1 = map { $_ => 1 } @excludetab;
@{$self->{option_results}->{servicetab}} = grep { not $array1{$_} } @{$self->{option_results}->{servicetab}};
}
foreach my $service (@{$self->{option_results}->{servicetab}}) {
$self->{result}->{count}->{$service} = 0;
if ($service eq 'EC2') {
$self->EC2(%options);
} elsif ($service eq 'S3') {
$self->S3(%options);
} elsif ($service eq 'RDS') {
$self->RDS(%options);
} else {
$self->{output}->add_option_msg(short_msg => "Service $service doesn't exists" );
$self->{output}->option_exit();
}
}
}
sub EC2
{
my ($self, %options) = @_;
my $apiRequest = {
'command' => 'ec2',
'subcommand' => 'describe-instances',
};
# Building JSON
my @ec2_statestab = split(/,/, $self->{option_results}->{ec2_state});
# exclusions
if (defined($self->{option_results}->{ec2_exclude_state})) {
my @excludetab = split /,/, $self->{option_results}->{ec2_exclude_state};
my %array1 = map { $_ => 1 } @excludetab;
@ec2_statestab = grep { not $array1{$_} } @ec2_statestab;
}
$apiRequest->{json} = {
'DryRun' => JSON::false,
'Filters' => [
{
'Name' => 'instance-state-name',
'Values' => [@ec2_statestab],
}
],
};
# Requesting API
$awsapi = $options{custom};
$self->{command_return} = $awsapi->execReq($apiRequest);
# Compute data
foreach my $instance (@{$self->{command_return}->{Reservations}}) {
foreach my $tags (@{$instance->{Instances}[0]->{Tags}}) {
if ($tags->{Key} eq 'Name') {
$instance->{Instances}[0]->{Name} = $tags->{Value};
}
}
$self->{result}->{'EC2'}->{$instance->{Instances}[0]->{InstanceId}} =
{
State => $instance->{Instances}[0]->{State}->{Name},
Name => $instance->{Instances}[0]->{Name}
};
$self->{result}->{count}->{'EC2'}++;
}
}
sub S3
{
my ($self, %options) = @_;
my (@buckets, @return) = ();
my $apiRequest = {
'command' => 's3',
'subcommand' => 'ls',
'output' => 'text'
};
# Requesting API
$awsapi = $options{custom};
$self->{command_return} = $awsapi->execReq($apiRequest);
# Exec command
foreach my $line (@{$self->{command_return}}) {
my ($date, $time, $name) = split / /, $line;
my $creationdate = $date . " " . $time;
push(@buckets, { Name => $name, CreationDate => $creationdate });
}
# Compute data
foreach my $bucket (@buckets) {
$self->{result}->{'S3'}->{$bucket->{Name}} =
{'Creation date' => $bucket->{CreationDate}};
$self->{result}->{count}->{'S3'}++;
}
}
sub RDS
{
my ($self, %options) = @_;
my $apiRequest = {
'command' => 'rds',
'subcommand' => 'describe-db-instances',
};
# Requesting API
$awsapi = $options{custom};
$self->{command_return} = $awsapi->execReq($apiRequest);
# Compute data
foreach my $dbinstance (@{$self->{command_return}->{DBInstances}}) {
$self->{result}->{'RDS'}->{$dbinstance->{DBInstanceIdentifier}} = {
State => $dbinstance->{DBInstanceStatus},
Name => $dbinstance->{DBInstanceIdentifier}
};
$self->{result}->{count}->{RDS}++;
}
}
sub disco_format {
my ($self, %options) = @_;
my $names = [ 'name', 'id', 'state', 'service' ];
$self->{output}->add_disco_format( elements => $names );
}
sub disco_show
{
my ($self, %options) = @_;
$self->api_request(%options);
foreach my $service (@Disco_service_tab) {
foreach my $device (keys %{$self->{result}->{$service}}) {
$self->{output}->add_disco_entry(
name => $self->{result}->{$service}->{$device}->{Name},
id => $device,
state => $self->{result}->{$service}->{$device}->{State},
service => $service,
);
}
}
}
sub run
{
my ($self, %options) = @_;
$self->api_request(%options);
# Send formated data to Centreon
foreach my $service (@{$self->{option_results}->{servicetab}}) {
$self->{output}->output_add(long_msg => sprintf("AWS service: %s", $service));
foreach my $device (keys %{$self->{result}->{$service}}) {
my $output = $device . " [";
foreach my $value (sort(keys %{$self->{result}->{$service}->{$device}})) {
$output = $output . $value . " = " . $self->{result}->{$service}->{$device}->{$value} . ", ";
}
$output =~ s/, $//;
$output = $output . "]";
$self->{output}->output_add(long_msg => $output);
}
$self->{output}->output_add(short_msg => sprintf("%s: %s", $service, $self->{result}->{count}->{$service}));
}
$self->{output}->display(
nolabel => 1,
force_ignore_perfdata => 1,
force_long_output => 1
);
$self->{output}->exit();
}
1;
__END__
=head1 MODE
List your EC2, RDS instance and S3 buckets
=over 8
=item B<--service>
(optional) List one particular service.
=item B<--exclude-service>
(optional) Service to exclude from the scan.
=item B<--ec2-state>
(optional) State to request (default: 'running','stopped')
=item B<--ec2-exclude-state>
(optional) State to exclude from the scan.
=back
=cut

View File

@ -1,51 +0,0 @@
#
# Copyright 2017 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::mode::metrics::ec2instancecpu;
use strict;
use warnings;
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(&cloudwatchCheck);
my @Param;
$Param[0] = {
'NameSpace' => 'AWS/EC2',
'MetricName' => 'CPUUtilization',
'ObjectName' => 'InstanceId',
'Unit' => 'Percent',
'Labels' => {
'ShortOutput' => "CPU Usage is %.2f%%",
'LongOutput' => "CPU Usage is %.2f%%",
'PerfData' => 'cpu',
'Unit' => '%',
'Value' => "%.2f",
}
};
sub cloudwatchCheck {
my ($self) = @_;
@{ $self->{metric} } = @Param;
}
1;

View File

@ -1,51 +0,0 @@
#
# Copyright 2017 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::mode::metrics::ec2instancecpucreditbalance;
use strict;
use warnings;
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(&cloudwatchCheck);
my @Param;
$Param[0] = {
'NameSpace' => 'AWS/EC2',
'MetricName' => 'CPUCreditBalance',
'ObjectName' => 'InstanceId',
'Unit' => 'Count',
'Labels' => {
'ShortOutput' => "CPUCreditBalance is %.2f%%",
'LongOutput' => "CPUCreditBalance is %.2f%%",
'PerfData' => 'CPUCreditBalance',
'Unit' => 'Count',
'Value' => "%.2f",
}
};
sub cloudwatchCheck {
my ($self) = @_;
@{ $self->{metric} } = @Param;
}
1;

View File

@ -1,51 +0,0 @@
#
# Copyright 2017 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::mode::metrics::ec2instancecpucreditusage;
use strict;
use warnings;
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(&cloudwatchCheck);
my @Param;
$Param[0] = {
'NameSpace' => 'AWS/EC2',
'MetricName' => 'CPUCreditUsage',
'ObjectName' => 'InstanceId',
'Unit' => 'Count',
'Labels' => {
'ShortOutput' => "CPUCreditUsage is %.2f%%",
'LongOutput' => "CPUCreditUsage is %.2f%%",
'PerfData' => 'CPUCreditUsage',
'Unit' => 'Count',
'Value' => "%.2f",
}
};
sub cloudwatchCheck {
my ($self) = @_;
@{ $self->{metric} } = @Param;
}
1;

View File

@ -1,66 +0,0 @@
#
# Copyright 2017 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::mode::metrics::ec2instancenetwork;
use strict;
use warnings;
use Data::Dumper;
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(&cloudwatchCheck);
my @Param;
$Param[0] = {
'NameSpace' => 'AWS/EC2',
'MetricName' => 'NetworkIn',
'ObjectName' => 'InstanceId',
'Unit' => 'Bytes',
'Labels' => {
'ShortOutput' => "Traffic In %s Bytes",
'LongOutput' => "Traffic In %s Bytes",
'PerfData' => 'traffic_in',
'Unit' => 'B',
'Value' => "%.2f",
}
};
$Param[1] = {
'NameSpace' => 'AWS/EC2',
'MetricName' => 'NetworkOut',
'ObjectName' => 'InstanceId',
'Unit' => 'Bytes',
'Labels' => {
'ShortOutput' => "Traffic Out %s Bytes",
'LongOutput' => "Traffic Out %s Bytes",
'PerfData' => 'traffic_out',
'Unit' => 'B',
'Value' => "%.2f",
}
};
sub cloudwatchCheck {
my ($self) = @_;
@{ $self->{metric} } = @Param;
}
1;

View File

@ -1,53 +0,0 @@
#
# Copyright 2017 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::mode::metrics::rdsinstancecpu;
use strict;
use warnings;
use POSIX;
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(&cloudwatchCheck);
my @Param;
$Param[0] = {
'NameSpace' => 'AWS/RDS',
'MetricName' => 'CPUUtilization',
'ObjectName' => 'DBInstanceIdentifier',
'Unit' => 'Percent',
'Labels' => {
'ShortOutput' => "CPU Usage is %.2f%%",
'LongOutput' => "CPU Usage is %.2f%%",
'PerfData' => 'cpu',
'Unit' => '%',
'Value' => "%.2f",
}
};
sub cloudwatchCheck {
my ($self) = @_;
@{ $self->{metric} } = @Param;
$self->{option_results}->{starttime} = strftime( "%FT%H:%M:%S.000Z", gmtime( $self->{option_results}->{def_endtime} - 300 ) );
}
1;

View File

@ -1,74 +0,0 @@
#
# Copyright 2017 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::mode::metrics::s3bucketsize;
use strict;
use warnings;
use POSIX;
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(&cloudwatchCheck);
my @Param;
$Param[0] = {
'NameSpace' => 'AWS/S3',
'MetricName' => 'BucketSizeBytes',
'ObjectName' => 'BucketName',
'Unit' => 'Bytes',
'ExtraDimensions' => {
'Name' => 'StorageType',
'Value'=> 'StandardStorage'
},
'Labels' => {
'ShortOutput' => "Bucket size is %s Bytes",
'LongOutput' => "Bucket size is %s Bytes",
'PerfData' => 'size',
'Unit' => 'Bytes',
'Value' => "%s",
}
};
$Param[1] = {
'NameSpace' => 'AWS/S3',
'MetricName' => 'NumberOfObjects',
'ObjectName' => 'BucketName',
'Unit' => 'Count',
'ExtraDimensions' => {
'Name' => 'StorageType',
'Value'=> 'AllStorageTypes'
},
'Labels' => {
'ShortOutput' => "Number of objects is %s",
'LongOutput' => "Number of objects is %s",
'PerfData' => 'number',
'Unit' => '',
'Value' => "%s",
}
};
sub cloudwatchCheck {
my ($self) = @_;
@{ $self->{metric} } = @Param;
$self->{option_results}->{starttime} = strftime( "%FT%H:%M:%S.000Z", gmtime( $self->{option_results}->{def_endtime} - 86400 ) );
}
1;

View File

@ -31,21 +31,16 @@ sub new {
$self->{version} = '0.1';
%{ $self->{modes} } = (
'instancestate' => 'cloud::aws::mode::instancestate',
'list' => 'cloud::aws::mode::list',
'cloudwatch' => 'cloud::aws::mode::cloudwatch',
'cloudwatch-get-alarms' => 'cloud::aws::mode::cloudwatchgetalarms',
'cloudwatch-get-metrics' => 'cloud::aws::mode::cloudwatchgetmetrics',
'cloudwatch-list-metrics' => 'cloud::aws::mode::cloudwatchlistmetrics',
);
$self->{custom_modes}{paws} = 'cloud::aws::custom::paws';
$self->{custom_modes}{awscli} = 'cloud::aws::custom::awscli';
return $self;
}
sub init {
my ( $self, %options ) = @_;
$self->SUPER::init(%options);
}
1;
__END__
@ -54,13 +49,4 @@ __END__
Check Amazon AWS cloud.
=over 8
For this plugin to work, you have to install and configure:
awscli (http://docs.aws.amazon.com/cli/latest/userguide/installing.html#install-bundle-other-os).
perl-json
perl-Module-Load
=back
=cut