diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2021-03-04 22:55:25 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2021-03-04 22:55:25 -0500 |
commit | 4e05dcc66315407d38df33b56b5538051c0b4317 (patch) | |
tree | 44fb2a194baf1391fbdd5278f6111ed3b31f6ffe | |
download | log_raider-4e05dcc66315407d38df33b56b5538051c0b4317.tar.gz |
Initial commit
-rw-r--r-- | jenkins_log_raider.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/jenkins_log_raider.py b/jenkins_log_raider.py new file mode 100644 index 0000000..fbf41a6 --- /dev/null +++ b/jenkins_log_raider.py @@ -0,0 +1,69 @@ +import argparse +import os +import sys + + +PIPELINE_MARKER = "[Pipeline]" +PIPELINE_BLOCK_START = '{' +PIPELINE_BLOCK_START_NOTE = '(' +PIPELINE_BLOCK_START_NOTE_END= ')' +PIPELINE_BLOCK_END = '}' +PIPELINE_BLOCK_END_NOTE = "//" + +def consume_token(s, token): + return s[s.find(token) + len(token) + 1:] + + +def parse_log(filename): + block_depth = 0 + block_reading = False + data = open(filename, "r").read() + for lineno, line in enumerate(data.splitlines()): + # Consume pipeline marker + if line.startswith(PIPELINE_MARKER): + event_type = "" + event_name = "" + line = consume_token(line, PIPELINE_MARKER) + + if line.startswith(PIPELINE_BLOCK_END): + line = consume_token(line, PIPELINE_BLOCK_END) + block_reading = False + block_depth -= 1 + + print(f"Block depth: {block_depth}") + elif line.startswith(PIPELINE_BLOCK_END_NOTE): + continue + + if line.startswith(PIPELINE_BLOCK_START): + line = consume_token(line, PIPELINE_BLOCK_START) + if line.startswith(PIPELINE_BLOCK_START_NOTE): + event_name = line[1:len(line) - 1] + block_reading = True + block_depth += 1 + print(f"Block depth: {block_depth}") + else: + event_type = line + + if event_type: + print(f"[{lineno}] Event Type: {event_type}") + if event_name: + print(f"[{lineno}] Event Desc.: {event_name}") + + elif block_reading: + print(f"[{lineno}] Data: {line}") + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('logfile') + args = parser.parse_args() + + if not os.path.exists(args.logfile): + print(f"{args.logfile}: does not exist") + + parse_log(args.logfile) + + +if __name__ == "__main__": + sys.exit(main()) + |