“guard let snmpSender = SnmpSender.shared” does not work. The “fatalError” is always thrown. According to the documentation of the “SwiftSnmpKit” framework, this is a singleton. Here is the code:
import Foundation
import SwiftSnmpKit
public class SnmpMachine {
private init() {
}
static func run(agent: String, userName: String, pduType: SnmpPduType, oid: String, password: String, privatePassword: String) async {
guard let snmpSender = SnmpSender.shared else {
fatalError("Snmp Sender not inialized")
}
let result = await snmpSender.send(host: agent, userName: userName, pduType: pduType, oid: oid, authenticationType: .sha1, authPassword: password, privPassword: privatePassword)
switch result {
case .failure(let error):
print("SNMP Error: (error.localizedDescription)")
case .success(let variableBinding):
print(variableBinding)
}
}
}
The code I use here comes directly from the documentation of the framework. Unfortunately, I don’t have any direct ideas as to why it doesn’t work (I’m a beginner). But does the ‘shared’ property perhaps not exist?
Thank you in advance for your help!
3