diff options
Diffstat (limited to 'monitor/josef_monitor.py')
-rwxr-xr-x | monitor/josef_monitor.py | 33 |
1 files changed, 19 insertions, 14 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() |