I have the following Perl Script
Code:
#!/usr/bin/perl
use RRDs;
# define location of rrdtool databases
my $rrd = '/var/lib/rrd';
# define location of images
my $img = '/var/www/localhost/htdocs/temp/';
&ProcessChain("DROP-INPUT", "Input Chain Drops");
&ProcessChain("DROP-FORWARD","Forward Chain Drops");
sub ProcessChain
{
# process interface
# inputs: $_[0]: Chain Name
# $_[1]: Chain Description
# get info
my $in = `/sbin/iptables -L $_[0] -v | grep LOG | awk '{print \$1}'`;
#my $out =`/sbin/iptables -L $_[0] -v | grep LOG | awk '{print \$2}'`;
# remove eol chars
chomp($in);
print "$_[0] packets in: $in\n";
# if rrdtool database doesn't exist, create it
if (! -e "$rrd/$_[0].rrd")
{
print "creating rrd database for $_[0]...\n";
RRDs::create "$rrd/$_[0].rrd",
"-s 300",
"DS:drop:DERIVE:600:0:12500000",
"RRA:AVERAGE:0.5:1:576",
"RRA:AVERAGE:0.5:6:672",
"RRA:AVERAGE:0.5:24:732",
"RRA:AVERAGE:0.5:144:1460";
}
# insert values into rrd
RRDs::update "$rrd/$_[0].rrd",
"-t", "drop",
"N:$in";
# create traffic graphs
&CreateGraph($_[0], "day", $_[1]);
&CreateGraph($_[0], "week", $_[1]);
&CreateGraph($_[0], "month", $_[1]);
&CreateGraph($_[0], "year", $_[1]);
}
sub CreateGraph
{
# creates graph
# inputs: $_[0]: Chain Name
# $_[1]: interval (ie, day, week, month, year)
# $_[2]: Chain Description
RRDs::graph "$img/$_[0]-$_[1].png",
"-s -1$_[1]",
"-t $_[0] :: $_[2]",
# "--lazy",
"-h", "80", "-w", "600",
"-l 0",
"-a", "PNG",
"-v Packets",
"DEF:drop=$rrd/$_[0].rrd:drop:AVERAGE",
"CDEF:dropav=drop,3600,*",
"AREA:dropav#32CD32:Dropped Packets",
"LINE1:dropav#336600",
"GPRINT:dropav:MAX: Max\\: %5.0lf %s",
"GPRINT:dropav:AVERAGE: Avg\\: %5.1lf %S",
"GPRINT:dropav:LAST: Current\\: %5.0lf %SPackets",
"HRULE:0#000000";
if ($ERROR = RRDs::error) { print "$0: unable to generate $_[0] $_[1] traffic graph: $ERR$
}
Now this _does_ work, with one problem, the values are all wrong.
The graph looks like this
http://mains.bounceme.net/DROP-INPUT-day.png
As you can see, the current value is 12, however the command returns
4. So where is it getting the value of 12?
Could it be the fact that I am storing the Average value in the RRD? I have several other scripts that are virtually the same and they all return the correct values.
Can any one offer any help???[/url]