centreon-plugins/cloud/aws/ec2/mode/listinstances.pm

102 lines
2.7 KiB
Perl
Raw Normal View History

2017-12-14 13:37:47 +01:00
#
2019-01-09 09:57:11 +01:00
# Copyright 2019 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::ec2::mode::listinstances;
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;
2019-09-10 13:39:18 +02:00
$options{options}->add_options(arguments => {});
2017-12-14 13:37:47 +01:00
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub manage_selection {
my ($self, %options) = @_;
2018-04-09 11:49:57 +02:00
$self->{instances} = $options{custom}->ec2_list_resources(region => $self->{option_results}->{region});
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
foreach (@{$self->{instances}}) {
next if ($_->{Type} !~ m/instance/);
2019-09-10 13:39:18 +02:00
$self->{output}->output_add(
long_msg => sprintf("[Id = %s][AvailabilityZone = %s][InstanceType = %s][State = %s][Tags = %s][KeyName = %s]",
2019-06-19 14:58:10 +02:00
$_->{Name}, $_->{AvailabilityZone}, $_->{InstanceType}, $_->{State}, $_->{Tags}, $_->{KeyName}));
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 instances:');
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) = @_;
2019-06-19 14:58:10 +02:00
$self->{output}->add_disco_format(elements => ['id', 'availabilityzone', 'instancetype', 'state', 'tags', 'keyname']);
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
foreach (@{$self->{instances}}) {
next if ($_->{Type} !~ m/instance/);
2017-12-14 13:37:47 +01:00
$self->{output}->add_disco_entry(
2019-04-19 17:10:47 +02:00
id => $_->{Name},
2018-04-09 11:49:57 +02:00
availabilityzone => $_->{AvailabilityZone},
instancetype => $_->{InstanceType},
state => $_->{State},
tags => $_->{Tags},
2019-06-19 14:58:10 +02:00
keyname => $_->{KeyName},
2017-12-14 13:37:47 +01:00
);
}
}
1;
__END__
=head1 MODE
2018-04-09 11:49:57 +02:00
List EC2 instances.
2017-12-14 13:37:47 +01:00
=over 8
=back
=cut