util

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2022 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SNMP_PORT       = uint16(161)
	MAX_CONNECT_TRY = 10
)
View Source
const (
	CONV_HWADDR    = "hwaddr"
	CONV_POWERSET  = "powerset_status"
	CONV_HEXTOINT  = "hextoint"
	CONV_HEXTOIP   = "hextoip"
	CONV_ENGINE_ID = "engine_id"
	CONV_REGEXP    = "regexp"
	CONV_ONE       = "to_one"
)

Variables

View Source
var (
	SNMP_POLL_SLEEP_TIME = 10 * time.Second

	// Device Manufacturer aka sysDescr
	SNMP_DEVICE_MANUFACTURER_OID = "1.3.6.1.2.1.1.1"
)
View Source
var (
	TRUNCATE     = true
	NO_TRUNCATE  = false
	MAX_SNMP_LEN = 128
)

Functions

func ContainsAny

func ContainsAny(s string, substrs ...string) bool

func DoWalk

func DoWalk(device string, baseOid string, format string, conf *kt.SnmpConfig, connectTimeout time.Duration, retries int, log logger.ContextL) error

Does a walk of the targeted device and exits.

func GetDeviceManufacturer

func GetDeviceManufacturer(server snmpWalker, log logger.ContextL) string

func GetFromConv

func GetFromConv(pdu gosnmp.SnmpPDU, conv string, log logger.ContextL) (int64, string)

Handle the case of wierd ints encoded as byte arrays.

func GetIndex

func GetIndex(value, prefix string) string

getIndex returns the rest of value after prefix, e.g. for 1.2.3.4.5.6 and 2.3.4, returns .5.6 Modeled on getIndex in topology-demo/devicemetrics/main.go. Prefix must occur in value, otherwise results are undefined (aka "wrong").

func InitSNMP

func InitSNMP(device *kt.SnmpDeviceConfig, connectTimeout time.Duration, retries int, posit string, log logger.ContextL) (*gosnmp.GoSNMP, error)

func LoadFile

func LoadFile(ctx context.Context, file string) ([]byte, error)

Utility to load a config file from various places

func PrettyPrint

func PrettyPrint(pdu gosnmp.SnmpPDU, format string, log logger.ContextL) string

func ReadOctetString

func ReadOctetString(variable gosnmp.SnmpPDU, truncate bool) (string, bool)

func ToInt64

func ToInt64(val interface{}) int64

toInt64 converts most of the numeric types in Go (and *all* the numeric types I expect to see from snmp) to int64.

func WalkOID

func WalkOID(ctx context.Context, device *kt.SnmpDeviceConfig, oid string, server *gosnmp.GoSNMP, log logger.ContextL, logName string) ([]gosnmp.SnmpPDU, error)

walk the OID subtree under a root, returning a slice of varbinds

func WriteFile

func WriteFile(ctx context.Context, file string, payload []byte, perms fs.FileMode) error

Utility to write a config file to various places

Types

This section is empty.

Jump to

Keyboard shortcuts

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