diff --git a/anta/custom_types.py b/anta/custom_types.py index c1e1f6428..4e8972d70 100644 --- a/anta/custom_types.py +++ b/anta/custom_types.py @@ -204,3 +204,4 @@ def validate_regex(value: str) -> str: ] BgpUpdateError = Literal["inUpdErrWithdraw", "inUpdErrIgnore", "inUpdErrDisableAfiSafi", "disabledAfiSafi", "lastUpdErrTime"] BfdProtocol = Literal["bgp", "isis", "lag", "ospf", "ospfv3", "pim", "route-input", "static-bfd", "static-route", "vrrp", "vxlan"] +SnmpVersion = Literal["v1", "v2c", "v3"] diff --git a/anta/tests/snmp.py b/anta/tests/snmp.py index 9d8b2dfa6..66b849ce9 100644 --- a/anta/tests/snmp.py +++ b/anta/tests/snmp.py @@ -12,7 +12,7 @@ from pydantic import BaseModel, model_validator -from anta.custom_types import Port, PositiveInteger +from anta.custom_types import Port, PositiveInteger, SnmpVersion from anta.models import AntaCommand, AntaTest from anta.tools import get_failed_logs, get_item, get_value @@ -282,7 +282,7 @@ class Input(AntaTest.Input): """List of SNMP hosts.""" class SNMPHost(BaseModel): - """Model for a SNMP Manager.""" + """Model for a SNMP Host.""" hostname: IPv4Address """IPv4 address of the SNMP notification host.""" @@ -290,7 +290,7 @@ class SNMPHost(BaseModel): """Optional VRF for SNMP Hosts. If not provided, it defaults to `default`.""" notification_type: Literal["trap", "inform"] """Type of SNMP notification (trap or inform).""" - version: Literal["v1", "v2c", "v3"] + version: SnmpVersion """SNMP protocol version.""" udp_port: Port | int = 162 """UDP port for SNMP. If not provided then defaults to 162.""" @@ -323,7 +323,7 @@ def test(self) -> None: # Verify SNMP host details. if not (snmp_hosts := get_value(self.instance_commands[0].json_output, "hosts")): - self.result.is_failure("SNMP is not configured.") + self.result.is_failure("No SNMP host is configured.") return for host in self.inputs.notification_hosts: diff --git a/tests/units/anta_tests/test_snmp.py b/tests/units/anta_tests/test_snmp.py index 3177aceb1..c2b5a1234 100644 --- a/tests/units/anta_tests/test_snmp.py +++ b/tests/units/anta_tests/test_snmp.py @@ -195,7 +195,7 @@ {"hostname": "192.168.1.101", "vrf": "default", "notification_type": "trap", "version": "v2c", "udp_port": 162, "community_string": "public"}, ] }, - "expected": {"result": "failure", "messages": ["SNMP is not configured."]}, + "expected": {"result": "failure", "messages": ["No SNMP host is configured."]}, }, { "name": "failure-details-not-found",