[Bps-public-commit] app-aws-cloudwatch-monitor-check-mailsummary branch add-check-module created. b36479c056bf50da6b3863a4e1a44a39e5440bfe

BPS Git Server git at git.bestpractical.com
Wed Dec 1 00:55:58 UTC 2021


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-check-mailsummary".

The branch, add-check-module has been created
        at  b36479c056bf50da6b3863a4e1a44a39e5440bfe (commit)

- Log -----------------------------------------------------------------
commit b36479c056bf50da6b3863a4e1a44a39e5440bfe
Author: Blaine Motsinger <blaine at bestpractical.com>
Date:   Wed Nov 24 18:30:43 2021 -0600

    Add initial check module

diff --git a/README b/README
index d89fffc..5427efb 100644
--- a/README
+++ b/README
@@ -1,3 +1,51 @@
 NAME
     App::AWS::CloudWatch::Monitor::Check::MailSummary - gather mail traffic
     summary data
+
+SYNOPSIS
+     my $plugin  = App::AWS::CloudWatch::Monitor::Check::MailSummary->new();
+     my $metrics = $plugin->check( $args_arrayref );
+
+     perl bin/aws-cloudwatch-monitor --check MailSummary --maillog-path /var/log/mail.log --maillog-time 23:00
+
+DESCRIPTION
+    "App::AWS::CloudWatch::Monitor::Check::MailSummary" is a
+    "App::AWS::CloudWatch::Monitor::Check" module which gathers mail traffic
+    summary data for a specified hour.
+
+METRICS
+    The following metrics are gathered and returned.
+
+    mail-Received
+    mail-Delivered
+    mail-Deferred
+    mail-Bounced
+    mail-Rejected
+
+METHODS
+    check
+        Gathers the metric data and returns an arrayref of hashrefs with
+        keys "MetricName", "Unit", "RawValue".
+
+ARGUMENTS
+    --maillog-path </path/to/maillog>
+        The "--maillog-path" argument is required and defines the full path,
+        with filename, where the maillog can be read.
+
+         perl bin/aws-cloudwatch-monitor --check MailSummary --maillog-path /var/log/mail.log
+
+    --maillog-time <hh:mm>
+        The optional "--maillog-time" argument may be defined to specify
+        which hour to get mailstats for.
+
+         perl bin/aws-cloudwatch-monitor --check MailSummary --maillog-path /var/log/mail.log --maillog-time 23:00
+
+        "maillog-time" must be formatted 24hr and minute (hh:mm).
+
+        If "maillog-time" isn't defined, mailstats are gathered for the
+        previous hour.
+
+DEPENDENCIES
+    <App::AWS::CloudWatch::Monitor::Check::MailSummary> depends on the
+    external program, "pflogsumm".
+
diff --git a/lib/App/AWS/CloudWatch/Monitor/Check/MailSummary.pm b/lib/App/AWS/CloudWatch/Monitor/Check/MailSummary.pm
new file mode 100644
index 0000000..f3229f0
--- /dev/null
+++ b/lib/App/AWS/CloudWatch/Monitor/Check/MailSummary.pm
@@ -0,0 +1,156 @@
+package App::AWS::CloudWatch::Monitor::Check::MailSummary;
+
+use strict;
+use warnings;
+
+use parent 'App::AWS::CloudWatch::Monitor::Check';
+
+use Getopt::Long qw(:config pass_through);
+use Time::Piece;
+use Time::Seconds;
+
+our $VERSION = '0.01';
+
+sub check {
+    my $self = shift;
+    my $arg  = shift;
+
+    Getopt::Long::GetOptionsFromArray( $arg, \my %opt, 'maillog-path=s', 'maillog-time=s' );
+
+    die "Option: maillog-path is required" unless $opt{'maillog-path'};
+
+    my $t;
+    if ( $opt{'maillog-time'} ) {
+        die 'Option: maillog-time must be 24hr hour and minute (hh:mm)'
+            unless $opt{'maillog-time'} =~ /^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/;
+
+        $t = Time::Piece->strptime( $opt{'maillog-time'}, '%H:%M' );
+    }
+    else {
+        $t = localtime;
+    }
+
+    my $now = $t->hour;
+    $now = '0' . $now if $now < 10;
+    $now = $now . '00';
+
+    $t -= ONE_HOUR;
+    my $start_hour = $t->hour;
+    $start_hour = '0' . $start_hour if $start_hour < 10;
+    $start_hour = $start_hour . '00';
+
+    my $time_key = $start_hour . '-' . ( $start_hour == 2300 ? 2400 : $now );
+    my $scope    = ( $time_key eq '2300-2400' ? 'yesterday' : 'today' );
+
+    # TODO: find pflogsumm bin location
+    my @pflogsumm_command = ( qw{ /usr/sbin/pflogsumm -d }, $scope, $opt{'maillog-path'}, qw{ --detail 0 } );
+    my ( $exit, $stdout, $stderr ) = $self->run_command( \@pflogsumm_command );
+
+    if ($exit) {
+        die "$stderr\n";
+    }
+
+    return unless $stdout;
+
+    my $traffic_summary_per_hour = {};
+    foreach my $line ( @{$stdout} ) {
+        next unless $line =~ /(\d{4}-\d{4})\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/;
+
+        $traffic_summary_per_hour->{$1} = {
+            Received  => $2,
+            Delivered => $3,
+            Deferred  => $4,
+            Bounced   => $5,
+            Rejected  => $6,
+        };
+    }
+
+    my $metrics;
+    foreach my $key ( sort keys %{ $traffic_summary_per_hour->{$time_key} } ) {
+        push @{$metrics},
+            {
+            MetricName => "mail-$key",
+            Unit       => 'Count',
+            RawValue   => $traffic_summary_per_hour->{$time_key}{$key},
+            },
+    }
+
+    return $metrics;
+}
+
+1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+App::AWS::CloudWatch::Monitor::Check::MailSummary - gather mail traffic summary data
+
+=head1 SYNOPSIS
+
+ my $plugin  = App::AWS::CloudWatch::Monitor::Check::MailSummary->new();
+ my $metrics = $plugin->check( $args_arrayref );
+
+ perl bin/aws-cloudwatch-monitor --check MailSummary --maillog-path /var/log/mail.log --maillog-time 23:00
+
+=head1 DESCRIPTION
+
+C<App::AWS::CloudWatch::Monitor::Check::MailSummary> is a C<App::AWS::CloudWatch::Monitor::Check> module which gathers mail traffic summary data for a specified hour.
+
+=head1 METRICS
+
+The following metrics are gathered and returned.
+
+=over
+
+=item mail-Received
+
+=item mail-Delivered
+
+=item mail-Deferred
+
+=item mail-Bounced
+
+=item mail-Rejected
+
+=back
+
+=head1 METHODS
+
+=over
+
+=item check
+
+Gathers the metric data and returns an arrayref of hashrefs with keys C<MetricName>, C<Unit>, C<RawValue>.
+
+=back
+
+=head1 ARGUMENTS
+
+=over
+
+=item --maillog-path </path/to/maillog>
+
+The C<--maillog-path> argument is required and defines the full path, with filename, where the maillog can be read.
+
+ perl bin/aws-cloudwatch-monitor --check MailSummary --maillog-path /var/log/mail.log
+
+=item --maillog-time <hh:mm>
+
+The optional C<--maillog-time> argument may be defined to specify which hour to get mailstats for.
+
+ perl bin/aws-cloudwatch-monitor --check MailSummary --maillog-path /var/log/mail.log --maillog-time 23:00
+
+C<maillog-time> must be formatted 24hr and minute (hh:mm).
+
+If C<maillog-time> isn't defined, mailstats are gathered for the previous hour.
+
+=back
+
+=head1 DEPENDENCIES
+
+<App::AWS::CloudWatch::Monitor::Check::MailSummary> depends on the external program, C<pflogsumm>.
+
+=cut
-----------------------------------------------------------------------


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


More information about the Bps-public-commit mailing list