diff options
author | Linus Nordberg <linus@nordberg.se> | 2015-05-15 09:48:23 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordberg.se> | 2015-05-15 09:48:50 +0200 |
commit | 9e1eda1ab1b0e8dc8db71502fd1f12c45708b9e6 (patch) | |
tree | 982ca666679693bb1534148e1162e91fd2dbc969 /tools/check-sth.py | |
parent | cb788e0a65e33e5595be325805328ddfac4e8277 (diff) |
Handle all dates as UTC.
Because timezones, how do they work?
Also, print the actual tree head when reporting an old STH.
Diffstat (limited to 'tools/check-sth.py')
-rwxr-xr-x | tools/check-sth.py | 18 |
1 files changed, 13 insertions, 5 deletions
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): |