Wow! This is very useful!<br><br>I was thinking on how to generate a networking report a few days ago... tomorrow i will start to the implementation<br><br>Thank you very much!!!<br><br clear="all">J. Guillermo Narváez<br>
OLPC XS Implementation Team - La Rioja | Argentina<br><br><br><div class="gmail_quote">On Tue, Apr 20, 2010 at 8:52 PM, Anna <span dir="ltr"><<a href="mailto:aschoolf@gmail.com">aschoolf@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">First of all, this is very kludgy and rather embarrassing, but I thought I'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> <schoolname> 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're not under my control and I've given up on that point as long as its working. I don't want them showing up as "Other" devices, as that's not an accurate count of what's going on, so I had to account for them in the report.<br>
<br>It's a couple of embarrassingly simple scripts in cron. Here are the dependencies I'm using:<br><br>dhcpstatus <a href="http://dhcpstatus.sourceforge.net/" target="_blank">http://dhcpstatus.sourceforge.net/</a><br>
nmap<br>
vnstat<br>Optional: A working mail server (I'm using ssmtp with gmail)<br><br>There are a couple of edits to the dhcpstatus configuration files, but nothing major and it's clear what to do in the README. If you don't want to email the report, it'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 '{print $3}' | sort | uniq >> /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 >/dev/null 2>&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="<a href="mailto:me@gmail.com" target="_blank">me@gmail.com</a>,<a href="mailto:you@gmail.com" target="_blank">you@gmail.com</a>"<br><br>#####File Location Variables<br><br># This is where the hourly MAC address dumps have been going all day<br>
DATA="/usr/local/dhcpstatus/data/hourlydump"<br><br># This is where we keep all the counts for historical purposes<br>HISTORY="/usr/local/dhcpstatus/data/history"<br><br>##### Define some odds and ends<br>
<br># Good enough range to get any APs on the network<br>RANGE="<a href="http://172.18.96.0/24" target="_blank">172.18.96.0/24</a> <a href="http://172.18.97.0/24" target="_blank">172.18.97.0/24</a> <a href="http://172.18.98.0/24" target="_blank">172.18.98.0/24</a> <a href="http://172.18.99.0/24" target="_blank">172.18.99.0/24</a>"<br>
<br># Pull the school name out of the hostname.<br>SERVER=`hostname | awk "-F." '{print $2}'`<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't need this, then you don'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't have empty lines<br>sed -n '/^$/d' $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="$(($ALL - $XO - $AP))"<br><br>##### Create the body of the email with the network stats<br><br>vnstat -i eth0 > /tmp/eth0<br>
vnstat -i eth1 > /tmp/eth1<br>echo "eth0 (faces the internet)" > /tmp/stats<br>#Edit this line if stuff isn't lining up right<br>echo "___Received___Transmitted___Total" >> /tmp/stats<br>
grep today /tmp/eth0 | head -n 1 >> /tmp/stats<br>echo >> /tmp/stats<br>echo "eth1 (to the XOs)" >> /tmp/stats<br>#Edit this line if stuff isn't lining up right<br>echo "___Received___Transmitted___Total" >> /tmp/stats<br>
grep today /tmp/eth1 | head -n 1 >> /tmp/stats<br><br>###### Send the report and log the data<br><br># This is the email subject line<br>STATUS="$SERVER $(date +%m-%d-%Y) XOs:$XO Other:$OTHER"<br><br># Log the daily status in the history file<br>
echo $STATUS >> $HISTORY<br><br># Email the daily status email. Also works for blog posts.<br>mail -s "$STATUS" $EMAIL < /tmp/stats<br><br>##### Cleanup for tomorrow<br><br>#Clean out the hourlydump file for the next day<br>
rm -f $DATA > /dev/null <br>________________________________________________________________________________<br><br>I have that in the crontab for 6:45 PM so it'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't a priority as its one short line of text per day.<br><br>Thoughts and criticisms are more than welcome.<br><font color="#888888"><br>Anna Schoolfield<br>Birmingham<br><br>
</font><br>_______________________________________________<br>
Server-devel mailing list<br>
<a href="mailto:Server-devel@lists.laptop.org">Server-devel@lists.laptop.org</a><br>
<a href="http://lists.laptop.org/listinfo/server-devel" target="_blank">http://lists.laptop.org/listinfo/server-devel</a><br>
<br></blockquote></div><br>