AussieBroadband CheckMK Plugin

James Young · September 12, 2018

I’ve recently changed my ISP to AussieBroadband.  Since I’m now working under a quota, I want a way to monitor my quota in CheckMK.  Enter a bit of python.  If you want to use this, you’ll need to adjust the hashbang to suit your actual OMD site, and then pass a parameter which is your username:password to get onto your ABB account.

#!/omd/sites/checkmk/bin/python2.7
#
# Parses AussieBroadband Quota Page to generate a CheckMK alert and stats pages
#

import requests
import re
import time
import sys
import json

status = 0
statustext = "OK"

try:
creds = sys.argv[1].split(":")

# Create a new session
s = requests.Session()

# Process a logon
headers = {
'User-Agent': 'abb_usage.py'
}
payload = {
'username': creds[0],
'password': creds[1]
}
s.post('https://myaussie-auth.aussiebroadband.com.au/login', headers=headers, data=payload)

# Fetch customer data and service id
r = s.get('https://myaussie-api.aussiebroadband.com.au/customer', headers=headers)
customer = json.loads(r.text)
sid = str(customer["services"]["NBN"][0]["service_id"])

# Fetch usage of the first service id
r = s.get('https://myaussie-api.aussiebroadband.com.au/broadband/'+sid+'/usage', headers=headers)
usage = json.loads(r.text)
quota_left = usage["remainingMb"]
quota_up = usage["uploadedMb"]
quota_down = usage["downloadedMb"]

# Derive some parameters for the check
total = quota_left + quota_up + quota_down
critthresh = 0.10*total
warnthresh = 0.25*total

# Determine the status of the check
if quota_left < critthresh:
status = 2
statustext = "CRITICAL"
elif quota_left < warnthresh:
status = 1
statustext = "WARNING"

# Format the output message
print "{7} - {1} MB quota remaining|left={1};{2};{3};0;{4}, upload={5}, download={6}".format( \
status, \
int(quota_left), \
int(warnthresh), \
int(critthresh), \
int(total), \
int(quota_up), \
int(quota_down), \
statustext)

except:
print "UNKNOWN - Unable to parse usage page!"
status = 3
statustext = "UNKNOWN"

sys.exit(status)

Enjoy.  It’s pretty quick and dirty, but it works.  You put this into your site’s local/lib/nagios/plugins directory, then add it as a classical check.

Twitter, Facebook