[Bps-public-commit] app-aws-cloudwatch-monitor branch add-option-to-display-available-check-modules created. 14e289362a02dde09891811063d71e42170cbcbc

BPS Git Server git at git.bestpractical.com
Tue Aug 2 16:40:22 UTC 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "app-aws-cloudwatch-monitor".

The branch, add-option-to-display-available-check-modules has been created
        at  14e289362a02dde09891811063d71e42170cbcbc (commit)

- Log -----------------------------------------------------------------
commit 14e289362a02dde09891811063d71e42170cbcbc
Author: Blaine Motsinger <blaine at bestpractical.com>
Date:   Tue Aug 2 11:39:25 2022 -0500

    Add --list-checks option
    
    This commit adds a new option, --list-checks, which prints the
    available check modules and exits.

diff --git a/bin/aws-cloudwatch-monitor b/bin/aws-cloudwatch-monitor
index 0768834..7e3a886 100755
--- a/bin/aws-cloudwatch-monitor
+++ b/bin/aws-cloudwatch-monitor
@@ -27,6 +27,7 @@ Getopt::Long::GetOptions(
     \my %opt,
     'check=s@',
     'from-cron',
+    'list-checks',
     'verify',
     'verbose',
     'version' => sub { print "aws-cloudwatch-monitor version $VERSION\n"; exit 0 },
@@ -34,7 +35,7 @@ Getopt::Long::GetOptions(
 ) or Pod::Usage::pod2usage( -exitval => 1 );
 
 Pod::Usage::pod2usage( -exitval => 0 ) if ( $opt{help} );
-Pod::Usage::pod2usage( -message => 'Option check is required', -exitval => 1 ) unless ( $opt{check} );
+Pod::Usage::pod2usage( -message => 'Option check is required', -exitval => 1 ) if ( !$opt{'list-checks'} && !$opt{check} );
 
 delete $opt{version};
 delete $opt{help};
@@ -59,7 +60,7 @@ aws-cloudwatch-monitor - collect and send metrics to AWS CloudWatch
 =head1 SYNOPSIS
 
  aws-cloudwatch-monitor [--check <module>]
-                        [--from-cron] [--verify] [--verbose]
+                        [--from-cron] [--list-checks] [--verify] [--verbose]
                         [--version] [--help]
 
 =head1 DESCRIPTION
@@ -84,6 +85,10 @@ C<--verbose> is forced to off and results information is suppressed if C<--from-
 
 C<--from-cron> additionally adds a random sleep interval up to 20 seconds.
 
+=item --list-checks
+
+Prints the available check modules and exits.
+
 =item --verify
 
 Checks configuration and prepares a remote call, but does not upload metrics to CloudWatch.
diff --git a/lib/App/AWS/CloudWatch/Monitor.pm b/lib/App/AWS/CloudWatch/Monitor.pm
index 1eca77b..6c5d79f 100644
--- a/lib/App/AWS/CloudWatch/Monitor.pm
+++ b/lib/App/AWS/CloudWatch/Monitor.pm
@@ -49,8 +49,20 @@ sub run {
     my $opt  = shift;
     my $arg  = shift;
 
+    my $loader = Module::Loader->new( max_depth => 1 );
+
+    if ( $opt->{'list-checks'} ) {
+        my $namespace     = 'App::AWS::CloudWatch::Monitor::Check';
+        my @check_modules = $loader->find_modules($namespace);
+        foreach my $module (@check_modules) {
+            $module =~ s/$namespace//;
+            $module =~ s/:://;
+            print $module . "\n";
+        }
+        exit 0;
+    }
+
     my $instance_id = App::AWS::CloudWatch::Monitor::CloudWatchClient::get_instance_id();
-    my $loader      = Module::Loader->new;
 
     if ( $opt->{'from-cron'} ) {
         sleep( rand(20) );
-----------------------------------------------------------------------


hooks/post-receive
-- 
app-aws-cloudwatch-monitor


More information about the Bps-public-commit mailing list