Skip to content

Instantly share code, notes, and snippets.

@tomoconnor
Created April 12, 2019 13:12
Show Gist options
  • Save tomoconnor/84b51c5f9790d74db1159aa7f930f8c4 to your computer and use it in GitHub Desktop.
Save tomoconnor/84b51c5f9790d74db1159aa7f930f8c4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
import requests
import sys
import xmltodict
GPIO.setmode(GPIO.BCM)
GPIO.cleanup()
GPIO.setwarnings(False)
def GREEN():
GPIO.setup(17, GPIO.OUT)
GPIO.output(17, GPIO.HIGH)
def AMBER():
GPIO.setup(27, GPIO.OUT)
GPIO.output(27, GPIO.HIGH)
def RED():
GPIO.setup(22, GPIO.OUT)
GPIO.output(22, GPIO.HIGH)
def OFF():
GPIO.setup(17, GPIO.OUT)
GPIO.setup(27, GPIO.OUT)
GPIO.setup(22, GPIO.OUT)
GPIO.output(17, GPIO.LOW)
GPIO.output(27, GPIO.LOW)
GPIO.output(22, GPIO.LOW)
username='andon'
passhash='01234567890'
url = "https://mon2k12v-01.example.org/api/gettreenodestats.xml?username=%s&passhash=%s"
r = requests.get(url%(username,passhash), verify=False)
if r.status_code == 200:
xml = xmltodict.parse(r.text)
up = int(xml['data']['upsens'])
warn = int(xml['data']['warnsens'])
down = int(xml['data']['downsens'])
partial = int(xml['data']['partialdownsens'])
unusual = int(xml['data']['unusualsens'])
paused = int(xml['data']['pausedsens'])
undefined = int(xml['data']['undefinedsens'])
total = int(xml['data']['totalsens'])
print "UP: %s" % up
print "DOWN: %s" % down
#by percentage
percentage_down = ((down*1.0) / (total*1.0) ) * 100
print "Network is %s down" % percentage_down
OFF()
if percentage_down > 5.0:
print "RED"
RED()
sys.exit(2)
if percentage_down > 2.5:
print "AMBER"
AMBER()
sys.exit(1)
if percentage_down < 1.0:
print "GREEN"
GREEN()
sys.exit(0)
else:
OFF()
RED()
sys.exit(255)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment