[mrtg] quick & dirty dhcp scripts

Eric Garnel egarnel3470 at yahoo.com
Fri Apr 25 00:11:50 MEST 2003


I threw together a quick script that graphs active & inactive dhcp
clients.
It requires fping and there is probably a much better way to do this.

NOTE: touch the tmp files 1st 

It consists of 2 scripts called in crontab, 233combo and combo.pl
that  are called every so often

#Author: Eric Garnel
#Date: April 24, 2003
# 233combo
#Rev: 1.0
# cheesy dhcp count scripts
#
# empty the bucket
>/tmp/233_dhcp.log;
#
# get more stuff in
#
/usr/sbin/fping -g 198.214.233.30 198.214.233.250 >
/tmp/233_dhcp.log;
# sift thru it
/bin/grep -c alive /tmp/233_dhcp.log > /tmp/dhcp233up;
>/tmp/dhcp233down;
#
# get more stuff in
#
#/usr/sbin/fping -g 198.214.233.30 198.214.233.250 >
/tmp/233_dhcp-down.log;
# sift thru it
/bin/grep -c unreachable /tmp/233_dhcp.log > /tmp/dhcp233down;

---combo.pl

#!/usr/bin/perl
#
#Author: Eric Garnel
#Date: April 24, 2003
#Rev: 1.0
# combo.pl

        open (INPUT, "</tmp/dhcp233up")
        or die "couldn't open file\n";
while (<INPUT>) {
        chomp;
print "$_\n";}
#
open (INPUT, "</tmp/dhcp233down")
        or die "couldn't open file\n";
while (<INPUT>) {
        chomp;
print "$_\n";
print "0\n";
print "0\n";
}

sample mrtg config
######## dhcp 233 count
Target[233dhcp]: `/usr/bin/perl /etc/mrtg/combo.pl`
Options[233dhcp]: growright,gauge,nopercent,nolegend
MaxBytes[233dhcp]: 220
Title[233dhcp]: Total number of active hosts in 233 subnet
PageTop[233dhcp]: <H1>Total number of active hosts in 233 subnet : 30
to 250</H1>
YLegend[233dhcp]: 233 Subnet
ShortLegend[233dhcp]:  hosts
Legend1[233dhcp]: Active Hosts $nbsp;
Legend2[233dhcp]:
Legend3[233dhcp]: Inactive Hosts
Legend4[233dhcp]:
LegendI[233dhcp]: Active Hosts
LegendO[233dhcp]: Inactive Hosts



=====

Eric Garnel CCNP, MCSE



eric at garnel.com

 

 

--
Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Archive     http://www.ee.ethz.ch/~slist/mrtg
FAQ         http://faq.mrtg.org    Homepage     http://www.mrtg.org
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the mrtg mailing list