SF.net SVN: logwatch:[286] trunk/scripts/services/fail2ban

[email protected] Thu, 29 Jan 2015 18:48:29 +0000
Newsgroups gmane.comp.log.logwatch.devel
Message-ID <[email protected]>
Revision: 286
          http://sourceforge.net/p/logwatch/code/286
Author:   opoplawski
Date:     2015-01-29 18:48:28 +0000 (Thu, 29 Jan 2015)
Log Message:
-----------
[fail2ban] Handle INFO Found and Ignore messages

Modified Paths:
--------------
    trunk/scripts/services/fail2ban

Modified: trunk/scripts/services/fail2ban
===================================================================
--- trunk/scripts/services/fail2ban	2015-01-29 17:17:33 UTC (rev 285)
+++ trunk/scripts/services/fail2ban	2015-01-29 18:48:28 UTC (rev 286)
@@ -51,6 +51,8 @@
 my @OtherList = ();
 
 my %ServicesBans = ();
+my %ServicesFound = ();
+my %ServicesIgnored = ();
 
 if ( $Debug >= 5 ) {
 	print STDERR "\n\nDEBUG: Inside Fail2Ban Filter \n\n";
@@ -108,9 +110,11 @@
 	    $ReInitializations++;
     } elsif ($ThisLine =~ /..,... WARNING:  is not a valid IP address/) {
 	# just ignore - this will be fixed within fail2ban and is harmless warning
-    }
-    else
-    {
+    } elsif ( my ($Service,$Host) = ($ThisLine =~ /INFO\s+\[(.*)\] Found (.*)/)) {
+	$ServicesFound{$Service}{$Host}++;
+    } elsif ( my ($Service,$Host) = ($ThisLine =~ /INFO\s+\[(.*)\] Ignore (.*)/)) {
+	$ServicesIgnored{$Service}{$Host}++;
+    } else {
 	# Report any unmatched entries...
 	push @OtherList, "$ThisLine\n";
     }
@@ -149,7 +153,28 @@
     }
 }
 
+if (keys %ServicesFound and $Detail>5) {
+    printf("\nFail2Ban hosts found:\n");
+    foreach my $service (sort {$a cmp $b} keys %ServicesFound) {
+        print("    $service:\n");
+	foreach my $ip (sort {$a cmp $b} keys %{$ServicesFound{$service}}) {
+	    printf("       %-15s (%3d Times)\n", "$ip",
+	       $ServicesFound{$service}{$ip});
+        }
+    }
+}
 
+if (keys %ServicesIgnored and $Detail>5) {
+    printf("\nFail2Ban hosts ignored:\n");
+    foreach my $service (sort {$a cmp $b} keys %ServicesIgnored) {
+        print("    $service:\n");
+	foreach my $ip (sort {$a cmp $b} keys %{$ServicesIgnored{$service}}) {
+	    printf("       %-15s (%3d Times)\n", "$ip",
+	       $ServicesIgnored{$service}{$ip});
+        }
+    }
+}
+
 if ($Detail>0) {
     if ($#IptablesErrors > 0) {
 	   printf("\n%d faulty iptables invocation(s)", $#IptablesErrors);

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/