Skip to content

Instantly share code, notes, and snippets.

@foospidy
Created March 20, 2017 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save foospidy/06c263747ea3291dec60b9555cb5f2af to your computer and use it in GitHub Desktop.
Save foospidy/06c263747ea3291dec60b9555cb5f2af to your computer and use it in GitHub Desktop.
#!/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