Running MRTG cfgmaker across your entire subnet?

I realized recently that I had a bunch of newly-provisioned VMs that weren’t being monitored by MRTG (one of the tools we use to monitor network usage and other fun stats). Rather than manually run cfgmaker against all the new machines, I decided to script my way out of this.

Step 1: Build a list of hosts to monitor

For this I used an nmap ping test to generate a list of “up” hosts:

nmap -sP 10.0.0.0/24 -oG 10.0.0.0-255.255.255.0

This creates a list of IPs that are up in a format like this:


Host: 10.0.0.60 () Status: Up
Host: 10.0.0.61 () Status: Up
Host: 10.0.0.63 () Status: Up
Host: 10.0.0.64 () Status: Up
Host: 10.0.0.65 () Status: Up

Step 2: Parse out the IP address and run cfgmaker

Here’s the command I ran:

$ for i in `perl -ne 'chomp; next if $_ =~ /^#/; my @a = split(/ /); print "$a[1]\n";' 10.0.0.0-255.255.255.0`; do /usr/bin/cfgmaker --global 'LogFormat: rrdtool' --global 'WorkDir: /mrtg/data/mrtg' --global 'Options[_]: growright,bits' --global 'XSize[_]: 600' --global 'YSize[_]: 400' public@$i > /etc/mrtg/mrtg-$i ; done

This parses out the IP address from the input file and for each address, runs cfgmaker and puts the output in /etc/mrtg/mrtg-[ipaddress] .

Taking this a step further, I used gethostbyaddr to resolve the IPs to hostnames, so the MRTG files have the proper hostnames in them:

$ for i in `perl -MSocket -ne 'chomp; next if $_ =~ /^#/; my @a = split(/ /); my $ip = inet_aton($a[1]); my $host = gethostbyaddr($ip, AF_INET); print "$host\n";' 10.0.0.0-255.255.255.0`; do /usr/bin/cfgmaker --global 'LogFormat: rrdtool' --global 'WorkDir: /mrtg/data/mrtg' --global 'Options[_]: growright,bits' --global 'XSize[_]: 600' --global 'YSize[_]: 400' public@$i > /etc/mrtg/mrtg-$i ; done

Then all of the mrtg .cfg config files are in /etc/mrtg/, but who wants to put in all those cron entries to run each one? Not me. Simple fix?

cat /etc/mrtg/*.cfg > /etc/mrtg-all.cfg

Then you only have one cron entry.

Advertisements

2 thoughts on “Running MRTG cfgmaker across your entire subnet?”

  1. Have you ever tried to get MRTG to read anything off of the Actiontec router, by chance? 🙂

    Seems that there’s a script for “misterhouse” that’s supposed to do it but I could never get it working..

    “David Norwood :: Tue, 30 Sep 2008 – added a new script and web page to monitor and graph internet traffic from an Actiontec MI424-WR used by Verizon FIOS”

  2. Well, I don’t know if the Fios Actiontec router supports SNMP. If it does I don’t know how to get into it. With my Cablevision cable modem it was pretty easy – public@192.168.100.1 I think was all it took. But I haven’t found anything indicating that the Actiontec router is SNMP-queryable, so I don’t know how MRTG would work.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s