[Bps-public-commit] app-aws-cloudwatch-monitor-check-fail2ban branch add-check-module created. 43f4f635f7faac73e12d787715598906ef3a403f

BPS Git Server git at git.bestpractical.com
Wed Dec 1 00:58:01 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-fail2ban".

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

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

    Add initial check module

diff --git a/README b/README
index a5064e7..45399a1 100644
--- a/README
+++ b/README
@@ -1,3 +1,40 @@
 NAME
     App::AWS::CloudWatch::Monitor::Check::Fail2Ban - gather fail2ban jail
     metrics
+
+SYNOPSIS
+     my $plugin  = App::AWS::CloudWatch::Monitor::Check::Fail2Ban->new();
+     my $metrics = $plugin->check();
+
+     perl bin/aws-cloudwatch-monitor --check Fail2Ban
+
+DESCRIPTION
+    "App::AWS::CloudWatch::Monitor::Check::Fail2Ban" is a
+    "App::AWS::CloudWatch::Monitor::Check" module which gathers fail2ban
+    jail metrics.
+
+METRICS
+    The following metrics are gathered and returned.
+
+    fail2ban-CurrentlyBanned
+        The cumulative currently banned for all active jails.
+
+    fail2ban-TotalBanned
+        The cumulative total banned for all active jails.
+
+METHODS
+    check
+        Gathers the metric data and returns an arrayref of hashrefs with
+        keys "MetricName", "Unit", "RawValue".
+
+DEPENDENCIES
+    <App::AWS::CloudWatch::Monitor::Check::Fail2Ban> depends on the external
+    program, "fail2ban-client".
+
+KNOWN ISSUES
+    "fail2ban-client" requires root privileges to read the logfiles. This
+    check must also be run with root privileges because of its dependency on
+    "fail2ban-client".
+
+     Permission denied to socket: /var/run/fail2ban/fail2ban.sock, (you must be root)
+
diff --git a/lib/App/AWS/CloudWatch/Monitor/Check/Fail2Ban.pm b/lib/App/AWS/CloudWatch/Monitor/Check/Fail2Ban.pm
new file mode 100644
index 0000000..939942f
--- /dev/null
+++ b/lib/App/AWS/CloudWatch/Monitor/Check/Fail2Ban.pm
@@ -0,0 +1,132 @@
+package App::AWS::CloudWatch::Monitor::Check::Fail2Ban;
+
+use strict;
+use warnings;
+
+use parent 'App::AWS::CloudWatch::Monitor::Check';
+
+our $VERSION = '0.01';
+
+sub check {
+    my $self = shift;
+
+    my @fail2ban_jails_command = ( '/usr/bin/fail2ban-client', 'status' );
+    my ( $exit, $stdout, $stderr ) = $self->run_command( \@fail2ban_jails_command );
+
+    if ($exit) {
+        die "$stderr\n";
+    }
+
+    return unless $stdout;
+
+    my @jails;
+    foreach my $line ( @{$stdout} ) {
+        next unless $line =~ qr/Jail list/;
+
+        # `- Jail list: http-one, http-two, http-three
+        $line =~ s/^`-\s+Jail\s+list:\s+//g;
+
+        # http-one, http-two, http-three
+        push @jails, split /,\s+/, $line;
+    }
+
+    my $currently_banned = 0;
+    my $total_banned     = 0;
+    foreach my $jail (@jails) {
+        ( $exit, $stdout, $stderr ) = $self->run_command( [ @fail2ban_jails_command, $jail ] );
+
+        if ($exit) {
+            die "$stderr\n";
+        }
+
+        return unless $stdout;
+
+        foreach my $line ( @{$stdout} ) {
+            if ( $line =~ qr/Currently banned/ ) {
+
+                #    |- Currently banned:   1485
+                if ( $line =~ /(\d+)$/ ) {
+                    $currently_banned += $1;
+                }
+            }
+
+            if ( $line =~ qr/Total banned/ ) {
+
+                #    |- Total banned:   3326
+                if ( $line =~ /(\d+)$/ ) {
+                    $total_banned += $1;
+                }
+            }
+        }
+    }
+
+    return [
+        {   MetricName => 'fail2ban-CurrentlyBanned',
+            Unit       => 'Count',
+            RawValue   => $currently_banned,
+        },
+        {   MetricName => 'fail2ban-TotalBanned',
+            Unit       => 'Count',
+            RawValue   => $total_banned,
+        },
+    ];
+}
+
+1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+App::AWS::CloudWatch::Monitor::Check::Fail2Ban - gather fail2ban jail metrics
+
+=head1 SYNOPSIS
+
+ my $plugin  = App::AWS::CloudWatch::Monitor::Check::Fail2Ban->new();
+ my $metrics = $plugin->check();
+
+ perl bin/aws-cloudwatch-monitor --check Fail2Ban
+
+=head1 DESCRIPTION
+
+C<App::AWS::CloudWatch::Monitor::Check::Fail2Ban> is a C<App::AWS::CloudWatch::Monitor::Check> module which gathers fail2ban jail metrics.
+
+=head1 METRICS
+
+The following metrics are gathered and returned.
+
+=over
+
+=item fail2ban-CurrentlyBanned
+
+The cumulative currently banned for all active jails.
+
+=item fail2ban-TotalBanned
+
+The cumulative total banned for all active jails.
+
+=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 DEPENDENCIES
+
+<App::AWS::CloudWatch::Monitor::Check::Fail2Ban> depends on the external program, C<fail2ban-client>.
+
+=head1 KNOWN ISSUES
+
+C<fail2ban-client> requires root privileges to read the logfiles.  This check must also be run with root privileges because of its dependency on C<fail2ban-client>.
+
+ Permission denied to socket: /var/run/fail2ban/fail2ban.sock, (you must be root)
+
+=cut
-----------------------------------------------------------------------


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


More information about the Bps-public-commit mailing list