Created
June 23, 2011 15:08
-
-
Save waffle2k/1042711 to your computer and use it in GitHub Desktop.
Dynamically call worker modules from a directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use lib( "/home/pblair/lp.beta/logparse/lib" ); | |
use File::Glob ':glob'; | |
use RBL::ProcessAggregate; | |
use RBL::Whitelist; | |
my @libs = bsd_glob('/home/pblair/lp.beta/logparse/lib/RBL/ProcessAggregate/*.pm'); | |
s/.*\/(\S+?)\.pm$/$1/ for @libs; | |
eval "require RBL::ProcessAggregate::$_" for @libs; | |
use constant INPUT => '/home/abuse/filterd-log-parsing/aggregate.json'; | |
use constant WHITELIST => '/var/run/logparse/whitelist.cidr'; | |
my $whitelist = RBL::Whitelist->new( WHITELIST ); | |
my ($ham,$spam) = RBL::ProcessAggregate::parse_aggregate( INPUT ); | |
$ham = RBL::ProcessAggregate::whitelist( $ham, $whitelist ); | |
$spam = RBL::ProcessAggregate::whitelist( $spam, $whitelist ); | |
my %workers = map { lc( $_ ) => "RBL::ProcessAggregate::" . $_ . "::process" } @libs; | |
for( keys %workers ){ | |
my @a = do { no strict "refs"; $workers{"$_"}( $ham, $spam ); }; | |
for my $ip ( @a ){ | |
my ($h,$s) = ( $ham->{$ip} * 1.0, $spam->{$ip} * 1.0 ); | |
my $total = $h + $s * 1.0; | |
$total = $s / $total; | |
printf "[%s],%s,%s,%s,%f\n", $_, | |
$ip, | |
$h, | |
$s, | |
$total; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment