- 论坛徽章:
- 0
|
本帖最后由 robinylp 于 2011-04-20 17:27 编辑
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
my @alerts;
my %prtrlinkios = ( "match" => qr/UPDOWN.*Port-channel.*down/,
"hosts" => ".*",
lifetime => 600
);
push(@alerts, \%prtrlinkios);
my %known;
#print Dumper(@alerts);
while(<STDIN>)
{
my $zahl == 0;
my $msg = $_;
/^[^ ]+ +[^ ]+ +[^ ]+ +([^ ]+).* %(.+)$/;
my $host = $1 || "";
my $logline = $2 || $msg;
for(my $i=0; $i<=$#alerts; $i++) {
my $match = $alerts[$i]{"match"};
my $hosts = $alerts[$i]{"hosts"};
if ($logline =~ /$match/ and $host =~ /$hosts/) {
print "Got match!\n";
$zahl++;
if ($known{"$host:$logline"}) {
if ((int $known{"$host:$logline"}) < time()) {
delete($known{"$host:$logline"});
} else {
next;
}
}
$known{"$host:$logline"} = time() + $alerts[$i]{"lifetime"};
open (FD, ">test.txt");
print FD "Logged:\n";
print FD $msg;
print FD "\n".$zahl;
close FD;
}
}
我想要抓取由server发给我的udp包,并且中间有 UPDOWN.*Port-channel.*down 字段的,并进行计数,然后每10分钟输入test.txt文件中。
高手帮忙啊!
在此先谢谢了! |
|