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.
For IPv6 bind addresses, the socket has IPV6_V6ONLY set to true.
§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.