summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosef Gustafsson <josef.gson@gmail.com>2015-10-07 10:21:23 +0200
committerJosef Gustafsson <josef.gson@gmail.com>2015-10-07 10:21:23 +0200
commitb8e07a42a095f18d0d07cbb07d18762904145fab (patch)
treeb959b8badd34fae15cc81f55fb24648c379be1cb
parent8340da39b4238024358eec092bb672462596465b (diff)
cleaning up timestamping
-rwxr-xr-xmonitor/josef_monitor.py33
-rw-r--r--monitor/monitor_conf.py6
2 files changed, 21 insertions, 18 deletions
diff --git a/monitor/josef_monitor.py b/monitor/josef_monitor.py
index 8b29443..86b6852 100755
--- a/monitor/josef_monitor.py
+++ b/monitor/josef_monitor.py
@@ -171,8 +171,7 @@ class ctlog:
def log(self, string):
- s = time.strftime('%Y-%m-%d %H:%M:%S') + " " + string
- s = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S') + " " + string
+ s = time_str() + " " + string
with open(self.logfile, 'a') as f:
f.write(s + "\n")
f.close()
@@ -181,8 +180,8 @@ class ctlog:
try:
new_sth, ip = get_sth_and_ip(self.url)
if not ip in self.fe_ips:
- self.fe_ips[ip] = new_sth["timestamp"]
self.log("New Front end IP: " + ip)
+ self.fe_ips[ip] = time_str()
except Exception, e:
self.log(ERROR_STR + "Failed to fetch STH and IP. " +str(e))
return
@@ -192,9 +191,9 @@ class ctlog:
except:
self.log(ERROR_STR + "Could not verify STH signature " + str(new_sth))
self.rollback()
- # print ERROR_STR + "Could not verify STH signature from " + self.url
- sth_time = datetime.datetime.fromtimestamp(new_sth['timestamp'] / 1000, UTC()).strftime("%Y-%m-%d %H:%M:%S")
+ # sth_time = datetime.datetime.fromtimestamp(new_sth['timestamp'] / 1000, UTC()).strftime("%Y-%m-%d %H:%M:%S")
+ sth_time = time_str(new_sth["timestamp"])
if new_sth["timestamp"] != self.sth["timestamp"]:
self.log("STH updated. Size: " + str(new_sth["tree_size"]) + ", Time: " + sth_time)
self.sth = new_sth
@@ -276,7 +275,8 @@ class ctlog:
# print ERROR_STR + " Regression in timestamps in " + self.name
else:
age = time.time() - new["timestamp"]/1000
- sth_time = datetime.datetime.fromtimestamp(new['timestamp'] / 1000, UTC()).strftime("%Y-%m-%d %H:%M:%S")
+ # sth_time = datetime.datetime.fromtimestamp(new['timestamp'] / 1000, UTC()).strftime("%Y-%m-%d %H:%M:%S")
+ sth_time = time_str(new["timestamp"])
roothash = new['sha256_root_hash']
if age > 24 * 3600:
s = ERROR_STR + "STH is older than 24h: %s UTC" % (sth_time)
@@ -399,6 +399,11 @@ class ctlog:
# print "ERROR:", e.read()
# sys.exit(0)
+def time_str(ts = None):
+ if ts is None:
+ return datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
+ else:
+ return datetime.datetime.fromtimestamp(ts / 1000, UTC()).strftime("%Y-%m-%d %H:%M:%S")
def setup_domain_monitoring():
monitored_domains = []
@@ -432,7 +437,7 @@ def main(args):
# Create log objects
for item in CONFIG.CTLOGS:
logs.append(ctlog(item["name"], item["url"], item["key"], item["id"], item["build"]))
- print time.strftime('%H:%M:%S') + " Setting up monitor for " + str(len(logs)) + " logs..."
+ print time_str() + " Setting up monitor for " + str(len(logs)) + " logs..."
# Set up state
for log in logs:
@@ -444,26 +449,26 @@ def main(args):
log.incremental_build()
# Main loop: Monitor
- print time.strftime('%H:%M:%S') + " Running... (see logfiles for output)"
+ print time_str() + " Running... (see logfiles for output)"
while True:
time.sleep(CONFIG.INTERVAL)
for log in logs:
log.update_roots()
old_sth = log.sth
- log.save_state() # Create rollback point in case of failure
- log.update_sth() # Should this be done if later checks fail? (reorder?)
+ log.save_state() # Create rollback point
+ log.update_sth()
if old_sth["timestamp"] != log.sth["timestamp"]:
- log.verify_progress(old_sth)
- log.verify_consistency(old_sth)
- log.incremental_build()
+ log.verify_progress(old_sth) # Does rollback on critical fail
+ log.verify_consistency(old_sth) # Does rollback on critical fail
+ log.incremental_build() # Does rollback on critical fail
for md in monitored_domains:
md.update()
# Normal exit of the program
except KeyboardInterrupt:
- print time.strftime('%H:%M:%S') + ' Received interrupt from user. Saving and exiting....'
+ print time_str() + ' Received interrupt from user. Saving and exiting....'
for log in logs:
log.save()
diff --git a/monitor/monitor_conf.py b/monitor/monitor_conf.py
index ca7b254..5a3737c 100644
--- a/monitor/monitor_conf.py
+++ b/monitor/monitor_conf.py
@@ -18,14 +18,12 @@ DOMAINS_FILE = OUTPUT_DIR + "domains.json"
DB_PATH = './tmpdb/'
MONITORED_DOMAINS = [
- # "*.preishelden.de",
"*.liu.se",
"*.kth.se",
"*.nordu.net",
"*.sunet.se",
- # "mail.google.com",
- # "*.symantec.com",
- # "*.se",
+ "*.dfri.se",
+ "*.iis.se",
]
# Some strings