From 94bba1d7c96eaff625a26070cc03b9b18007f194 Mon Sep 17 00:00:00 2001 From: Morten Brekkevold Date: Tue, 27 Aug 2024 09:56:41 +0000 Subject: [PATCH] Rely on pre-parsed IP address in BGP traps The SNMP layer should now have properly parsed an IP address object from the `jnxBgpM2PeerRemoteAddr` value, so the BGP trap handler no longer needs to parse the raw value itself. --- src/zino/trapobservers/bgp_traps.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/zino/trapobservers/bgp_traps.py b/src/zino/trapobservers/bgp_traps.py index 449d1d676..767bf455e 100644 --- a/src/zino/trapobservers/bgp_traps.py +++ b/src/zino/trapobservers/bgp_traps.py @@ -17,7 +17,6 @@ """ import logging -from ipaddress import ip_address from typing import Optional, Tuple from zino.statemodels import BGPOperState, BGPPeerSession, IPAddress @@ -73,10 +72,7 @@ def _pre_parse_trap(self, trap: TrapMessage) -> Tuple[IPAddress, BGPOperState]: raise MissingRequiredTrapVariables() try: - remote_addr = bytes(trap.get_all("jnxBgpM2PeerRemoteAddr")[0].raw_value) - peer = ip_address(remote_addr) - except ValueError: - raise ValueError(f"BGP transition trap received with invalid peer address: {remote_addr!r}") + peer = trap.get_all("jnxBgpM2PeerRemoteAddr")[0].value except IndexError: raise ValueError("BGP transition trap received without peer address")