diff --git a/centreon-plugins/cloud/aws/cloudwatch/mode/discovery.pm b/centreon-plugins/cloud/aws/cloudwatch/mode/discovery.pm index de98a156a..8a99f92e3 100644 --- a/centreon-plugins/cloud/aws/cloudwatch/mode/discovery.pm +++ b/centreon-plugins/cloud/aws/cloudwatch/mode/discovery.pm @@ -40,6 +40,7 @@ sub new { BACKUP_VAULT => $self->can('discover_backup_vault'), # DYNAMODB => $self->can('discover_dynamodb_table'), CLOUDFRONT => $self->can('discover_cloudfront'), + ELASTICACHE => $self->can('discover_elasticache'), EBS => $self->can('discover_ebs'), EC2 => $self->can('discover_ec2'), EFS => $self->can('discover_efs'), @@ -64,7 +65,6 @@ sub new { sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - } sub discover_vpc { @@ -72,8 +72,11 @@ sub discover_vpc { my @disco_data; - my $vpcs = $options{custom}->discovery(region => $options{region}, - service => 'ec2', command => 'describe-vpcs'); + my $vpcs = $options{custom}->discovery( + region => $options{region}, + service => 'ec2', + command => 'describe-vpcs' + ); foreach my $vpc (@{$vpcs->{Vpcs}}) { next if (!defined($vpc->{VpcId})); my %vpc; @@ -138,6 +141,15 @@ sub discover_cloudfront { return \@disco_data, \@disco_keys; } +sub discover_elasticache { + my (%options) = @_; + + use cloud::aws::elasticache::mode::discovery; + my @disco_data = cloud::aws::elasticache::mode::discovery->run(custom => $options{custom}, discover => 1); + my @disco_keys = keys %{$disco_data[0]} if (@disco_data != 0); + return \@disco_data, \@disco_keys; +} + sub discover_ebs { my (%options) = @_; diff --git a/centreon-plugins/cloud/aws/custom/awscli.pm b/centreon-plugins/cloud/aws/custom/awscli.pm index fe546036e..51d7692fe 100644 --- a/centreon-plugins/cloud/aws/custom/awscli.pm +++ b/centreon-plugins/cloud/aws/custom/awscli.pm @@ -882,7 +882,7 @@ sub cloudfront_list_distributions { my $raw_results = $self->execute(cmd_options => $cmd_options); my $results = []; - foreach (@{$raw_results->{DistributionList}->{Items}}) { + foreach (@{$raw_results->{DistributionList}->{Items}}) { push @$results, { Id => $_->{Id}, Status => $_->{Status}, @@ -894,6 +894,26 @@ sub cloudfront_list_distributions { return $results; } +sub elasticache_describe_cache_clusters { + my ($self, %options) = @_; + + my $cmd_options = $self->discovery_set_cmd(service => 'elasticache', command => 'describe-cache-clusters'); + my $raw_results = $self->execute(cmd_options => $cmd_options); + + my $results = []; + foreach (@{$raw_results->{CacheClusters}}) { + push @$results, { + CacheClusterId => $_->{CacheClusterId}, + Engine => $_->{Engine}, + EngineVersion => $_->{EngineVersion}, + ReplicationGroupLogDeliveryEnabled => $_->{ReplicationGroupLogDeliveryEnabled}, + SecurityGroups => $_->{SecurityGroups} + }; + } + + return $results; +} + 1; __END__ diff --git a/centreon-plugins/cloud/aws/custom/paws.pm b/centreon-plugins/cloud/aws/custom/paws.pm index f23ab3a07..579e398a2 100644 --- a/centreon-plugins/cloud/aws/custom/paws.pm +++ b/centreon-plugins/cloud/aws/custom/paws.pm @@ -762,6 +762,33 @@ sub cloudfront_list_distributions { return $results; } +sub elasticache_describe_cache_clusters { + my ($self, %options) = @_; + + my $results = []; + eval { + my $ec = $self->{paws}->service('ElastiCache', region => $self->{option_results}->{region}); + my $cacheClusterMessage = $ec->DescribeCacheClusters(); + my $cacheClusters = $cacheClusterMessage->CacheClusters; + + foreach (@$cacheClusters) { + push @$results, { + CacheClusterId => $_->{CacheClusterId}, + Engine => $_->{Engine}, + EngineVersion => $_->{EngineVersion}, + ReplicationGroupLogDeliveryEnabled => $_->{ReplicationGroupLogDeliveryEnabled}, + SecurityGroups => $_->{SecurityGroups} + }; + } + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "error: $@"); + $self->{output}->option_exit(); + } + + return $results; +} + 1; __END__ diff --git a/centreon-plugins/cloud/aws/elasticache/mode/discovery.pm b/centreon-plugins/cloud/aws/elasticache/mode/discovery.pm index e1d1f0cfc..b5096f986 100644 --- a/centreon-plugins/cloud/aws/elasticache/mode/discovery.pm +++ b/centreon-plugins/cloud/aws/elasticache/mode/discovery.pm @@ -1,3 +1,23 @@ +# +# Copyright 2023 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::elasticache::mode::discovery; use base qw(centreon::plugins::mode); @@ -28,32 +48,29 @@ sub run { my $disco_stats; $disco_stats->{start_time} = time(); - - my $instances = $options{custom}->discovery( - service => 'elasticache', - command => 'describe-cache-clusters' - ); - foreach my $ecc_instance (@{$instances->{CacheClusters}}) { + my $instances = $options{custom}->elasticache_describe_cache_clusters(); + + foreach my $ecc_instance (@$instances) { next if (!defined($ecc_instance->{CacheClusterId})); - my %ecc; - $ecc{type}= "elasticache"; - $ecc{id} = $ecc_instance->{CacheClusterId}; - $ecc{engine} = $ecc_instance->{Engine}; - $ecc{engine_version} = $ecc_instance->{EngineVersion}; - $ecc{replication_group_log_delivery_enabled} = $ecc_instance->{ReplicationGroupLogDeliveryEnabled}; - + + my %ecc; + $ecc{type}= 'elasticache'; + $ecc{id} = $ecc_instance->{CacheClusterId}; + $ecc{engine} = $ecc_instance->{Engine}; + $ecc{engine_version} = $ecc_instance->{EngineVersion}; + $ecc{replication_group_log_delivery_enabled} = $ecc_instance->{ReplicationGroupLogDeliveryEnabled} =~ /1|true/i ? 1 : 0; foreach my $secureGroups (@{$ecc_instance->{SecurityGroups}}) { push @{$ecc{security_groups}}, { status => $secureGroups->{Status}, security_group_id => $secureGroups->{SecurityGroupId} }; } - push @disco_data, \%ecc; + push @disco_data, \%ecc; } $disco_stats->{end_time} = time(); $disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time}; $disco_stats->{discovered_items} = @disco_data; $disco_stats->{results} = \@disco_data; - + my $encoded_data; eval { if (defined($self->{option_results}->{prettify})) { @@ -62,7 +79,7 @@ sub run { $encoded_data = JSON::XS->new->utf8->encode($disco_stats); } }; - + if ($@) { $encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}'; } @@ -91,4 +108,3 @@ Prettify JSON output. =back =cut - diff --git a/centreon-plugins/cloud/aws/elasticache/plugin.pm b/centreon-plugins/cloud/aws/elasticache/plugin.pm index cd1205a57..1ab3ce413 100644 --- a/centreon-plugins/cloud/aws/elasticache/plugin.pm +++ b/centreon-plugins/cloud/aws/elasticache/plugin.pm @@ -29,25 +29,24 @@ sub new { my $self = $class->SUPER::new( package => __PACKAGE__, %options ); bless $self, $class; - $self->{version} = '0.1'; - %{ $self->{modes} } = ( - 'commands-memcached' => 'cloud::aws::elasticache::mode::commandsmemcached', - 'commands-redis' => 'cloud::aws::elasticache::mode::commandsredis', - 'connections' => 'cloud::aws::elasticache::mode::connections', - 'cpu' => 'cloud::aws::elasticache::mode::cpu', - 'discovery' => 'cloud::aws::elasticache::mode::discovery', - 'evictions' => 'cloud::aws::elasticache::mode::evictions', - 'items' => 'cloud::aws::elasticache::mode::items', - 'network' => 'cloud::aws::elasticache::mode::network', - 'replication' => 'cloud::aws::elasticache::mode::replication', - 'requests-memcached' => 'cloud::aws::elasticache::mode::requestsmemcached', - 'requests-redis' => 'cloud::aws::elasticache::mode::requestsredis', - 'usage-memcached' => 'cloud::aws::elasticache::mode::usagememcached', - 'usage-redis' => 'cloud::aws::elasticache::mode::usageredis', - ); + $self->{modes} = { + 'commands-memcached' => 'cloud::aws::elasticache::mode::commandsmemcached', + 'commands-redis' => 'cloud::aws::elasticache::mode::commandsredis', + 'connections' => 'cloud::aws::elasticache::mode::connections', + 'cpu' => 'cloud::aws::elasticache::mode::cpu', + 'discovery' => 'cloud::aws::elasticache::mode::discovery', + 'evictions' => 'cloud::aws::elasticache::mode::evictions', + 'items' => 'cloud::aws::elasticache::mode::items', + 'network' => 'cloud::aws::elasticache::mode::network', + 'replication' => 'cloud::aws::elasticache::mode::replication', + 'requests-memcached' => 'cloud::aws::elasticache::mode::requestsmemcached', + 'requests-redis' => 'cloud::aws::elasticache::mode::requestsredis', + 'usage-memcached' => 'cloud::aws::elasticache::mode::usagememcached', + 'usage-redis' => 'cloud::aws::elasticache::mode::usageredis', + }; - $self->{custom_modes}{paws} = 'cloud::aws::custom::paws'; - $self->{custom_modes}{awscli} = 'cloud::aws::custom::awscli'; + $self->{custom_modes}->{paws} = 'cloud::aws::custom::paws'; + $self->{custom_modes}->{awscli} = 'cloud::aws::custom::awscli'; return $self; }