From 9e1eda1ab1b0e8dc8db71502fd1f12c45708b9e6 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Fri, 15 May 2015 09:48:23 +0200 Subject: Handle all dates as UTC. Because timezones, how do they work? Also, print the actual tree head when reporting an old STH. --- tools/check-sth.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'tools') diff --git a/tools/check-sth.py b/tools/check-sth.py index 85e4661..708a438 100755 --- a/tools/check-sth.py +++ b/tools/check-sth.py @@ -9,7 +9,7 @@ import argparse import json import errno import shutil -from datetime import datetime, timedelta +from datetime import datetime, timedelta, tzinfo from certtools import get_sth NAGIOS_OK = 0 @@ -59,14 +59,22 @@ def mv_file(fromfn, tofn): def write_file(fn, sth): open(fn, 'w').write(json.dumps(sth)) +class UTC(tzinfo): + def utcoffset(self, dt): + return timedelta(hours=0) + def dst(self, dt): + return timedelta(0) + def check_age(sth): - now = datetime.now() - sth_time = datetime.fromtimestamp(sth['timestamp'] / 1000) + now = datetime.now(UTC()) + sth_time = datetime.fromtimestamp(sth['timestamp'] / 1000, UTC()) if now > sth_time + timedelta(0, 6 * 3600): - print "CRITICAL: STH older than 6h: ", sth_time + print "CRITICAL: %s is older than 6h: %s" % \ + (sth['sha256_root_hash'], sth_time) sys.exit(NAGIOS_CRIT) if now > sth_time + timedelta(0, 2 * 3600): - print "WARNING: STH older than 2h: ", sth_time + print "WARNING: %s is older than 2h: %s" % \ + (sth['sha256_root_hash'], sth_time) sys.exit(NAGIOS_WARN) def check_treesize(cur, prev): -- cgit v1.1