First of all, this is very kludgy and rather embarrassing, but I thought I&#39;d post it in case other folks wanted to expand on the idea or someone out there needed a similar report.<br><br>Anyway, on XS 0.6, I managed to cobble together a daily report that looks like this:<br>
<br>    &lt;schoolname&gt; 04-15-2010 XOs:37 Other:7<br><br>    eth0 (faces the internet)<br>    _____Received___Transmitted___Total<br>    today 573.00 MB | 46.22 MB | 619.23 MB<br><br>    eth1 (to the XOs)<br>    _____Received___Transmitted___Total<br>
    today 70.66 MB | 702.79 MB | 773.45 MB<br><br>Basically I wanted daily reporting on how many unique XOs and other devices (iPhones, laptops, etc) got dhcp leases and about how much traffic went through the tubes. The report needs to be short and clear enough so that non-technical folks can understand it.  Also, I wanted a gist of the differential in traffic due to Squid caching, which can be seen in the above example.<br>
<br>My situation here is complicated by the APs getting dynamic dhcp leases.  Yes, I know, but they&#39;re not under my control and I&#39;ve given up on that point as long as its working.  I don&#39;t want them showing up as &quot;Other&quot; devices, as that&#39;s not an accurate count of what&#39;s going on, so I had to account for them in the report.<br>
<br>It&#39;s a couple of embarrassingly simple scripts in cron.  Here are the dependencies I&#39;m using:<br><br>dhcpstatus    <a href="http://dhcpstatus.sourceforge.net/">http://dhcpstatus.sourceforge.net/</a><br>nmap<br>
vnstat<br>Optional: A working mail server (I&#39;m using ssmtp with gmail)<br><br>There are a couple of edits to the dhcpstatus configuration files, but nothing major and it&#39;s clear what to do in the README.  If you don&#39;t want to email the report, it&#39;s easy enough to throw into a text file for Apache or whatever.<br>
<br>Once I configured dhcpstatus, I created a directory for the data in /usr/local/dhcpstatus and did this silly little script in /usr/local/bin, making sure that /usr/local/bin was in my path in the crontab.<br><br>[root@schoolserver ~]# cat /usr/local/bin/hourly-dhcp-lease-dump <br>
#!/bin/bash<br>#Pull a list of all the Mac Addresses with current dhcp leases and dump into a file<br>dhcpstatus -s 172.18.96.0 | grep Mac | awk &#39;{print $3}&#39; | sort | uniq &gt;&gt; /usr/local/dhcpstatus/data/hourlydump<br>
<br>I have it run every hour from 6:30 AM to 6:30 PM.  Probably overkill, but it only takes a few seconds.<br><br>30 6-18 * * * /usr/local/bin/hourly-dhcp-lease-dump &gt;/dev/null 2&gt;&amp;1<br><br>Also in /usr/local/bin, I did up the script for the report.  I put lines around it as its rather long.<br>
________________________________________________________________________________<br><br>[root@schoolserver ~]# cat /usr/local/bin/daily-dhcp-lease-report <br>#!/bin/bash<br><br>##### Who do we want to send this to?  Separate multiple email addresses with a comma<br>
EMAIL=&quot;<a href="mailto:me@gmail.com">me@gmail.com</a>,<a href="mailto:you@gmail.com">you@gmail.com</a>&quot;<br><br>#####File Location Variables<br><br># This is where the hourly MAC address dumps have been going all day<br>
DATA=&quot;/usr/local/dhcpstatus/data/hourlydump&quot;<br><br># This is where we keep all the counts for historical purposes<br>HISTORY=&quot;/usr/local/dhcpstatus/data/history&quot;<br><br>##### Define some odds and ends<br>
<br># Good enough range to get any APs on the network<br>RANGE=&quot;<a href="http://172.18.96.0/24">172.18.96.0/24</a> <a href="http://172.18.97.0/24">172.18.97.0/24</a> <a href="http://172.18.98.0/24">172.18.98.0/24</a> <a href="http://172.18.99.0/24">172.18.99.0/24</a>&quot;<br>
<br># Pull the school name out of the hostname.<br>SERVER=`hostname | awk &quot;-F.&quot; &#39;{print $2}&#39;`<br><br>##### Dealing with data ...<br><br>#-----Getting information on the network via nmap----<br># The only things on the network with open telnet ports should be the access points<br>
# If you don&#39;t need this, then you don&#39;t need to run this script as root<br>AP=`nmap -sS -p 23 $RANGE | grep -c open`<br><br># Make sure the daily dump file doesn&#39;t have empty lines<br>sed -n &#39;/^$/d&#39; $DATA<br>
<br># Get a count of all the unique XOs in the hourly dump file<br># This will change with the XO 1.5<br>XO=`cat $DATA | sort | uniq | grep -c 00:17:c4`<br><br># Get a count of all the unique devices in the hourly dump file<br>
ALL=`cat $DATA | sort | uniq | wc -l`<br><br># Calculate the number of non-XO Devices<br>OTHER=&quot;$(($ALL - $XO - $AP))&quot;<br><br>##### Create the body of the email with the network stats<br><br>vnstat -i eth0 &gt; /tmp/eth0<br>
vnstat -i eth1 &gt; /tmp/eth1<br>echo &quot;eth0 (faces the internet)&quot; &gt; /tmp/stats<br>#Edit this line if stuff isn&#39;t lining up right<br>echo &quot;___Received___Transmitted___Total&quot; &gt;&gt; /tmp/stats<br>
grep today /tmp/eth0 | head -n 1 &gt;&gt; /tmp/stats<br>echo &gt;&gt; /tmp/stats<br>echo &quot;eth1 (to the XOs)&quot; &gt;&gt; /tmp/stats<br>#Edit this line if stuff isn&#39;t lining up right<br>echo &quot;___Received___Transmitted___Total&quot; &gt;&gt; /tmp/stats<br>
grep today /tmp/eth1 | head -n 1 &gt;&gt; /tmp/stats<br><br>###### Send the report and log the data<br><br># This is the email subject line<br>STATUS=&quot;$SERVER $(date +%m-%d-%Y) XOs:$XO Other:$OTHER&quot;<br><br># Log the daily status in the history file<br>
echo $STATUS &gt;&gt; $HISTORY<br><br># Email the daily status email.  Also works for blog posts.<br>mail -s &quot;$STATUS&quot; $EMAIL &lt; /tmp/stats<br><br>##### Cleanup for tomorrow<br><br>#Clean out the hourlydump file for the next day<br>
rm -f $DATA &gt; /dev/null <br>________________________________________________________________________________<br><br>I have that in the crontab for 6:45 PM so it&#39;s ready for night owls and early risers.<br><br>45 18 * * * /usr/local/bin/daily-dhcp-lease-report<br>
<br>Rotating the history file really isn&#39;t a priority as its one short line of text per day.<br><br>Thoughts and criticisms are more than welcome.<br><br>Anna Schoolfield<br>Birmingham<br><br>