Skip to content

Commit

Permalink
Rely on pre-parsed IP address in BGP traps
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lunkwill42 committed Aug 27, 2024
1 parent 1c4a633 commit 94bba1d
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/zino/trapobservers/bgp_traps.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"""

import logging
from ipaddress import ip_address
from typing import Optional, Tuple

from zino.statemodels import BGPOperState, BGPPeerSession, IPAddress
Expand Down Expand Up @@ -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")

Expand Down

0 comments on commit 94bba1d

Please sign in to comment.