|
Packit |
667938 |
#!/usr/bin/perl
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# ipchainacc version 1.1.0
|
|
Packit |
667938 |
# Author: John Lange, john@darkcore.net
|
|
Packit |
667938 |
# Date: September 12, 2000
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
# This script was written to provide output for MRTG
|
|
Packit |
667938 |
# (multi router traffic grapher) via ipchains.
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
# http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
## Changelog
|
|
Packit |
667938 |
# Sept 12, 2000
|
|
Packit |
667938 |
# v1.1.0 added flag for selection of graphing either packets, or bytes.
|
|
Packit |
667938 |
# The default is packets (which is pretty useless), but since
|
|
Packit |
667938 |
# the previous releases were graphing packets I kept the default
|
|
Packit |
667938 |
# the same.
|
|
Packit |
667938 |
# I always meant for this to be bytes but I only recently noticed
|
|
Packit |
667938 |
# this bug so I added a config flag for bytes.
|
|
Packit |
667938 |
# Also changed the uptime slightly, but its still broken. When
|
|
Packit |
667938 |
# goes past 99 days, it will hack the last digit off (used to happen
|
|
Packit |
667938 |
# after 9 days)
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
# June 22, 2000
|
|
Packit |
667938 |
# v1.0.1 added -x to ipchains to expand byte counters
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
# v1.0.0 Inital Release
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
# This command must return 4 lines of output:
|
|
Packit |
667938 |
# Line 1 : current state of the 'incoming bytes counter'
|
|
Packit |
667938 |
# Line 2 : current state of the 'outgoing bytes counter'
|
|
Packit |
667938 |
# Line 3 : string, telling the uptime of the target.
|
|
Packit |
667938 |
# Line 4 : string, telling the name of the target.
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# This script relies on you having setup your ipchains rules beforehand
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#--- sample ipchains rules that will work with this script
|
|
Packit |
667938 |
## Add some empty rules for accounting purposes only
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
#/sbin/ipchains -F acctin
|
|
Packit |
667938 |
#/sbin/ipchains -F acctout
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
## add the new rules
|
|
Packit |
667938 |
#/sbin/ipchains -N acctin
|
|
Packit |
667938 |
#/sbin/ipchains -N acctout
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
## empty rules on the chains
|
|
Packit |
667938 |
#/sbin/ipchains -A acctin
|
|
Packit |
667938 |
#/sbin/ipchains -A acctout
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
#/sbin/ipchains -I input -j acctin
|
|
Packit |
667938 |
#/sbin/ipchains -I output -j acctout
|
|
Packit |
667938 |
#----------- end ---------------
|
|
Packit |
667938 |
|
|
Packit |
667938 |
## edit for your system
|
|
Packit |
667938 |
|
|
Packit |
667938 |
$ipchains='/sbin/ipchains'; # path to ipchains
|
|
Packit |
667938 |
$host=`/bin/hostname --fqdn`; # local hostname (for information only)
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# if you use the ipchains rules above, you don't have to change these
|
|
Packit |
667938 |
$inrule='acctin'; # name of input accounting rule
|
|
Packit |
667938 |
$outrule='acctout'; # name of output accounting rule
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# What should we graph? packet counters = 0, bytes = 1
|
|
Packit |
667938 |
# If you used this script before and you want to keep counting
|
|
Packit |
667938 |
# packets, then set this to 0. If you would rather do the
|
|
Packit |
667938 |
# sensible thing and count bytes, then set this to 1. If you change
|
|
Packit |
667938 |
# from one to the other, then you should delete all the previous
|
|
Packit |
667938 |
# history since it will be meaningless.
|
|
Packit |
667938 |
$bytec=0;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
## -- don't edit below here ----
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# fetch the status from ipchains
|
|
Packit |
667938 |
$_=`$ipchains -L $inrule -v -n -x |grep -v -i Chain |grep -v -i pkts`;
|
|
Packit |
667938 |
@in_bytes = split;
|
|
Packit |
667938 |
printf "$in_line"; # just for debugging
|
|
Packit |
667938 |
|
|
Packit |
667938 |
$_=`$ipchains -L $outrule -v -n -x |grep -v -i Chain |grep -v -i pkts`;
|
|
Packit |
667938 |
@out_bytes = split;
|
|
Packit |
667938 |
printf "$out_line"; # just for debugging
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#$c=1;
|
|
Packit |
667938 |
#foreach $value (@in_bytes) {
|
|
Packit |
667938 |
# printf "$c: $value\n";
|
|
Packit |
667938 |
# $c++;
|
|
Packit |
667938 |
#};
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# uptime of the machine
|
|
Packit |
667938 |
open(UPTIME,"uptime |cut -b 13-27|");
|
|
Packit |
667938 |
$upTime=<UPTIME>;
|
|
Packit |
667938 |
close(UPTIME);
|
|
Packit |
667938 |
chop $upTime;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# 4 lines of output only.
|
|
Packit |
667938 |
printf "$in_bytes[$bytec]\n$out_bytes[$bytec]\n$upTime\n$host";
|