diff options
Diffstat (limited to 'monitor/gaol/gaol_auditor.py')
-rwxr-xr-x | monitor/gaol/gaol_auditor.py | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/monitor/gaol/gaol_auditor.py b/monitor/gaol/gaol_auditor.py index d2da59b..4e2aca5 100755 --- a/monitor/gaol/gaol_auditor.py +++ b/monitor/gaol/gaol_auditor.py @@ -85,24 +85,34 @@ class ctlog: raise e - def log(self, string): - s = time_str() + " " + string + def log(self, string, t="INFO"): + # s = time_str() + " " + string + if t == "ERROR": + s = time_str() + " " + ERROR_STR + string + email(s) + elif t == "WARNING": + s = time_str() + " " + WARNING_STR + string + elif t == "INFO": + s = time_str() + " " + string + else: + print "UNKNOWN LOGGING TYPE: " + t + with open(self.logfile, 'a') as f: f.write(s + "\n") f.close() - email(s) + # email(s) def update_sth(self): try: new_sth = get_sth(self.url) except Exception, e: - self.log(ERROR_STR + "Failed to fetch STH. " +str(e)) + self.log("Failed to fetch STH. " +str(e), "ERROR") return try: check_sth_signature(self.url, new_sth, base64.b64decode(self.key)) except: - self.log(ERROR_STR + "Could not verify STH signature " + str(new_sth)) + self.log("Could not verify STH signature " + str(new_sth), "ERROR") if self.sth: sth_time = time_str(new_sth["timestamp"]) @@ -119,28 +129,27 @@ class ctlog: try: if new["tree_size"] == old["tree_size"]: if old["sha256_root_hash"] != new["sha256_root_hash"]: - self.log(ERROR_STR + "New root hash for same tree size! Old:" + str(old) + " New:" + str(new)) + self.log("New root hash for same tree size! Old:" + str(old) + " New:" + str(new), "ERROR") elif new["tree_size"] < old["tree_size"]: - self.log(ERROR_STR + "New tree is smaller than old tree! Old:" + str(old) + " New:" + str(new)) + self.log("New tree is smaller than old tree! Old:" + str(old) + " New:" + str(new), "ERROR") if new["timestamp"] < old["timestamp"]: - self.log(ERROR_STR + "Regression in timestamps! Old:" + str(old) + " New:" + str(new)) + self.log("Regression in timestamps! Old:" + str(old) + " New:" + str(new), "ERROR") else: age = time.time() - new["timestamp"]/1000 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) - self.log(s + str(new)) - print s + self.log("STH is older than 24h: %s UTC" % (sth_time) + str(new), "ERROR") + # print s elif age > 12 * 3600: - s = "WARNING: STH is older than 12h: %s UTC" % (sth_time) - self.log(s) + s = "STH is older than 12h: %s UTC" % (sth_time) + self.log(s, "WARNING") elif age > 6 * 3600: - s = "WARNING: STH is older than 6h: %s UTC" % (sth_time) - self.log(s) + s = "STH is older than 6h: %s UTC" % (sth_time) + self.log(s, "WARNING") except Exception, e: - self.log(ERROR_STR + "Failed to verify progress! Old:" + str(old) + " New:" + str(new) + " Exception: " + str(e)) + self.log("Failed to verify progress! Old:" + str(old) + " New:" + str(new) + " Exception: " + str(e), "ERROR") def verify_consistency(self, old): new = self.sth @@ -153,15 +162,15 @@ class ctlog: res = verify_consistency_proof(decoded_consistency_proof, old["tree_size"], new["tree_size"], base64.b64decode(old["sha256_root_hash"])) if old["sha256_root_hash"] != str(base64.b64encode(res[0])): - self.log(ERROR_STR + "Verification of consistency for old hash failed! Old:" \ + self.log("Verification of consistency for old hash failed! Old:" \ + str(old) + " New:" + str(new) + " Calculated:" + str(base64.b64encode(res[0]))\ - + " Proof:" + str(consistency_proof)) + + " Proof:" + str(consistency_proof), "ERROR") elif new["sha256_root_hash"] != str(base64.b64encode(res[1])): - self.log(ERROR_STR + "Verification of consistency for new hash failed! Old:" \ - + str(old) + " New:" + str(new) + " Proof:" + str(consistency_proof)) + self.log("Verification of consistency for new hash failed! Old:" \ + + str(old) + " New:" + str(new) + " Proof:" + str(consistency_proof), "ERROR") except Exception, e: - self.log(ERROR_STR + "Could not verify consistency! " + " Old:" + str(old) + " New:" + str(new) + " Error:" + str(e)) + self.log("Could not verify consistency! " + " Old:" + str(old) + " New:" + str(new) + " Error:" + str(e), "ERROR") |