From c3b87df1b0e5d21459204bf1c102f3824ca46208 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 26 May 2021 16:07:34 +0100 Subject: [PATCH 1/3] EngineerProgress: Progress can be for a single engineer, no array This tweak means we'll look in the event itself instead, but still won't cope with missing expected keys. That's up next.... --- monitor.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/monitor.py b/monitor.py index eeedfbd6..304dc4a4 100644 --- a/monitor.py +++ b/monitor.py @@ -1651,7 +1651,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below :param entry: Journal event dict :return: True if passes validation, else False. """ - # The event should have at least one of thes + # The event should have at least one of these if 'Engineers' not in entry and 'Progress' not in entry: logger.warning(f"EngineerProgress has neither 'Engineers' nor 'Progress': {entry=}") return False @@ -1687,7 +1687,13 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below return False if 'Progress' in entry: - for e in entry['Engineers']: + # Progress can be only a single Engineer, so it's not an array + # { "timestamp":"2021-05-24T17:57:52Z", + # "event":"EngineerProgress", + # "Engineer":"Felicity Farseer", + # "EngineerID":300100, + # "Progress":"Invited" } + for e in entry.get('Engineers', entry): for f in ('Engineer', 'EngineerID', 'Rank', 'Progress', 'RankProgress'): if f not in e: logger.warning(f"Engineer entry without '{f}' key: {e=} in {entry=}") From af5ffabd305992628bdd2d9cc928f5324c0a89a5 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 26 May 2021 16:10:36 +0100 Subject: [PATCH 2/3] EngineerProgress: Cope with no Rank/RankProgress in 'single engineer' form Yes, this isn't DRY, if we do the check a third time I'll pull it out into a helper function. --- monitor.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/monitor.py b/monitor.py index 304dc4a4..667c17e1 100644 --- a/monitor.py +++ b/monitor.py @@ -1696,6 +1696,12 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below for e in entry.get('Engineers', entry): for f in ('Engineer', 'EngineerID', 'Rank', 'Progress', 'RankProgress'): if f not in e: + # For some Progress there's no Rank/RankProgress yet + if f in ('Rank', 'RankProgress'): + if (progress := e.get('Progress', None)) is not None: + if progress in ('Invited', 'Known'): + continue + logger.warning(f"Engineer entry without '{f}' key: {e=} in {entry=}") return False From 6f100a3ebf6aa50546067ce0ce60423204fe4570 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 26 May 2021 16:17:20 +0100 Subject: [PATCH 3/3] EngineerProgress: Duh, we already checked for the array, this is the array-less form This was never properly edited after copy/paste from the "we have an array" form. --- monitor.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/monitor.py b/monitor.py index 667c17e1..c6837b2f 100644 --- a/monitor.py +++ b/monitor.py @@ -1687,23 +1687,22 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below return False if 'Progress' in entry: - # Progress can be only a single Engineer, so it's not an array + # Progress is only a single Engineer, so it's not an array # { "timestamp":"2021-05-24T17:57:52Z", # "event":"EngineerProgress", # "Engineer":"Felicity Farseer", # "EngineerID":300100, # "Progress":"Invited" } - for e in entry.get('Engineers', entry): - for f in ('Engineer', 'EngineerID', 'Rank', 'Progress', 'RankProgress'): - if f not in e: - # For some Progress there's no Rank/RankProgress yet - if f in ('Rank', 'RankProgress'): - if (progress := e.get('Progress', None)) is not None: - if progress in ('Invited', 'Known'): - continue + for f in ('Engineer', 'EngineerID', 'Rank', 'Progress', 'RankProgress'): + if f not in entry: + # For some Progress there's no Rank/RankProgress yet + if f in ('Rank', 'RankProgress'): + if (progress := entry.get('Progress', None)) is not None: + if progress in ('Invited', 'Known'): + continue - logger.warning(f"Engineer entry without '{f}' key: {e=} in {entry=}") - return False + logger.warning(f"Progress event without '{f}' key: {entry=}") + return False return True