GoSNMPServer is an SNMP server library fully written in Go. It provides Server Get, GetNext, GetBulk, Walk, BulkWalk, Set and Traps. It supports IPv4 and IPv6, using SNMPv2c or SNMPv3. Builds are tested against linux/amd64 and linux/386.
Build your own SNMP Server, try this:
go install github.com/slayercat/GoSNMPServer/cmd/gosnmpserver
$(go env GOPATH)/bin/gosnmpserver run-server
snmpwalk -v 3 -l authPriv -n public -u testuser -a md5 -A testauth -x des -X testpriv 127.0.0.1:1161 1
import "github.com/slayercat/gosnmp"
import "github.com/slayercat/GoSNMPServer"
import "github.com/slayercat/GoSNMPServer/mibImps"
master := GoSNMPServer.MasterAgent{
Logger: GoSNMPServer.NewDefaultLogger(),
SecurityConfig: GoSNMPServer.SecurityConfig{
AuthoritativeEngineBoots: 1,
Users: []gosnmp.UsmSecurityParameters{
{
UserName: c.String("v3Username"),
AuthenticationProtocol: gosnmp.MD5,
PrivacyProtocol: gosnmp.DES,
AuthenticationPassphrase: c.String("v3AuthenticationPassphrase"),
PrivacyPassphrase: c.String("v3PrivacyPassphrase"),
},
},
},
SubAgents: []*GoSNMPServer.SubAgent{
{
CommunityIDs: []string{c.String("community")},
OIDs: mibImps.All(),
},
},
}
server := GoSNMPServer.NewSNMPServer(master)
err := server.ListenUDP("udp", "127.0.0.1:1161")
if err != nil {
logger.Errorf("Error in listen: %+v", err)
}
server.ServeForever()
This library provides some common oid for use. See mibImps for code, See here.
Append GoSNMPServer.PDUValueControlItem
to your SubAgent OIDS:
{
OID: fmt.Sprintf("1.3.6.1.2.1.2.2.1.1.%d", ifIndex),
Type: gosnmp.Integer,
OnGet: func() (value interface{}, err error) { return GoSNMPServer.Asn1IntegerWrap(ifIndex), nil },
Document: "ifIndex",
},
Supports Types: See RFC-2578 FOR SMI
Could use wrap function for detect type error. See GoSNMPServer.Asn1IntegerWrap
/ GoSNMPServer.Asn1IntegerUnwrap
and so on.
This library is based on soniah/gosnmp for encoder / decoders. (made a fork for maintenance)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。