traps

package
v0.0.2-0...-4ce78c8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2021 License: Apache-2.0, Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NetSNMPExampleHeartbeatNotificationVariables = []gosnmp.SnmpPDU{

		{Name: "1.3.6.1.2.1.1.3.0", Type: gosnmp.TimeTicks, Value: uint32(1000)},

		{Name: "1.3.6.1.6.3.1.1.4.1.0", Type: gosnmp.OctetString, Value: "1.3.6.1.4.1.8072.2.3.0.1"},

		{Name: "1.3.6.1.4.1.8072.2.3.2.1", Type: gosnmp.Integer, Value: 1024},

		{Name: "1.3.6.1.4.1.8072.2.3.2.2", Type: gosnmp.OctetString, Value: "test"},
	}
)

List of variables for a NetSNMP::ExampleHeartBeatNotification trap message. See: http://www.circitor.fr/Mibs/Html/N/NET-SNMP-EXAMPLES-MIB.php#netSnmpExampleHeartbeatNotification

Functions

func FormatPacketToJSON

func FormatPacketToJSON(packet *SnmpPacket) (map[string]interface{}, error)

FormatPacketToJSON converts an SNMP trap packet to a JSON-serializable object.

func GetPort

func GetPort(t *testing.T) uint16

GetPort requests a random UDP port number and makes sure it is available

func GetStatus

func GetStatus() map[string]interface{}

GetStatus returns key-value data for use in status reporting of the traps server.

func GetTags

func GetTags(packet *SnmpPacket) []string

GetTags returns a list of tags associated to an SNMP trap packet.

func IsRunning

func IsRunning() bool

IsRunning returns whether the trap server is currently running.

func StartServer

func StartServer(cf *Config) error

StartServer starts the global trap server.

func StopServer

func StopServer()

StopServer stops the global trap server, if it is running.

Types

type Config

type Config struct {
	Enabled          bool          `yaml:"enabled"`          // snmp_traps_enabled
	Port             uint16        `yaml:"port"`             // snmp_traps_config.port
	CommunityStrings []string      `yaml:"communityStrings"` // snmp_traps_config.community_strings
	BindHost         string        `yaml:"bindHost"`         // snmp_traps_config.bind_host
	StopTimeout      time.Duration `yaml:"stopTimeout"`      // snmp_traps_config.stop_timeout
}

Config contains configuration for SNMP trap listeners. YAML field tags provided for test marshalling purposes.

func (*Config) Addr

func (c *Config) Addr() string

Addr returns the host:port address to listen on.

func (*Config) BuildV2Params

func (c *Config) BuildV2Params() *gosnmp.GoSNMP

BuildV2Params returns a valid GoSNMP SNMPv2 params structure from configuration.

func (*Config) Validate

func (c *Config) Validate(bindhost string) error

ReadConfig builds and returns configuration from Agent configuration.

type PacketsChannel

type PacketsChannel = chan *SnmpPacket

PacketsChannel is the type of channels of trap packets.

func GetPacketsChannel

func GetPacketsChannel() PacketsChannel

GetPacketsChannel returns a channel containing all received trap packets.

type SnmpPacket

type SnmpPacket struct {
	Content *gosnmp.SnmpPacket
	Addr    *net.UDPAddr
}

SnmpPacket is the type of packets yielded by server listeners.

type TrapServer

type TrapServer struct {
	Addr string
	// contains filtered or unexported fields
}

TrapServer manages an SNMPv2 trap listener.

func NewTrapServer

func NewTrapServer(cf *Config) (*TrapServer, error)

NewTrapServer configures and returns a running SNMP traps server.

func (*TrapServer) Stop

func (s *TrapServer) Stop()

Stop stops the TrapServer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL