edgreenberg has asked for the wisdom of the Perl Monks concerning the following question:
This little gem comes from the logwatch script that reads the fail2ban log. I'm not getting any output, and put the script under the debugger.
while (defined(my $ThisLine = <STDIN>)) { if ( $Debug >= 5 ) { print STDERR "DEBUG($DebugCounter): $ThisLine"; $DebugCounter++; } chomp($ThisLine); if ( ($ThisLine =~ /..,... DEBUG: /) or ($ThisLine =~ /..,... \S*\s*: DEBUG /) or # syntax of 0.7.? f +ail2ban ($ThisLine =~ /..,... INFO: (Fail2Ban v.* is running|Exiting| +Enabled sections:)/) or ($ThisLine =~ /INFO\s+Log rotation detected for/) or ($ThisLine =~ /INFO\s+Jail.+(?:stopped|started|uses poller)/) + or ($ThisLine =~ /INFO\s+Changed logging target to/) or ($ThisLine =~ /INFO\s+Creating new jail/) or ($ThisLine =~ /..,... \S+\s*: INFO\s+(Set |Socket|Exiting|Gam +in|Created|Added|Using)/) or # syntax of 0.7.? fail2ban ($ThisLine =~ /..,... WARNING: Verbose level is /) or ($ThisLine =~ /..,... WARNING: Restoring firewall rules/) ) { if ( $Debug >= 6 ) { print STDERR "DEBUG($DebugCounter): line ignored\n"; } } elsif ( my ($Service,$Host,$NumFailures) = ($ThisLine =~ m/INFO: + (\S+): (.+) has (\d+) login failure\(s\). Banned./)) { if ($Debug >= 4) { print STDERR "DEBUG: Found host $Host trying to access $Se +rvice - failed $NumFailures times\n"; } push @{$ServicesBans{$Service}{$Host}{'Failures'}}, $NumFailur +es; } elsif ( my ($Service,$Host) = ($ThisLine =~ m/ ERROR:\s(.*):\s(\ +S+)\salready in ban list/)) { $ServicesBans{$Service}{$Host}{'AlreadyInTheList'}++; } elsif ( my ($Service,$Host) = ($ThisLine =~ m/WARNING\s*\[(.*)\] +\s*(\S+)\s*already banned/)) { $ServicesBans{$Service}{$Host}{'AlreadyInTheList'}++; } elsif ( my ($Service,$Host) = ($ThisLine =~ m/ WARNING:\s(.*):\s +ReBan (\S+)/)) { $ServicesBans{$Service}{$Host}{'ReBan'}++; } elsif ($ThisLine =~ / ERROR:?\s*(Execution of command )?\'?iptab +les/) { push @IptablesErrors, "$ThisLine\n"; } elsif ($ThisLine =~ /ERROR.*returned \d+$/) { push @ActionErrors, "$ThisLine\n"; } elsif (($ThisLine =~ /..,... WARNING: \#\S+ reinitialization of +firewalls/) or ($ThisLine =~ / ERROR\s*Invariant check failed. Trying to +restore a sane environment/)) { $ReInitializations++; } elsif ($ThisLine =~ /..,... WARNING: is not a valid IP address/ +) { # just ignore - this will be fixed within fail2ban and is harm +less warning } else { # Report any unmatched entries... push @OtherList, "$ThisLine\n"; } }
When I run this under the debugger, and I advance using the "s" command, should I expect the debugger to stop on each of the elsif statements before evaluating it, or should it only stop if the argument is true?
Many Thanks, Ed Greenberg
Back to
Seekers of Perl Wisdom