1#!/usr/bin/perl 2 3# ipchainacc version 1.1.0 4# Author: John Lange, john@darkcore.net 5# Date: September 12, 2000 6# 7# This script was written to provide output for MRTG 8# (multi router traffic grapher) via ipchains. 9# 10# http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html 11# 12## Changelog 13# Sept 12, 2000 14# v1.1.0 added flag for selection of graphing either packets, or bytes. 15# The default is packets (which is pretty useless), but since 16# the previous releases were graphing packets I kept the default 17# the same. 18# I always meant for this to be bytes but I only recently noticed 19# this bug so I added a config flag for bytes. 20# Also changed the uptime slightly, but its still broken. When 21# goes past 99 days, it will hack the last digit off (used to happen 22# after 9 days) 23# 24# June 22, 2000 25# v1.0.1 added -x to ipchains to expand byte counters 26# 27# v1.0.0 Inital Release 28# 29# 30# This command must return 4 lines of output: 31# Line 1 : current state of the 'incoming bytes counter' 32# Line 2 : current state of the 'outgoing bytes counter' 33# Line 3 : string, telling the uptime of the target. 34# Line 4 : string, telling the name of the target. 35 36# This script relies on you having setup your ipchains rules beforehand 37 38#--- sample ipchains rules that will work with this script 39## Add some empty rules for accounting purposes only 40# 41#/sbin/ipchains -F acctin 42#/sbin/ipchains -F acctout 43# 44## add the new rules 45#/sbin/ipchains -N acctin 46#/sbin/ipchains -N acctout 47# 48## empty rules on the chains 49#/sbin/ipchains -A acctin 50#/sbin/ipchains -A acctout 51# 52#/sbin/ipchains -I input -j acctin 53#/sbin/ipchains -I output -j acctout 54#----------- end --------------- 55 56## edit for your system 57 58$ipchains='/sbin/ipchains'; # path to ipchains 59$host=`/bin/hostname --fqdn`; # local hostname (for information only) 60 61# if you use the ipchains rules above, you don't have to change these 62$inrule='acctin'; # name of input accounting rule 63$outrule='acctout'; # name of output accounting rule 64 65# What should we graph? packet counters = 0, bytes = 1 66# If you used this script before and you want to keep counting 67# packets, then set this to 0. If you would rather do the 68# sensible thing and count bytes, then set this to 1. If you change 69# from one to the other, then you should delete all the previous 70# history since it will be meaningless. 71$bytec=0; 72 73## -- don't edit below here ---- 74 75# fetch the status from ipchains 76$_=`$ipchains -L $inrule -v -n -x |grep -v -i Chain |grep -v -i pkts`; 77@in_bytes = split; 78printf "$in_line"; # just for debugging 79 80$_=`$ipchains -L $outrule -v -n -x |grep -v -i Chain |grep -v -i pkts`; 81@out_bytes = split; 82printf "$out_line"; # just for debugging 83 84#$c=1; 85#foreach $value (@in_bytes) { 86# printf "$c: $value\n"; 87# $c++; 88#}; 89 90# uptime of the machine 91open(UPTIME,"uptime |cut -b 13-27|"); 92$upTime=<UPTIME>; 93close(UPTIME); 94chop $upTime; 95 96# 4 lines of output only. 97printf "$in_bytes[$bytec]\n$out_bytes[$bytec]\n$upTime\n$host"; 98