pub struct AgentBuilder { /* private fields */ }Expand description
Builder for Agent.
Implementations§
Source§impl AgentBuilder
impl AgentBuilder
Sourcepub fn bind(self, addr: impl Into<String>) -> Self
pub fn bind(self, addr: impl Into<String>) -> Self
Set the bind address.
Default is “0.0.0.0:161”.
Sourcepub fn community(self, community: &[u8]) -> Self
pub fn community(self, community: &[u8]) -> Self
Add an accepted community string for v1/v2c requests.
Multiple communities can be added. If none are added, all community strings are rejected.
Sourcepub fn communities<I, C>(self, communities: I) -> Self
pub fn communities<I, C>(self, communities: I) -> Self
Add multiple community strings.
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.
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 v3.
If not set, a default engine ID will be generated.
Sourcepub fn max_message_size(self, size: usize) -> Self
pub fn max_message_size(self, size: usize) -> Self
Set the maximum message size for responses.
Default is 1472 octets (fits Ethernet MTU minus IP/UDP headers). GETBULK responses will be truncated to fit within this limit.
For SNMPv3 requests, the agent uses the minimum of this value and the msgMaxSize from the request.
Sourcepub fn handler(self, prefix: Oid, handler: Arc<dyn MibHandler>) -> Self
pub fn handler(self, prefix: Oid, handler: Arc<dyn MibHandler>) -> Self
Register a MIB handler for an OID subtree.
Handlers are matched by longest prefix. When a request comes in, the handler with the longest matching prefix is used.
Sourcepub fn vacm<F>(self, configure: F) -> Self
pub fn vacm<F>(self, configure: F) -> Self
Configure VACM (View-based Access Control Model) using a builder function.
When VACM is enabled, all requests are checked against the configured
access control rules. Requests that don’t have proper access are rejected
with noAccess error (v2c/v3) or noSuchName (v1).
§Example
use async_snmp::agent::{Agent, SecurityModel, VacmBuilder};
use async_snmp::message::SecurityLevel;
use async_snmp::oid;
let agent = Agent::builder()
.bind("0.0.0.0:161")
.community(b"public")
.community(b"private")
.vacm(|v| v
.group("public", SecurityModel::V2c, "readonly_group")
.group("private", SecurityModel::V2c, "readwrite_group")
.access("readonly_group", |a| a
.read_view("full_view"))
.access("readwrite_group", |a| a
.read_view("full_view")
.write_view("write_view"))
.view("full_view", |v| v
.include(oid!(1, 3, 6, 1)))
.view("write_view", |v| v
.include(oid!(1, 3, 6, 1, 2, 1, 1))))
.build()
.await?;