diff --git a/anta/tests/logging.py b/anta/tests/logging.py index 3a84fc45b..a1d59d116 100644 --- a/anta/tests/logging.py +++ b/anta/tests/logging.py @@ -279,7 +279,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"), @@ -290,7 +290,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 = "" 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,