From 4003204f1423abfde966271f0f5379c3a63b3115 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Sat, 9 Dec 2023 14:11:00 -0500 Subject: [PATCH] Remove bracketed text from fault_str This ensures that certain faults e.g. Ceph status faults, will be combined despite the added text in brackets, while still keeping them mostly separate. Also ensure the health text is updated each time to assist with this, as this health text may now change independent of the fault ID. --- daemon-common/faults.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/daemon-common/faults.py b/daemon-common/faults.py index d4fb1d50..b3b166bc 100644 --- a/daemon-common/faults.py +++ b/daemon-common/faults.py @@ -21,13 +21,16 @@ 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 ): - # Generate a fault ID from the fault_message and fault_delta - fault_str = f"{fault_name} {fault_delta} {fault_message}" + # 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}" 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 @@ -63,6 +66,7 @@ def generate_fault( zkhandler.write( [ (("faults.last_time", fault_id), fault_time), + (("faults.message", fault_id), fault_message), ] ) # Otherwise, generate a new fault event