snmpgo
snmpgo is a golang implementation for SNMP.
Supported Message Types
Sending
- SNMP V1
- GetRequest
- GetNextRequest
- SNMP V2c, V3
- GetRequest
- GetNextRequest
- GetBulkRequest
- V2Trap
- InformRequest
Receiving
- SNMP V2c
- V2Trap
- InformRequest
- SNMP V3
- V2Trap
Examples
Example for sending a GetRequest. Explain how to use basic of the API.
package main
import (
"fmt"
"github.com/k-sone/snmpgo"
)
func main() {
snmp, err := snmpgo.NewSNMP(snmpgo.SNMPArguments{
Version: snmpgo.V2c,
Address: "127.0.0.1:161",
Retries: 1,
Community: "public",
})
if err != nil {
// Failed to create snmpgo.SNMP object
fmt.Println(err)
return
}
oids, err := snmpgo.NewOids([]string{
"1.3.6.1.2.1.1.1.0",
"1.3.6.1.2.1.1.2.0",
"1.3.6.1.2.1.1.3.0",
})
if err != nil {
// Failed to parse Oids
fmt.Println(err)
return
}
if err = snmp.Open(); err != nil {
// Failed to open connection
fmt.Println(err)
return
}
defer snmp.Close()
pdu, err := snmp.GetRequest(oids)
if err != nil {
// Failed to request
fmt.Println(err)
return
}
if pdu.ErrorStatus() != snmpgo.NoError {
// Received an error from the agent
fmt.Println(pdu.ErrorStatus(), pdu.ErrorIndex())
}
// get VarBind list
fmt.Println(pdu.VarBinds())
// select a VarBind
fmt.Println(pdu.VarBinds().MatchOid(oids[0]))
}
Example for sending a V2Trap. Explain how to build varbinds using API.
Example for sending a GetRequest to multiple agents.
This command displays the traffic of agent at regular intervals. Explain how to process the obtained information.
snmpget@Net-SNMP like command.
snmpbulkwalk@Net-SNMP like command.
snmptrap@Net-SNMP like command.
Dependencies
License
MIT