Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env python
#
# clock_skew.py
# This script reads json data from /tmp/sigsci-agents.json
# and prints a message if an agent's clock skew is greater
# or equal to the defined thresholds.
#
# SigSciApiPy (https://github.com/signalsciences/SigSciApiPy) is
# an easy way to pull agent data from the Signal Sciences API and
# save it to /tmp/sigsci-agents.json
#
# Example usage with SigSciApi.py:
# ./SigSci.py --agents > /tmp/sigsci-agents.json; ./clock_skew.py
#
# Thresholds
WARN = 3
ALERT = 5
import json
agents = open('/tmp/sigsci-agents.json', 'r')
data = json.load(agents)
skew = 0
count = 0
agents.close()
for agent in data['data']:
skew = int(agent['host.clock_skew'])
if skew >= ALERT:
print("ALERT: Clock skew for {0} is {1}".format(agent['agent.name'], skew))
count += 1
elif skew >= WARN:
print("WARNING: Clock skew on {0} is {1}".format(agent['agent.name'], skew))
count += 1
if count == 0:
print("Everything is running on time!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment