Here is some of the code for work in progress for the linksys router
Cacti uses a system that goes as far as I can tell as follows:
[display of graphs]
/\
||
/ = > [data source] ==> [graph] <==\
// /\ \\
|| || ||
[data input method] => [data template] => [graph template]
To read from netflow to cacti, I'm working at the data input method level.
So far, I have got some perl code, that will read the flow-capture files, and return the total bytes for an IP address, for either incoming or outgoing connections, asuming that it has been dumped with flow-print -f 6 into a specific file. This can easily be changed, but its a very basic script at the moment:
#!/usr/bin/perl
# command to create data
#
# usage perl netstat.pl {incoming|outgoing} {IP address}
# /usr/local/netflow/bin/flow-cat /var/netflow/test/2006/2006-01/ |
# /usr/local/netflow/bin/flow-print -f 6 | ~/dump.txt
#if the incomming connections are wanted
if ($ARGV[0] =~ /^incoming$/)
{
# search for all that start with the input IP address
$output = `cat /root/dump.txt | grep -Ew " $ARGV[1] (([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+))" | sort`;
# remove the unneeded source and destination IP addresses, and white space
$output =~ s/$ARGV[1]\s*(([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+))\s*([0-9])*\s*//g;
}
#if the outgoing connections are wanted
else
{
# search for all that start with the input IP address
$output = `cat /root/dump.txt | grep -Ew "(([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)).*$ARGV[1]"`;
# remove the unneeded source and destination IP addresses, and white space
$output =~ s/(([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)).*$ARGV[1]\s*([0-9]+)\s*//g;
}
# remove linebreaks and add + between items
$output =~ s/\n\s/+/g;
#create array to allow sum of bytes transfered to be counted
@output_array = split(/\+/, $output);
$length = @output_array;
#process array
$output = 0;
$i =0;
while ($i < $length)
{
$_ = (pop @output_array);
$output = $output + $_;
$i++;
}
#output the sum of bytes transfered
print "$output\n";
I am learning perl as I go along, so expect improvements in the code
< < Linksys Router > > other pages < < Livejournal feed > >