All pastes #407538 Raw Edit

Untitled

public text v1 · immutable
#407538 ·published 2007-03-24 02:50 UTC
rendered paste body
#!/usr/bin/env perl 

$threadHistory = 5;
$ipHistory = 5;

while (<>) {
    m/\s[A-Z]+\s+\[([^\]]+)\]\s/ || next;
    $thread = $1;

    if (m/(\d+\.\d+\.\d+\.\d+)/) {
        pushIp($1, $_);
    }

    if (m/\scollection failed for\s(\S+)/) {
        $ip = $1;

        print("--- Last for thread ---\n");
        printLastForThread($thread, $_);

        print("--- Last for IP ---\n");
        printLastForIp($ip, $_);

        print("--- Data collection failed ---\n");
        print($_);

        print("\n");
    } else {
        pushThread($thread, $_);
    }
}

sub printLastForThread {
    my $thread = shift(@_);
    my $line = shift(@_);

    if (exists($threads{$thread})) {
        print(@{$threads{$thread}});
    }
}

sub pushThread {
    my $thread = shift(@_);
    my $line = shift(@_);

    if (exists($threads{$thread})) {
        $size = scalar(@{$threads{$thread}});
        if ($size > ($threadHistory - 1)) {
            splice(@{$threads{$thread}}, 0, $size - $threadHistory - 1);
        }
    }

    push(@{$threads{$thread}}, $line);
}

sub printLastForIp {
    my $ip = shift(@_);
    my $line = shift(@_);

    if (exists($ips{$ip})) {
        print(@{$ips{$ip}});
    }
}

sub pushIp {
    my $ip = shift(@_);
    my $line = shift(@_);

    if (exists($ips{$ip})) {
        $size = scalar(@{$ips{$ip}});
        if ($size > ($ipHistory - 1)) {
            splice(@{$ips{$ip}}, 0, $size - $ipHistory - 1);
        }
    }

    push(@{$ips{$ip}}, $line);
}