Quota Usage Checking with Nagios

James Young · January 10, 2013

My ISP (Adam Internet) supplies an XML usage page, which uses Basic authentication.  You sign up on their admin page for a token, and you then use those credentials (username:token) as the creds when fetching the usage page, and you get back a whole bunch of XML.  There’s various smartphone tools to use that data.  What I wanted was a Nagios check, and also for perfdata to go into pnp4nagios from that based on my Internet usage.

At this link you can find a script I wrote which does all of this.  You’ll need to install the LWP and XML::XPath modules to Perl, which you can do in CentOS with;

yum install perl-XML-XPath

LWP should be installed by default.  Usage is quite simple, just call it like this;

check_adam -u username:token -w 90 -c 95

to set warning threshold at 90% and critical threshold at 95%.  The script works by fetching the XML usage data, parsing it using XPath, and pulling out various bits of info.  It then generates a status line for Nagios similar to the following;

OK: 10 of 100 GiB (10%). 0.5 GiB today. Day 24.

Showing you absolute usage, quota, percentage usage, amount used today, and how far you are into your billing cycle.  Threshold is based on the percentage listed there. At some stage I’ll put in some cleverness around alerting if you’re going to run out of quota at your current usage, or something similar.

Perfdata returned is quite extensive - quota, usage overall, usage today, days into cycle, SNR (both directions), Sync speed (both directions), attenuation (both directions).


Twitter, Facebook