Skip to content

Instantly share code, notes, and snippets.

@tbaschak
Created November 20, 2019 01:04
Show Gist options
  • Save tbaschak/ee6a07cd54eff3826e3fa5ce3eb47332 to your computer and use it in GitHub Desktop.
Save tbaschak/ee6a07cd54eff3826e3fa5ce3eb47332 to your computer and use it in GitHub Desktop.
Python3 Nagios check plugin that will notify if MBIX RS configs get more than a day out of date.
#!/usr/bin/env python3
import sys
from datetime import datetime
import requests
rs = { 'rs1': 'http://lg.mbix.ca/rs1.txt',
'rs2': 'http://lg.mbix.ca/rs2.txt'}
now = datetime.now()
timestamp = int(datetime.timestamp(now))
status = 'good'
status_msg = ''
for routeserver in rs:
response = requests.get(rs[routeserver])
data = response.text
rs_lastupdated = int(data.rstrip())
update_delta = timestamp - rs_lastupdated
if( update_delta > 86400 ):
status = 'major'
status_msg += routeserver + ' was last updated over a day ago (' + str(update_delta) + 's ago). '
elif ( update_delta > 45000 ):
status = 'minor'
status_msg += routeserver + ' was last updated over a 12h ago (' + str(update_delta) + 's ago). '
#Determine state to pass to Nagios
#CRITICAL = 2
#WARNING = 1
#OK = 0
if status == 'major':
print("%s" % (status_msg))
sys.exit(2)
elif status == 'minor':
print("%s" % (status_msg))
sys.exit(1)
elif status == 'good':
print("Route Servers are current")
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment