Categorygithub.com/eriksejr/GoSNMPServer
modulepackage
0.0.7
Repository: https://github.com/eriksejr/gosnmpserver.git
Documentation: pkg.go.dev

# README

GoSNMPServer

Build Status GoDoc codecov

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.

TL;DR

Build your own SNMP Server, try this:

go install github.com/eriksejr/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

Quick Start

import "github.com/gosnmp/gosnmp"
import "github.com/eriksejr/GoSNMPServer"
import "github.com/eriksejr/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()

Serve your own oids

This library provides some common oid for use. See mibImps for code, See GoDoc 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

  • Integer
  • OctetString
  • ObjectIdentifier
  • IPAddress
  • Counter32
  • Gauge32
  • TimeTicks
  • Counter64
  • Uinteger32
  • OpaqueFloat
  • OpaqueDouble

Could use wrap function for detect type error. See GoSNMPServer.Asn1IntegerWrap / GoSNMPServer.Asn1IntegerUnwrap and so on.

Thanks

This library is based on soniah/gosnmp for encoder / decoders. (made a fork for maintenance)

# Packages

No description provided by the author
No description provided by the author

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
IsValidObjectIdentifier will check an oid string is valid oid Deprecated: instead use VerifyOid.
NewDefaultLogger makes a new DefaultLogger.
NewDiscardLogger makes a discard logger.
No description provided by the author
No description provided by the author
VerifyOid will check an oid string is valid oid, each number should be positive uint32.
WrapLogrus wraps a new DefaultLogger.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
PermissionAllowanceAllowed allowed for access.
PermissionAllowanceDenied denies for access.

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

DefaultLogger is a logger warps logrus.
DiscardLogger throws away everything.
MasterAgent identifys software which runs on managed devices One server (port) could ONLY have one MasterAgent.
PDUValueControlItem describe the action of get / set / walk in pdu tree.
No description provided by the author
No description provided by the author
SnmpLoggerAdapter adapts a logger to gosnmp.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

ILogger is a logger.
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
FuncPDUControlCheckPermission checks for permission.
FuncPDUControlGet will be called on get value.
FuncPDUControlSet will be called on set value.
FuncPDUControlTrap will be called on trap.
PermissionAllowance ENUM controls for Allowance.