centreon-plugins/cloud/aws/billing/mode/listservices.pm

121 lines
3.5 KiB
Perl
Raw Normal View History

2017-12-14 13:37:47 +01:00
#
2018-01-29 14:11:11 +01:00
# Copyright 2018 Centreon (http://www.centreon.com/)
2017-12-14 13:37:47 +01:00
#
# 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.
#
2018-04-09 11:49:57 +02:00
package cloud::aws::billing::mode::listservices;
2017-12-14 13:37:47 +01:00
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;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
2018-04-09 11:49:57 +02:00
$self->{aws_region} = defined($self->{option_results}->{region}) ? $self->{option_results}->{region} : 'us-east-1';
2017-12-14 13:37:47 +01:00
}
sub manage_selection {
my ($self, %options) = @_;
2018-04-09 11:49:57 +02:00
$self->{dimensions} = $options{custom}->cloudwatch_list_metrics(region => $self->{aws_region},
namespace => 'AWS/Billing');
2017-12-14 13:37:47 +01:00
}
sub run {
my ($self, %options) = @_;
$self->manage_selection(%options);
2018-04-09 11:49:57 +02:00
my %already;
foreach my $dimension (@{$self->{dimensions}}) {
my $servicename = '';
my $currency = '';
foreach my $name (@{$dimension->{Dimensions}}) {
$servicename = $name->{Value} if ($name->{Name} =~ m/ServiceName/ && $name->{Value} ne '');
$currency = $name->{Value} if ($name->{Name} =~ m/Currency/ && $name->{Value} ne '');
}
next if (defined($already{$servicename}) || $servicename eq '');
$self->{output}->output_add(long_msg => sprintf("[ServiceName = %s][Currency = %s]", $servicename, $currency));
$already{$servicename} = 1;
2017-12-14 13:37:47 +01:00
}
$self->{output}->output_add(severity => 'OK',
2018-04-09 11:49:57 +02:00
short_msg => 'List services:');
2017-12-14 13:37:47 +01:00
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
sub disco_format {
my ($self, %options) = @_;
2018-04-09 11:49:57 +02:00
$self->{output}->add_disco_format(elements => ['servicename', 'currency']);
2017-12-14 13:37:47 +01:00
}
sub disco_show {
my ($self, %options) = @_;
$self->manage_selection(%options);
2018-04-09 11:49:57 +02:00
my %already;
foreach my $dimension (@{$self->{dimensions}}) {
my $servicename = '';
my $currency = '';
foreach my $name (@{$dimension->{Dimensions}}) {
$servicename = $name->{Value} if ($name->{Name} =~ m/ServiceName/ && $name->{Value} ne '');
$currency = $name->{Value} if ($name->{Name} =~ m/Currency/ && $name->{Value} ne '');
}
next if (defined($already{$servicename}) || $servicename eq '');
2017-12-14 13:37:47 +01:00
$self->{output}->add_disco_entry(
2018-04-09 11:49:57 +02:00
servicename => $servicename,
currency => $currency,
2017-12-14 13:37:47 +01:00
);
2018-04-09 11:49:57 +02:00
$already{$servicename} = 1;
2017-12-14 13:37:47 +01:00
}
}
1;
__END__
=head1 MODE
2018-04-09 11:49:57 +02:00
List billed Amazon services.
2017-12-14 13:37:47 +01:00
=over 8
=back
=cut