Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(anta): Added the test case to verify syslog logging is enabled #859

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions anta/tests/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,37 @@ def _get_logging_states(logger: logging.Logger, command_output: str) -> str:
return log_states


class VerifySyslogLogging(AntaTest):
"""Verifies if syslog logging is enabled.

Expected Results
----------------
* Success: The test will pass if syslog logging is enabled.
* Failure: The test will fail if syslog logging is disabled.

Examples
--------
```yaml
anta.tests.logging:
- VerifySyslogLogging:
```
"""

name = "VerifySyslogLogging"
description = "Verifies if syslog logging is enabled."
categories: ClassVar[list[str]] = ["logging"]
commands: ClassVar[list[AntaCommand | AntaTemplate]] = [AntaCommand(command="show logging", ofmt="text")]

@AntaTest.anta_test
def test(self) -> None:
"""Main test function for VerifySyslogLogging."""
self.result.is_success()
log_output = self.instance_commands[0].text_output

if "Syslog logging: enabled" not in _get_logging_states(self.logger, log_output):
self.result.is_failure("Syslog logging is disabled.")


class VerifyLoggingPersistent(AntaTest):
"""Verifies if logging persistent is enabled and logs are saved in flash.

Expand Down
1 change: 1 addition & 0 deletions examples/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ anta.tests.lanz:
- VerifyLANZ:

anta.tests.logging:
- VerifySyslogLogging:
- VerifyLoggingPersistent:
- VerifyLoggingSourceIntf:
interface: Management1
Expand Down
42 changes: 42 additions & 0 deletions tests/units/anta_tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
VerifyLoggingPersistent,
VerifyLoggingSourceIntf,
VerifyLoggingTimestamp,
VerifySyslogLogging,
)
from tests.units.anta_tests import test

Expand Down Expand Up @@ -277,4 +278,45 @@
"inputs": None,
"expected": {"result": "failure", "messages": ["Device has reported syslog messages with a severity of ERRORS or higher"]},
},
{
"name": "success",
"test": VerifySyslogLogging,
"eos_data": [
"""Syslog logging: enabled
Buffer logging: level debugging

External configuration:
active:
inactive:

Facility Severity Effective Severity
-------------------- ------------- ------------------
aaa debugging debugging
accounting debugging debugging""",
],
"inputs": None,
"expected": {"result": "success"},
},
{
"name": "failure",
"test": VerifySyslogLogging,
"eos_data": [
"""Syslog logging: disabled
Buffer logging: level debugging
Console logging: level errors
Persistent logging: disabled
Monitor logging: level errors

External configuration:
active:
inactive:

Facility Severity Effective Severity
-------------------- ------------- ------------------
aaa debugging debugging
accounting debugging debugging""",
],
"inputs": None,
"expected": {"result": "failure", "messages": ["Syslog logging is disabled."]},
},
]
Loading