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. Any USM user also requires a persisted AuthoritativeEngine. 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)
- No authoritative engine (required when adding a USM user)
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.
Adding any user requires a persisted AuthoritativeEngine before
build, because this receiver is authoritative for V3
Inform exchanges.
§Example
use async_snmp::notification::NotificationReceiver;
use async_snmp::{AuthProtocol, AuthoritativeEngine, PrivProtocol};
use std::convert::Infallible;
let engine = AuthoritativeEngine::install(b"receiver-engine".to_vec(), |_| {
Ok::<(), Infallible>(())
})?;
let receiver = NotificationReceiver::builder()
.bind("0.0.0.0:162")
.authoritative_engine(engine)
.usm_user("trapuser", |u| {
u.auth_priv(
AuthProtocol::Sha1,
b"authpassword",
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?;Set the persisted local authoritative engine state for SNMPv3.
A receiver with USM users can be authoritative for Informs and requires
this value. Construct it with AuthoritativeEngine::install on first
installation or AuthoritativeEngine::restart on later starts. The
retained callback persists runtime rollover increments before use.
Sourcepub async fn build(self) -> Result<NotificationReceiver>
pub async fn build(self) -> Result<NotificationReceiver>
Build the notification receiver.
Returns a configuration error when a USM user is configured without a
persisted AuthoritativeEngine.
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