Improve fault detail handling further

Since we already had a "details" field, simply move where it gets added
to the message later, in generate_fault, after the main message value
was used to generate the ID.
This commit is contained in:
2023-12-09 16:13:36 -05:00
parent 4ca2381077
commit 7e6d922877
2 changed files with 27 additions and 21 deletions

View File

@ -21,21 +21,27 @@
from datetime import datetime
from hashlib import md5
from re import sub
def generate_fault(
zkhandler, logger, fault_name, fault_time, fault_delta, fault_message
zkhandler,
logger,
fault_name,
fault_time,
fault_delta,
fault_message,
fault_details=None,
):
# Strip off any "extra" data from the message (things in brackets)
fault_core_message = sub(r"[\(\[].*?[\)\]]", "", fault_message).strip()
# Generate a fault ID from the fault_name, fault_delta, and fault_core_message
fault_str = f"{fault_name} {fault_delta} {fault_core_message}"
# Generate a fault ID from the fault_name, fault_delta, and fault_message
fault_str = f"{fault_name} {fault_delta} {fault_message}"
fault_id = str(md5(fault_str.encode("utf-8")).hexdigest())[:8]
# Strip the microseconds off of the fault time; we don't care about that precision
fault_time = str(fault_time).split(".")[0]
if fault_details is not None:
fault_message = f"{fault_message}: {fault_details}"
# If a fault already exists with this ID, just update the time
if not zkhandler.exists("base.faults"):
logger.out(