Need help with gosnmp?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

alouca
203 Stars 76 Forks Other 102 Commits 11 Opened issues

Description

A simple SNMP library written in GoLang

Services available

!
?

Need anything else?

Contributors list

# 339,893
Go
44 commits
# 3,312
Bootstr...
codeign...
css3-an...
Gulp
4 commits
# 66,864
Shell
Scala
Haskell
unix-co...
3 commits
# 23,268
Perl
hugo
mojolic...
stripe
3 commits
# 156,396
golang
Shell
C
quantum...
2 commits
# 157,897
Go
Shell
HTML
web-app...
2 commits
# 243,355
Go
HTML
prometh...
icmp
2 commits
# 297,723
Go
Shell
jwe
oath
2 commits
# 338,454
C
Shell
Objecti...
1 commit
# 138,155
Shell
pypi
health-...
ipv4
1 commit
# 112,323
Erlang
rabbitm...
sasl
dns-ove...
1 commit
# 145,269
Ruby
Rails
javascr...
Clojure
1 commit
# 73,563
mariadb
MySQL
SQL
ripgrep
1 commit
# 566,844
Go
1 commit
# 327,987
Elixir
C
Shell
PHP
1 commit
# 53,510
Ruby
ftp-cli...
gitlab-...
Rails
1 commit
# 216,707
Shell
headles...
slimerj...
phantom...
1 commit

gosnmp

GoSNMP is a simple SNMP client library, written fully in Go. Currently it supports only GetRequest (with the rest GetNextRequest, SetRequest in the pipe line). Support for traps is also in the plans.

Install

The easiest way to install is via go get:

go get github.com/alouca/gosnmp

License

Some parts of the code are borrowed by the Golang project (specifically some functions for unmarshaling BER responses), which are under the same terms and conditions as the Go language, which are marked appropriately in the source code. The rest of the code is under the BSD license.

See the LICENSE file for more details.

Usage

The library usage is pretty simple:

// Connect to 192.168.0.1 with timeout of 5 seconds

import ( "github.com/alouca/gosnmp" "log" )

s, err := gosnmp.NewGoSNMP("61.147.69.87", "public", gosnmp.Version2c, 5) if err != nil { log.Fatal(err) } resp, err := s.Get(".1.3.6.1.2.1.1.1.0") if err == nil { for _, v := range resp.Variables { switch v.Type { case gosnmp.OctetString: log.Printf("Response: %s : %s : %s \n", v.Name, v.Value.(string), v.Type.String()) } } }

The response value is always given as an interface{} depending on the PDU response from the SNMP server. For an example checkout examples/example.go.

Responses are a struct of the following format:

type Variable struct {
  Name  asn1.ObjectIdentifier
  Type  Asn1BER
  Value interface{}
}

Where Name is the OID encoded as an object identifier, Type is the encoding type of the response and Value is an interface{} type, with the response appropriately decoded.

SNMP BER Types can be one of the following:

type Asn1BER byte

const ( Integer Asn1BER = 0x02 BitString = 0x03 OctetString = 0x04 Null = 0x05 ObjectIdentifier = 0x06 Counter32 = 0x41 Gauge32 = 0x42 TimeTicks = 0x43 Opaque = 0x44 NsapAddress = 0x45 Counter64 = 0x46 Uinteger32 = 0x47 )

GoSNMP supports most of the above values, subsequent releases will support all of them.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.