diff options
author | Josef Gustafsson <josef.gson@gmail.com> | 2015-09-28 11:51:57 +0200 |
---|---|---|
committer | Josef Gustafsson <josef.gson@gmail.com> | 2015-09-28 11:51:57 +0200 |
commit | df4d69358f7ec6115d835cabe47e749aa04ba6ff (patch) | |
tree | b1742ddb912cde2d4176f3ba3311318a4839ba4d /monitor/josef_monitor.py | |
parent | 90b3ea06bf21659a9b7cfb8f72cbbc7b22d7367d (diff) |
enabling mixed auditing/monitoring. changing timespamp format
Diffstat (limited to 'monitor/josef_monitor.py')
-rwxr-xr-x | monitor/josef_monitor.py | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/monitor/josef_monitor.py b/monitor/josef_monitor.py index 035ef72..f33039a 100755 --- a/monitor/josef_monitor.py +++ b/monitor/josef_monitor.py @@ -36,7 +36,7 @@ else: class ctlog: - def __init__(self, name, url, key, log_id=None): + def __init__(self, name, url, key, log_id=None, build=True): self.name = name self.url = url self.key = key @@ -47,6 +47,7 @@ class ctlog: self.sth = None self.entries = 0 self.root_hash = None + self.build = build self.log("Starting monitor") @@ -58,20 +59,22 @@ class ctlog: except Exception, e: self.log("Failed to fetch STH. " + str(e)) return - start_size = self.entries - while self.entries < self.sth["tree_size"]: - tmp_size = self.entries - self.subtree, self.entries = self.fetch_and_increment_subtree(self.entries, self.sth["tree_size"] -1, self.url, self.subtree) - if tmp_size != self.entries: - self.log("Got entries " + str(tmp_size) + " to " \ - + str(self.entries -1 ) + " of " + str(self.sth["tree_size"]-1)) - - if self.entries != start_size: - if verify_subtree(self.sth, self.subtree, self.url): - self.log("Successfully build tree with " + str(self.entries - start_size) + \ - " new entries. Size: " + str(self.entries)) - else: - self.log("ERROR Failed to build tree from entries.") + + if self.build: + start_size = self.entries + while self.entries < self.sth["tree_size"]: + tmp_size = self.entries + self.subtree, self.entries = self.fetch_and_increment_subtree(self.entries, self.sth["tree_size"] -1, self.url, self.subtree) + if tmp_size != self.entries: + self.log("Got entries " + str(tmp_size) + " to " \ + + str(self.entries -1 ) + " of " + str(self.sth["tree_size"]-1)) + + if self.entries != start_size: + if verify_subtree(self.sth, self.subtree, self.url): + self.log("Successfully build tree with " + str(self.entries - start_size) + \ + " new entries. Size: " + str(self.entries)) + else: + self.log("ERROR Failed to build tree from entries.") def fetch_and_increment_subtree(self, first, last, url, subtree =[[]]): new_leafs = [] @@ -118,7 +121,7 @@ class ctlog: raise e def log(self, string): - s = time.strftime('%Y-%m-%d, %H:%M:%S') + " " + string + s = time.strftime('%Y-%m-%d %H:%M:%S') + " " + string with open(self.logfile, 'a') as f: f.write(s + "\n") f.close() @@ -131,7 +134,7 @@ class ctlog: return try: - check_sth_signature(self.url, new_sth, base64.b64deode(self.key)) + check_sth_signature(self.url, new_sth, base64.b64decode(self.key)) except: self.log("ERROR: Could not verify STH signature") print "ERROR: Could not verify STH signature from " + self.url @@ -397,7 +400,7 @@ def main(args): logs = [] try: for item in CONFIG.CTLOGS: - logs.append(ctlog(item["name"], item["url"], item["key"], item["id"])) + 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..." # Set up state @@ -406,6 +409,7 @@ def main(args): log.load() # Build new entries for log in logs: + # if log.build: log.incremental_build() # Main loop: Monitor @@ -420,6 +424,7 @@ def main(args): if old_sth["timestamp"] != log.sth["timestamp"]: log.verify_progress(old_sth) log.verify_consistency(old_sth) + # if log.build: log.incremental_build() for md in monitored_domains: @@ -453,7 +458,7 @@ def main(args): if __name__ == '__main__': - if not os.path.exists(CONFIG.OUTPUT_DIR): + if CONFIG.OUTPUT_DIR and not os.path.exists(CONFIG.OUTPUT_DIR): os.makedirs(CONFIG.OUTPUT_DIR) if CONFIG.DB_PATH and not os.path.exists(CONFIG.DB_PATH): |