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

BPS Git Server git at git.bestpractical.com
Tue May 31 22:50:25 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-check-fail2ban".

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

- Log -----------------------------------------------------------------
commit 3c37ab20abf2f1e9a6b2fb5351e121c3b96eb041
Author: Blaine Motsinger <blaine at bestpractical.com>
Date:   Wed Jan 26 18:21:11 2022 -0600

    Add README.md for display on GitHub

diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP
index 60ea4b4..61c20fc 100644
--- a/MANIFEST.SKIP
+++ b/MANIFEST.SKIP
@@ -37,6 +37,8 @@ MYMETA\.json
 MYMETA\.yml$
 \.tar\.gz$$
 
+README.md
+
 # Author tests and files
 996_perl-tidy.t
 997_perl-critic.t
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..4c85d41
--- /dev/null
+++ b/README.md
@@ -0,0 +1,42 @@
+# 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();
+
+    aws-cloudwatch-monitor --check Fail2Ban
+
+# DESCRIPTION
+
+`App::AWS::CloudWatch::Monitor::Check::Fail2Ban` is a [App::AWS::CloudWatch::Monitor::Check](https://metacpan.org/pod/App::AWS::CloudWatch::Monitor::Check) module which gathers fail2ban jail metrics.
+
+# METRICS
+
+Data for this check is read from [fail2ban-client(1)](http://man.he.net/man1/fail2ban-client).  The following metrics are 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(1)](http://man.he.net/man1/fail2ban-client).
+
+# KNOWN ISSUES
+
+[fail2ban-client(1)](http://man.he.net/man1/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(1)](http://man.he.net/man1/fail2ban-client).
+
+    Permission denied to socket: /var/run/fail2ban/fail2ban.sock, (you must be root)
commit b7c29727fdc282ce630ae85f20f8de18033c0ae5
Author: Blaine Motsinger <blaine at bestpractical.com>
Date:   Fri Jan 21 14:31:44 2022 -0600

    Add LICENSE
    
    This commit adds the Apache 2.0 license.

diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..6b0b127
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,203 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   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.
+
diff --git a/lib/App/AWS/CloudWatch/Monitor/Check/Fail2Ban.pm b/lib/App/AWS/CloudWatch/Monitor/Check/Fail2Ban.pm
index c9b7566..5c43667 100644
--- a/lib/App/AWS/CloudWatch/Monitor/Check/Fail2Ban.pm
+++ b/lib/App/AWS/CloudWatch/Monitor/Check/Fail2Ban.pm
@@ -1,3 +1,17 @@
+# Copyright 2021 Best Practical Solutions, LLC <sales at bestpractical.com>
+#
+# 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
+#
+#    https://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 App::AWS::CloudWatch::Monitor::Check::Fail2Ban;
 
 use strict;
commit 822f50112758bf49206ec8e0642fd3a3a8356eb7
Author: Blaine Motsinger <blaine at bestpractical.com>
Date:   Fri Jan 21 14:28:56 2022 -0600

    Add build scaffolding

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d711349
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,13 @@
+MYMETA.*
+blib/
+/nytprof.out*
+/.prove
+*~
+*.swp
+*.swo
+cover_db/
+Makefile
+Makefile.old
+MANIFEST.bak
+App-AWS-CloudWatch-Monitor-Check-Fail2Ban*
+pm_to_blib
diff --git a/Changes b/Changes
new file mode 100644
index 0000000..4b0bbd3
--- /dev/null
+++ b/Changes
@@ -0,0 +1,4 @@
+Revision history for perl module App::AWS::CloudWatch::Monitor::Check::Fail2Ban
+
+0.01 YYYY-MM-DD
+ - Initial version
diff --git a/MANIFEST b/MANIFEST
new file mode 100644
index 0000000..bd3c2c8
--- /dev/null
+++ b/MANIFEST
@@ -0,0 +1,8 @@
+Changes
+lib/App/AWS/CloudWatch/Monitor/Check/Fail2Ban.pm
+LICENSE
+Makefile.PL
+MANIFEST			This list of files
+MANIFEST.SKIP
+README
+t/00_load.t
diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP
new file mode 100644
index 0000000..60ea4b4
--- /dev/null
+++ b/MANIFEST.SKIP
@@ -0,0 +1,46 @@
+# Avoid version control files.
+\bRCS\b
+\bCVS\b
+\bSCCS\b
+,v$
+\B\.svn\b
+\B\.git\b
+\B\.gitignore\b
+\b_darcs\b
+
+# Avoid Makemaker generated and utility files.
+\bMANIFEST\.bak
+\bMakefile$
+\bblib/
+\bMakeMaker-\d
+\bpm_to_blib\.ts$
+\bpm_to_blib$
+\bblibdirs\.ts$         # 6.18 through 6.25 generated this
+
+# Avoid Module::Build generated and utility files.
+\bBuild$
+\b_build/
+
+# Avoid temp and backup files.
+~$
+\.old$
+\#$
+\b\.#
+\.bak$
+
+# Avoid Devel::Cover files.
+\bcover_db\b
+
+t/tmp/
+\.tagstagstags
+MYMETA\.json
+MYMETA\.yml$
+\.tar\.gz$$
+
+# Author tests and files
+996_perl-tidy.t
+997_perl-critic.t
+998_pod-checker.t
+999_pod-coverage.t
+perltidyrc
+perlcriticrc
diff --git a/Makefile.PL b/Makefile.PL
new file mode 100644
index 0000000..4822615
--- /dev/null
+++ b/Makefile.PL
@@ -0,0 +1,43 @@
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+    NAME => 'App::AWS::CloudWatch::Monitor::Check::Fail2Ban',
+    AUTHOR => 'Best Practical Solutions, LLC <modules at bestpractical.com>',
+    ABSTRACT_FROM => 'lib/App/AWS/CloudWatch/Monitor/Check/Fail2Ban.pm',
+    VERSION_FROM => 'lib/App/AWS/CloudWatch/Monitor/Check/Fail2Ban.pm',
+    LICENSE => 'apache_2_0',
+    META_MERGE => {
+        'meta-spec' => { version => 2 },
+        resources => {
+            repository => {
+                type => 'git',
+                url => 'https://github.com/bestpractical/app-aws-cloudwatch-monitor-check-fail2ban.git',
+                web => 'https://github.com/bestpractical/app-aws-cloudwatch-monitor-check-fail2ban',
+            },
+        },
+    },
+
+    MIN_PERL_VERSION => '5.10.1',
+    BUILD_REQUIRES => {
+        'ExtUtils::MakeMaker' => '6.64',  # for TEST_REQUIRES
+    },
+    CONFIGURE_REQUIRES => {
+        'ExtUtils::MakeMaker' => '6.64',
+    },
+    TEST_REQUIRES => {
+        'FindBin' => 0,
+        'File::Find' => 0,
+        'File::Spec' => 0,
+        'Test::More' => '0.98',  # for subtest()
+    },
+    PREREQ_PM => {
+        'parent' => 0,
+        'strict' => 0,
+        'warnings' => 0,
+        'App::AWS::CloudWatch::Monitor' => 0,
+    },
+
+    test => {
+        TESTS => 't/*.t',
+    },
+);
commit c636150254ec219312e4f25d6b60c13238ff09f4
Author: Blaine Motsinger <blaine at bestpractical.com>
Date:   Fri Jan 21 14:26:03 2022 -0600

    Add load and author tests

diff --git a/t/00_load.t b/t/00_load.t
new file mode 100644
index 0000000..ec56611
--- /dev/null
+++ b/t/00_load.t
@@ -0,0 +1,37 @@
+use strict;
+use warnings;
+
+use FindBin;
+use File::Find ();
+use File::Spec ();
+use Test::More;
+
+foreach my $module (find_all_perl_modules()) {
+    use_ok($module) or BAIL_OUT;
+}
+
+done_testing();
+
+sub find_all_perl_modules {
+    my $base = "$FindBin::RealBin/../";
+
+    my @modules;
+    File::Find::find(
+        sub {
+            my $file = $File::Find::name;
+            return unless $file =~ /\.pm$/;
+            return if $file =~ /Test/;
+
+            my $rel_path = File::Spec->abs2rel( $file, $base );
+            return if $rel_path =~ /^blib/;
+            $rel_path =~ s/^[t\/]*lib\///;
+            $rel_path =~ s/\//::/g;
+            $rel_path =~ s/\.pm$//;
+
+            push( @modules, $rel_path );
+        },
+        $base,
+    );
+
+    return @modules;
+}
diff --git a/t/996_perl-tidy.t b/t/996_perl-tidy.t
new file mode 100644
index 0000000..d4a8a51
--- /dev/null
+++ b/t/996_perl-tidy.t
@@ -0,0 +1,22 @@
+use strict;
+use warnings;
+
+use FindBin;
+use Test::More;
+
+unless ( $ENV{TEST_AUTHOR} ) {
+    my $msg = 'Author test. Set $ENV{TEST_AUTHOR} to a true value to run.';
+    plan( skip_all => $msg );
+}
+
+eval { require Test::PerlTidy; };
+
+if ($@) {
+    my $msg = 'Test::PerlTidy required to criticise code';
+    plan( skip_all => $msg );
+}
+
+Test::PerlTidy::run_tests(
+    path       => "$FindBin::RealBin/../lib",
+    perltidyrc => "$FindBin::RealBin/perltidyrc",
+);
diff --git a/t/997_perl-critic.t b/t/997_perl-critic.t
new file mode 100644
index 0000000..40637c2
--- /dev/null
+++ b/t/997_perl-critic.t
@@ -0,0 +1,23 @@
+use strict;
+use warnings;
+
+use FindBin;
+use File::Spec;
+use Test::More;
+
+unless ( $ENV{TEST_AUTHOR} ) {
+    my $msg = 'Author test. Set $ENV{TEST_AUTHOR} to a true value to run.';
+    plan( skip_all => $msg );
+}
+
+eval { require Test::Perl::Critic; };
+
+if ($@) {
+    my $msg = 'Test::Perl::Critic required to criticise code';
+    plan( skip_all => $msg );
+}
+
+my $rcfile = File::Spec->catfile( 't', 'perlcriticrc' );
+Test::Perl::Critic->import( -profile => $rcfile );
+
+all_critic_ok("$FindBin::RealBin/../lib");
diff --git a/t/998_pod-checker.t b/t/998_pod-checker.t
new file mode 100644
index 0000000..503ec4d
--- /dev/null
+++ b/t/998_pod-checker.t
@@ -0,0 +1,19 @@
+use strict;
+use warnings;
+
+use FindBin;
+use Test::More;
+
+unless ( $ENV{TEST_AUTHOR} ) {
+    my $msg = 'Author test. Set $ENV{TEST_AUTHOR} to a true value to run.';
+    plan( skip_all => $msg );
+}
+
+eval { require Test::Pod; };
+
+if ($@) {
+    my $msg = 'Test::Pod required to criticise code';
+    plan( skip_all => $msg );
+}
+
+Test::Pod::all_pod_files_ok( Test::Pod::all_pod_files("$FindBin::RealBin/../lib") );
diff --git a/t/999_pod-coverage.t b/t/999_pod-coverage.t
new file mode 100644
index 0000000..77ab714
--- /dev/null
+++ b/t/999_pod-coverage.t
@@ -0,0 +1,18 @@
+use strict;
+use warnings;
+
+use Test::More;
+
+unless ( $ENV{TEST_AUTHOR} ) {
+    my $msg = 'Author test. Set $ENV{TEST_AUTHOR} to a true value to run.';
+    plan( skip_all => $msg );
+}
+
+eval { require Test::Pod::Coverage; };
+
+if ($@) {
+    my $msg = 'Test::Pod::Coverage required to criticise code';
+    plan( skip_all => $msg );
+}
+
+Test::Pod::Coverage::all_pod_coverage_ok();
diff --git a/t/perlcriticrc b/t/perlcriticrc
new file mode 100644
index 0000000..b410ee0
--- /dev/null
+++ b/t/perlcriticrc
@@ -0,0 +1,204 @@
+### PERLCRITIC OPTIONS
+color = 1
+verbose = %m at %f line %l [%p]\n
+severity = 2
+force = 1
+
+
+### POLICY SETTINGS
+# we don't unpack @_ right away as we mostly use named vars with defaults
+[-Subroutines::RequireArgUnpacking]
+
+# errstr for DBI is okay, and probably others since I like that convention.
+[-Variables::ProhibitPackageVars]
+#packages = DBI
+
+# HEREDOC doesn't adhere to my tidy eye
+[-ValuesAndExpressions::ProhibitImplicitNewlines]
+
+# don't require extended format for shortish regex
+# keeping this in here for documentation purposes
+[-RegularExpressions::RequireExtendedFormatting]
+#minimum_regex_length_to_complain_about = 60
+
+# don't require Carp
+[-ErrorHandling::RequireCarping]
+
+# postfix is okay, unless it's really weird
+[-ControlStructures::ProhibitPostfixControls]
+
+# needless ruleset for modern Perl versions
+[-ValuesAndExpressions::ProhibitInterpolationOfLiterals]
+
+# don't use backticks
+[InputOutput::ProhibitBacktickOperators]
+only_in_void_context = 1
+
+# 3 arg open is modern Perl
+[InputOutput::ProhibitTwoArgOpen]
+
+# close filehandles as soon as possible after opening them.
+[InputOutput::RequireBriefOpen]
+lines = 17
+
+# forbid a bare `## no critic'
+# shouldn't be turning off critic anyway
+[Miscellanea::ProhibitUnrestrictedNoCritic]
+
+# Minimize complexity in code that is outside of subroutines.
+[-Modules::ProhibitExcessMainComplexity]
+max_mccabe = 28
+
+# write `require Module' instead of `require 'Module.pm''.
+[Modules::RequireBarewordIncludes]
+
+# end each module with an explicitly `1;' instead of some funky expression.
+# sorry Charles ;)
+[Modules::RequireEndWithOne]
+
+# always make the 'package' explicit.
+[Modules::RequireExplicitPackage]
+
+# package declaration must match filename.
+[Modules::RequireFilenameMatchesPackage]
+
+# Give every module a `$VERSION' number.
+[Modules::RequireVersionVar]
+
+# don't use vague variable or subroutine names like 'last' or 'record'.
+[NamingConventions::ProhibitAmbiguousNames]
+forbid = last left right no abstract contract record second close
+
+# write `@{ $array_ref }' instead of `@$array_ref'.
+# consistency mostly.  I don't really care either way, but should be consistent.
+[References::ProhibitDoubleSigils]
+
+## REGEX
+[RegularExpressions::ProhibitUnusedCapture]
+[RegularExpressions::ProhibitUnusualDelimiters]
+[-RegularExpressions::RequireDotMatchAnything]
+[-RegularExpressions::RequireLineBoundaryMatching]
+[-RegularExpressions::ProhibitEnumeratedClasses]
+[-RegularExpressions::ProhibitFixedStringMatches]
+
+# don't name things the same as other things
+[Subroutines::ProhibitBuiltinHomonyms]
+
+# too many arguments
+[Subroutines::ProhibitManyArgs]
+
+# don't write `sub my_function (@@) {}'.
+[Subroutines::ProhibitSubroutinePrototypes]
+
+# prevent unused private subroutines.
+[Subroutines::ProhibitUnusedPrivateSubroutines]
+
+# prevent access to private subs in other packages.
+[Subroutines::ProtectPrivateSubs]
+
+# end every path through a subroutine with an explicit `return' statement.
+[Subroutines::RequireFinalReturn]
+
+# shouldn't be turning these off or not defining these
+[TestingAndDebugging::ProhibitNoStrict]
+[TestingAndDebugging::ProhibitNoWarnings]
+[TestingAndDebugging::RequireUseStrict]
+[TestingAndDebugging::RequireUseWarnings]
+
+# unless is okay sometimes
+[-ControlStructures::ProhibitUnlessBlocks]
+
+# don't require constants inplace of magic variables
+# I'm still on the fence about this
+[-ValuesAndExpressions::ProhibitMagicNumbers]
+
+# don't prohibit constant pragma
+[-ValuesAndExpressions::ProhibitConstantPragma]
+
+# don't prohibit long numbers
+[-ValuesAndExpressions::RequireNumberSeparators]
+
+# don't require check of close
+[-InputOutput::RequireCheckedClose]
+
+# allow error strings from syscalls
+[Variables::ProhibitPunctuationVars]
+allow = $! $0
+
+# don't care about noisy quotes
+[-ValuesAndExpressions::ProhibitNoisyQuotes]
+
+# don't care about empty quotes
+[-ValuesAndExpressions::ProhibitEmptyQuotes]
+
+# set sub complexity to 30
+[Subroutines::ProhibitExcessComplexity]
+max_mccabe = 30
+
+# dont prohibit C style for loops
+[-ControlStructures::ProhibitCStyleForLoops]
+
+
+## TODO: re-evaluate these
+# when working on old modules, export is okay
+[-Modules::ProhibitAutomaticExportation]
+
+# Write ` !$foo && $bar || $baz ' instead of ` not $foo && $bar or $baz'.
+[ValuesAndExpressions::ProhibitMixedBooleanOperators]
+
+# Use `my' instead of `local', except when you have to.
+[Variables::ProhibitLocalVars]
+
+# Don't ask for storage you don't need.
+[Variables::ProhibitUnusedVariables]
+
+# don't use 'grep' in void contexts.
+[BuiltinFunctions::ProhibitVoidGrep]
+
+# don't use 'map' in void contexts.
+[BuiltinFunctions::ProhibitVoidMap]
+
+# don't use 'grep' in boolean context
+[BuiltinFunctions::ProhibitBooleanGrep]
+
+# Write `bless {}, $class;' instead of just `bless {};'.
+[ClassHierarchies::ProhibitOneArgBless]
+
+# Use spaces instead of tabs.
+[CodeLayout::ProhibitHardTabs]
+
+# Don't use whitespace at the end of lines.
+[CodeLayout::ProhibitTrailingWhitespace]
+
+# Use the same newline through the source.
+[CodeLayout::RequireConsistentNewlines]
+
+# Must run code through perltidy.
+[CodeLayout::RequireTidyCode]
+
+# Put a comma at the end of every multi-line list declaration, including the last one.
+[CodeLayout::RequireTrailingCommas]
+
+# Don't write long "if-elsif-elsif-elsif-elsif...else" chains.
+[ControlStructures::ProhibitCascadingIfElse]
+
+# Don't use operators like `not', `!~', and `le' within `until' and `unless'.
+[ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions]
+
+# Don't write code after an unconditional `die, exit, or next'.
+[ControlStructures::ProhibitUnreachableCode]
+
+
+## POD
+# The `=head1 NAME' section should match the package.
+# [Documentation::RequirePackageMatchesPodName]
+
+# All POD should be after `__END__'.
+# [Documentation::RequirePodAtEnd]
+
+# Organize your POD into the customary sections.
+[-Documentation::RequirePodSections]
+
+# Don't require links to have text.
+# links to perl man pages are self explanatory.
+[-Documentation::RequirePodLinksIncludeText]
diff --git a/t/perltidyrc b/t/perltidyrc
new file mode 100644
index 0000000..4348b2a
--- /dev/null
+++ b/t/perltidyrc
@@ -0,0 +1,34 @@
+-l=140   # Max line width is 140 cols
+-i=4     # Indent level is 4 cols
+-ci=4    # Continuation indent is 4 cols
+-vt=4    # Maximal vertical tightness
+-cti=0   # No extra indentation for closing brackets
+-pt=1    # Medium parenthesis tightness
+-sbt=1   # Medium square bracket tightness
+-bt=1    # Medium brace tightness (for non-code blocks)
+-bbt=1   # Medium block brace tightness (for code blocks)
+--nospace-for-semicolon
+-nolq    # Don't outdent long quoted strings
+         # Break before all operators:
+-wbb="% + - * / x != == >= <= =~ < > | & **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x="
+
+-fpsc=0  # Don't try to line up all comments to a fixed column
+-hsc     # Align hanging side comments
+-bbs     # Ensure a blank line before every sub definition (except one-liners)
+-bbb     # Ensure a blank line before code blocks (for, while, if, ....)
+
+-bar     # K&R style code braces
+-nolc    # Long comments indented, even when this make the total line length "too long"
+-noll    # Long lines indented, even when this make the total line length "too long"
+-nola    # Don't treat labels as special cases when indenting
+
+-nst     # Do NOT output to STDOUT (since we want to use -b)
+-b       # Backup the input file to .bak and perform all tidying in the original file
+-se      # Write errors to STDERR
+
+-it=4    # iterations
+--block-brace-vertical-tightness=1
+--nospace-terminal-semicolon
+--noadd-semicolons
+-nbl     # --noopening-brace-on-new-line
+--backup-file-extension=/    # delete bak file
commit 78cb6f4624152e65180faa8104d1fd8b993a613a
Author: Blaine Motsinger <blaine at bestpractical.com>
Date:   Fri Jan 21 14:18:53 2022 -0600

    Update documentation

diff --git a/README b/README
index 835e0d4..d0155fc 100644
--- a/README
+++ b/README
@@ -10,11 +10,12 @@ SYNOPSIS
 
 DESCRIPTION
     "App::AWS::CloudWatch::Monitor::Check::Fail2Ban" is a
-    "App::AWS::CloudWatch::Monitor::Check" module which gathers fail2ban
-    jail metrics.
+    App::AWS::CloudWatch::Monitor::Check module which gathers fail2ban jail
+    metrics.
 
 METRICS
-    The following metrics are gathered and returned.
+    Data for this check is read from fail2ban-client(1). The following
+    metrics are returned.
 
     fail2ban-CurrentlyBanned
         The cumulative currently banned for all active jails.
@@ -28,13 +29,13 @@ METHODS
         keys "MetricName", "Unit", "RawValue".
 
 DEPENDENCIES
-    <App::AWS::CloudWatch::Monitor::Check::Fail2Ban> depends on the external
-    program, "fail2ban-client".
+    "App::AWS::CloudWatch::Monitor::Check::Fail2Ban" depends on the external
+    program, fail2ban-client(1).
 
 KNOWN ISSUES
-    "fail2ban-client" requires root privileges to read the logfiles. This
+    fail2ban-client(1) requires root privileges to read the logfiles. This
     check must also be run with root privileges because of its dependency on
-    "fail2ban-client".
+    fail2ban-client(1).
 
      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
index 51a5d7d..c9b7566 100644
--- a/lib/App/AWS/CloudWatch/Monitor/Check/Fail2Ban.pm
+++ b/lib/App/AWS/CloudWatch/Monitor/Check/Fail2Ban.pm
@@ -91,11 +91,11 @@ App::AWS::CloudWatch::Monitor::Check::Fail2Ban - gather fail2ban jail metrics
 
 =head1 DESCRIPTION
 
-C<App::AWS::CloudWatch::Monitor::Check::Fail2Ban> is a C<App::AWS::CloudWatch::Monitor::Check> module which gathers fail2ban jail metrics.
+C<App::AWS::CloudWatch::Monitor::Check::Fail2Ban> is a L<App::AWS::CloudWatch::Monitor::Check> module which gathers fail2ban jail metrics.
 
 =head1 METRICS
 
-The following metrics are gathered and returned.
+Data for this check is read from L<fail2ban-client(1)>.  The following metrics are returned.
 
 =over
 
@@ -121,11 +121,11 @@ Gathers the metric data and returns an arrayref of hashrefs with keys C<MetricNa
 
 =head1 DEPENDENCIES
 
-<App::AWS::CloudWatch::Monitor::Check::Fail2Ban> depends on the external program, C<fail2ban-client>.
+C<App::AWS::CloudWatch::Monitor::Check::Fail2Ban> depends on the external program, L<fail2ban-client(1)>.
 
 =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>.
+L<fail2ban-client(1)> requires root privileges to read the logfiles.  This check must also be run with root privileges because of its dependency on L<fail2ban-client(1)>.
 
  Permission denied to socket: /var/run/fail2ban/fail2ban.sock, (you must be root)
 
commit 1c6cbec2e3380798fdd6e6d7af29cb3dde4b259e
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..835e0d4 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();
+
+     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..51a5d7d
--- /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();
+
+ 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