Skip to content

Instantly share code, notes, and snippets.

@rodrickbrown
Created June 13, 2022 13:13
Show Gist options
  • Save rodrickbrown/7e7086667f279fbeebf09071564c8f53 to your computer and use it in GitHub Desktop.
Save rodrickbrown/7e7086667f279fbeebf09071564c8f53 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# Simple Script to check Std Dev offset
# of ntp servers
def checkStdDev(ntpsd: dict) -> None:
hostnames = ntpsd.keys()
for host in hostnames:
for loglines in ntpsd[host]:
logvalues = [ float(x) for x in loglines[2:len(loglines)] ]
logvalues.insert(0,loglines[0])
stddev = logvalues[-1]
#print(host,logvalues)
if float(stddev) > 1:
print("Firing alert for {} -> Std Dev: {} ntp-server: [{}]".format(host,
logvalues[-1],logvalues[0]))
if __name__ == '__main__':
ntpsd = dict()
ntpsl = list()
with open('output.txt') as logdata:
for line in logdata:
line = line.rstrip()
if len(line) <= 1:
continue
if line.startswith("host:"):
ntpsl = []
hostname = line.split(":")[-1]
continue
ntpsl.append(line.split(","))
ntpsd[hostname] = ntpsl
checkStdDev(ntpsd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment