From ea0f5e9954ef0efc7eb16798ee6b3d295765dd90 Mon Sep 17 00:00:00 2001 From: paul Date: Mon, 30 Sep 2024 11:39:59 +0100 Subject: [PATCH 1/4] allow for positive or negative offset time zones --- anta/tests/logging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anta/tests/logging.py b/anta/tests/logging.py index b32bc99fd..a988f9fc5 100644 --- a/anta/tests/logging.py +++ b/anta/tests/logging.py @@ -282,7 +282,7 @@ class VerifyLoggingTimestamp(AntaTest): def test(self) -> None: """Main test function for VerifyLoggingTimestamp.""" log_pattern = r"ANTA VerifyLoggingTimestamp validation" - timestamp_pattern = r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6}-\d{2}:\d{2}" + timestamp_pattern = r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6}[\+-]\d{2}:\d{2}" output = self.instance_commands[1].text_output lines = output.strip().split("\n")[::-1] last_line_with_pattern = "" From e1e06613a195a70dcc613abdadf3da93b328ada7 Mon Sep 17 00:00:00 2001 From: paul Date: Wed, 2 Oct 2024 14:34:02 +0100 Subject: [PATCH 2/4] add unit test for positive offset --- tests/units/anta_tests/test_logging.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/units/anta_tests/test_logging.py b/tests/units/anta_tests/test_logging.py index cfc034c87..b4294367e 100644 --- a/tests/units/anta_tests/test_logging.py +++ b/tests/units/anta_tests/test_logging.py @@ -201,7 +201,7 @@ "expected": {"result": "failure", "messages": ["Logs are not generated with the device FQDN"]}, }, { - "name": "success", + "name": "success-negative-offset", "test": VerifyLoggingTimestamp, "eos_data": [ "", @@ -213,6 +213,19 @@ "inputs": None, "expected": {"result": "success"}, }, + { + "name": "success-positive-offset", + "test": VerifyLoggingTimestamp, + "eos_data": [ + "", + "2023-05-10T15:41:44.680813+05:00 NW-CORE.example.org ConfigAgent: %SYS-6-LOGMSG_INFO: " + "Message from arista on command-api (10.22.1.107): ANTA VerifyLoggingTimestamp validation\n" + "2023-05-10T15:42:44.680813+05:00 NW-CORE.example.org ConfigAgent: %SYS-6-LOGMSG_INFO: " + "Other log\n", + ], + "inputs": None, + "expected": {"result": "success"}, + }, { "name": "failure", "test": VerifyLoggingTimestamp, From 652464d30a078adbbb704a61fc1745c91d1704d4 Mon Sep 17 00:00:00 2001 From: Guillaume Mulocher Date: Thu, 3 Oct 2024 16:34:43 +0200 Subject: [PATCH 3/4] Update logging.py --- anta/tests/logging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anta/tests/logging.py b/anta/tests/logging.py index a988f9fc5..395d92940 100644 --- a/anta/tests/logging.py +++ b/anta/tests/logging.py @@ -271,7 +271,7 @@ class VerifyLoggingTimestamp(AntaTest): """ name = "VerifyLoggingTimestamp" - description = "Verifies if logs are generated with the riate timestamp." + description = "Verifies if logs are generated with the appropriate timestamp." categories: ClassVar[list[str]] = ["logging"] commands: ClassVar[list[AntaCommand | AntaTemplate]] = [ AntaCommand(command="send log level informational message ANTA VerifyLoggingTimestamp validation", ofmt="text"), From b654ce1d7abcb95c11194bd968b3f326a793fd6e Mon Sep 17 00:00:00 2001 From: paul Date: Thu, 3 Oct 2024 16:15:20 +0100 Subject: [PATCH 4/4] update regex --- anta/tests/logging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anta/tests/logging.py b/anta/tests/logging.py index 395d92940..2972b4ec8 100644 --- a/anta/tests/logging.py +++ b/anta/tests/logging.py @@ -282,7 +282,7 @@ class VerifyLoggingTimestamp(AntaTest): def test(self) -> None: """Main test function for VerifyLoggingTimestamp.""" log_pattern = r"ANTA VerifyLoggingTimestamp validation" - timestamp_pattern = r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6}[\+-]\d{2}:\d{2}" + timestamp_pattern = r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6}[+-]\d{2}:\d{2}" output = self.instance_commands[1].text_output lines = output.strip().split("\n")[::-1] last_line_with_pattern = ""