#!/usr/bin/perl use strict; my $workdir = shift || die "usage: $0 workdir [infile]\n"; my $ipreg = "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"; my $lastip; my %in; my %out; while(<>) { my ($ruleno, $packets, $bytes, $ruletext) = split (/\s+/, $_, 4); if ($ruletext =~ /^count ip from any to ($ipreg)/) { $in{$1} = $bytes; } elsif ($ruletext =~ /^count ip from ($ipreg) to any/) { $out{$1} = $bytes; } elsif ($ruletext =~ /^count ip from any to any in/) { $in{"0.0.0.0"} = $bytes; } elsif ($ruletext =~ /^count ip from any to any out/) { $out{"0.0.0.0"} = $bytes; } } for my $ip (sort keys %in) { if (!-f "$workdir/$ip.rrd") { my $cmd = qq{rrdtool create $workdir/$ip.rrd --step 60 DS:in:DERIVE:600:0:1000000000 DS:out:DERIVE:600:0:1000000000 RRA:AVERAGE:0.5:1:1440 RRA:AVERAGE:0.5:5:600 RRA:AVERAGE:0.5:30:700 RRA:AVERAGE:0.5:120:775 RRA:AVERAGE:0.5:1440:797 RRA:MAX:0.5:1:1440 RRA:MAX:0.5:5:600 RRA:MAX:0.5:30:700 RRA:MAX:0.5:120:775 RRA:MAX:0.5:1440:797 }; $cmd =~ s/\n/ /gs; system $cmd; print STDERR "+" if -t STDERR; } system (qq{rrdtool update $workdir/$ip.rrd -t in:out N:}.$in{$ip}.qq{:}.$out{$ip}); print STDERR "." if -t STDERR; } print STDERR "\n" if -t STDERR;