pub struct NotificationReceiverBuilder { /* private fields */ }Expand description
Builder for NotificationReceiver.
Configures the bind address, optional community filtering for v1/v2c, and USM credentials for v3. Community filtering and USM users are independent and may be combined; a single receiver then handles all versions on one port. See the module docs.
Implementations§
Source§impl NotificationReceiverBuilder
impl NotificationReceiverBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new builder with default settings.
Defaults:
- Bind address:
0.0.0.0:162(UDP, standard SNMP trap port) - No USM users (v3 notifications rejected until users are added)
Sourcepub fn bind(self, addr: impl Into<String>) -> Self
pub fn bind(self, addr: impl Into<String>) -> Self
Set the UDP bind address.
Default is 0.0.0.0:162 (UDP, standard SNMP trap port).
Sourcepub fn usm_user<F>(self, username: impl Into<Bytes>, configure: F) -> Self
pub fn usm_user<F>(self, username: impl Into<Bytes>, configure: F) -> Self
Add a USM user for V3 authentication.
§Example
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")
.privacy(PrivProtocol::Aes128, b"privpassword")
})
.build()
.await?;Sourcepub fn community(self, community: &[u8]) -> Self
pub fn community(self, community: &[u8]) -> Self
Restrict accepted v1/v2c notifications to the given community string.
Community filtering is opt-in. With no community configured the
receiver accepts v1/v2c notifications under any community and surfaces
the community on the returned Notification for caller-side policy.
Once one or more communities are configured, a v1/v2c notification
whose community matches none of them is dropped and never returned
from NotificationReceiver::recv; a dropped inform is not
acknowledged. Comparison is constant-time. This does not affect v3,
which is gated by USM.
Call multiple times to accept several communities.
§Example
use async_snmp::notification::NotificationReceiver;
let receiver = NotificationReceiver::builder()
.bind("0.0.0.0:162")
.community(b"public")
.build()
.await?;Sourcepub fn communities<I, C>(self, communities: I) -> Self
pub fn communities<I, C>(self, communities: I) -> Self
Restrict accepted v1/v2c notifications to any of the given communities.
Convenience for calling Self::community once per entry. See that
method for the filtering semantics.
§Example
use async_snmp::notification::NotificationReceiver;
let receiver = NotificationReceiver::builder()
.bind("0.0.0.0:162")
.communities(["public", "monitor"])
.build()
.await?;Sourcepub fn engine_id(self, engine_id: impl Into<Vec<u8>>) -> Self
pub fn engine_id(self, engine_id: impl Into<Vec<u8>>) -> Self
Set the engine ID for SNMPv3.
If not set, a default engine ID will be generated based on the RFC 3411 format using enterprise number and timestamp.
Sourcepub fn engine_boots(self, boots: u32) -> Self
pub fn engine_boots(self, boots: u32) -> Self
Set the initial engine boots value.
This should be persisted across restarts and incremented each time the receiver starts. Default is 1.
Sourcepub async fn build(self) -> Result<NotificationReceiver>
pub async fn build(self) -> Result<NotificationReceiver>
Build the notification receiver.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for NotificationReceiverBuilder
impl RefUnwindSafe for NotificationReceiverBuilder
impl Send for NotificationReceiverBuilder
impl Sync for NotificationReceiverBuilder
impl Unpin for NotificationReceiverBuilder
impl UnsafeUnpin for NotificationReceiverBuilder
impl UnwindSafe for NotificationReceiverBuilder
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> 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