<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Evan Hoffman&#039;s silly writings. &#187; nmap</title>
	<atom:link href="http://www.evanhoffman.com/evan/tag/nmap/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.evanhoffman.com/evan</link>
	<description>When 3-nines uptime is just way too much.</description>
	<lastBuildDate>Mon, 06 Sep 2010 00:36:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Running MRTG cfgmaker across your entire subnet?</title>
		<link>http://www.evanhoffman.com/evan/2010/01/27/running-mrtg-cfgmaker-across-your-entire-subnet/</link>
		<comments>http://www.evanhoffman.com/evan/2010/01/27/running-mrtg-cfgmaker-across-your-entire-subnet/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 17:00:30 +0000</pubDate>
		<dc:creator>evan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mrtg]]></category>
		<category><![CDATA[nmap]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[routers2.cgi]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://www.evanhoffman.com/evan/?p=336</guid>
		<description><![CDATA[I realized recently that I had a bunch of newly-provisioned VMs that weren&#8217;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 [...]]]></description>
			<content:encoded><![CDATA[<p>I realized recently that I had a bunch of newly-provisioned VMs that weren&#8217;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.</p>
<p><span id="more-336"></span></p>
<p><strong>Step 1: Build a list of hosts to monitor</strong></p>
<p>For this I used an nmap ping test to generate a list of &#8220;up&#8221; hosts:</p>
<p><code>nmap -sP 10.0.0.0/24 -oG 10.0.0.0-255.255.255.0</code></p>
<p>This creates a list of IPs that are up in a format like this:</p>
<p><code><br />
Host: 10.0.0.60 ()      Status: Up<br />
Host: 10.0.0.61 ()      Status: Up<br />
Host: 10.0.0.63 ()      Status: Up<br />
Host: 10.0.0.64 ()      Status: Up<br />
Host: 10.0.0.65 ()      Status: Up<br />
</code></p>
<p><strong>Step 2: Parse out the IP address and run cfgmaker</strong></p>
<p>Here&#8217;s the command I ran:</p>
<p><code>$ 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</code></p>
<p>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] . </p>
<p>Taking this a step further, I used gethostbyaddr to resolve the IPs to hostnames, so the MRTG files have the proper  hostnames in them:</p>
<p><code>$ 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</code></p>
<p>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?</p>
<p><code> cat /etc/mrtg/*.cfg > /etc/mrtg-all.cfg</code></p>
<p>Then you only have one cron entry.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.evanhoffman.com/evan/2010/01/27/running-mrtg-cfgmaker-across-your-entire-subnet/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
