pub struct NotificationReceiver { /* private fields */ }Expand description
SNMP Notification Receiver.
Listens for incoming SNMP notifications (traps and informs) on a UDP socket. For InformRequest notifications, automatically sends a Response-PDU.
§V3 Authentication
To receive authenticated V3 notifications, use the builder pattern to configure USM credentials:
use async_snmp::notification::NotificationReceiver;
use async_snmp::{AuthProtocol, PrivProtocol};
let receiver = NotificationReceiver::builder()
.bind("0.0.0.0:162")
.usm_user("trapuser", |u| {
u.auth(AuthProtocol::Sha1, b"authpassword")
})
.build()
.await?;Implementations§
Source§impl NotificationReceiver
impl NotificationReceiver
Sourcepub fn builder() -> NotificationReceiverBuilder
pub fn builder() -> NotificationReceiverBuilder
Create a builder for configuring the notification receiver.
Use this to configure USM credentials for V3 authentication.
Sourcepub async fn bind(addr: impl AsRef<str>) -> Result<Self>
pub async fn bind(addr: impl AsRef<str>) -> Result<Self>
Bind to a local address.
The standard SNMP notification port is 162.
For V3 authentication support, use NotificationReceiver::builder() instead.
§Example
use async_snmp::notification::NotificationReceiver;
// Bind to the standard trap port (requires root/admin on most systems)
let receiver = NotificationReceiver::bind("0.0.0.0:162").await?;
// Or use an unprivileged port for testing
let receiver = NotificationReceiver::bind("0.0.0.0:1162").await?;Sourcepub fn local_addr(&self) -> SocketAddr
pub fn local_addr(&self) -> SocketAddr
Get the local address this receiver is bound to.
Sourcepub async fn recv(&self) -> Result<(Notification, SocketAddr)>
pub async fn recv(&self) -> Result<(Notification, SocketAddr)>
Receive a notification.
This method blocks until a notification is received. For InformRequest notifications, a Response-PDU is automatically sent back to the sender.
Returns the notification and the source address.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for NotificationReceiver
impl RefUnwindSafe for NotificationReceiver
impl Send for NotificationReceiver
impl Sync for NotificationReceiver
impl Unpin for NotificationReceiver
impl UnsafeUnpin for NotificationReceiver
impl UnwindSafe for NotificationReceiver
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more