Removing unnecessary protocol conformance.
SwiftSnmpKit
A Swift Package for making SNMP (Simple Network Management Protocol) requests to network devices.
SwiftSnmpKit supports the following SNMP versions:
Only SNMP queries to UDP port 161 are supported. SNMP traps or informs to UDP port 162 are not supported. TCP transport is not supported.
The following SNMP query types are supported:
The following SNMP reply types are supported:
SNMP EngineIDs, Engine Boots, and Engine Times will be reported by the SnmpSender singleton and used for future queries.
import SwiftSnmpKit
guard let snmpSender = SnmpSender.shared else...
await snmpSender.send()
You can use Swift Package Manager and specify dependency in Package.swift by adding this:
Package.swift
.package(url: "https://github.com/darrellroot/SwiftSnmpKit.git", .upToNextMajor(from: "0.1.6"))
guard let snmpSender = SnmpSender.shared else { fatalError("Snmp Sender not inialized") }
let result = await snmpSender.send(host: agent, command: .getRequest, community: community, oid: "1.3.6.1.2.1.1.1.0")
let getNextResult = await snmpSender.send(host: agent, userName: "ciscoprivuser", pduType: .getNextRequest, oid: "1.3.6.1.2", authenticationType: .sha1, authPassword: "authpassword", privPassword: "privpassword")
authPassword and privPassword parameters are optional.
SNMPv2c requests will be attempted only once. Your code needs to retransmit in the event of packet loss.
SNMPv3 requests will be attempted up to three times. This allows SNMP reports to populate the EngineID, EngineBoots, and EngineTime fields.
switch getNextResult { case .failure(let error): consecutiveNextFailures += 1 print("SNMP Error: \(error.localizedDescription)") case .success(let variableBinding): print(variableBinding) if variableBinding.value == AsnValue.endOfMibView { done = true } if variableBinding.value == AsnValue.noSuchObject { consecutiveNextFailures += 1 } else { consecutiveNextFailures = 0 } nextOid = variableBinding.oid }
A sample project with command-line SNMP tools is at https://github.com/darrellroot/SwiftSnmpTools
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
SwiftSnmpKit
A Swift Package for making SNMP (Simple Network Management Protocol) requests to network devices.
Features
SwiftSnmpKit supports the following SNMP versions:
Only SNMP queries to UDP port 161 are supported. SNMP traps or informs to UDP port 162 are not supported. TCP transport is not supported.
The following SNMP query types are supported:
The following SNMP reply types are supported:
SNMP EngineIDs, Engine Boots, and Engine Times will be reported by the SnmpSender singleton and used for future queries.
Overview
import SwiftSnmpKit
at the top of your source fileguard let snmpSender = SnmpSender.shared else...
await snmpSender.send()
Swift Package Manager
You can use Swift Package Manager and specify dependency in
Package.swift
by adding this:Initialize the SNMP Sender singleton
Send a SNMP request and wait for reply (SNMPv2c example)
Send a SNMP request and wait for reply (SNMPv3 example)
authPassword and privPassword parameters are optional.
SNMPv2c requests will be attempted only once. Your code needs to retransmit in the event of packet loss.
SNMPv3 requests will be attempted up to three times. This allows SNMP reports to populate the EngineID, EngineBoots, and EngineTime fields.
Switch on result
Sample Project
A sample project with command-line SNMP tools is at https://github.com/darrellroot/SwiftSnmpTools