Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.
/ snmpclient2 Public archive
forked from k-sone/snmpgo

snmpgo is a golang implementation for sending SNMP messages

License

Notifications You must be signed in to change notification settings

mei-rune/snmpclient2

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

snmpgo

snmpgo is a golang implementation for sending SNMP messages.

Supported Message Types

  • SNMP V1
    • GetRequest
    • GetNextRequest
  • SNMP V2c, V3
    • GetRequest
    • GetNextRequest
    • GetBulkRequest
    • V2Trap
    • InformRequest

Examples

getv2.go, getv3.go

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.Arguments{
        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 VariableBinding list
    fmt.Println(pdu.VariableBindings())

    // select a VariableBinding
    fmt.Println(pdu.VariableBindings().MatchOid(oids[0]))
}

trapv2.go, trapv3.go

Example for sending a V2Trap. Explain how to build VariableBindings using API.

multiget.go

Example for sending a GetRequest to multiple agents.

ifstat.go

This command displays the traffic of agent at regular intervals. Explain how to process the obtained information.

snmpgoget.go

snmpget@Net-SNMP like command.

snmpgobulkwalk.go

snmpbulkwalk@Net-SNMP like command.

snmpgotrap.go

snmptrap@Net-SNMP like command.

License

MIT

About

snmpgo is a golang implementation for sending SNMP messages

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%