snmp

package
v0.0.0-...-427f216 Latest Latest
Warning

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

Go to latest
Published: May 28, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// IfNumberOid [Get] 网络接口的数目
	IfNumberOid = ".1.3.6.1.2.1.2.1.0"
	// IfDescOid [Walk] 网络接口信息描述
	IfDescOid = ".1.3.6.1.2.1.2.2.1.2"
	// IfTypeOid [Walk] 网络接口类型
	IfTypeOid = ".1.3.6.1.2.1.2.2.1.3"
	// IfMTUOid [Walk] 接口发送和接收的最大 IP 数据报
	IfMTUOid = ".1.3.6.1.2.1.2.2.1.4"
	// IfSpeedOid [Walk] 接口当前宽带 bps
	IfSpeedOid = ".1.3.6.1.2.1.2.2.1.5"
	// IfPMacOid [Walk] 接口物理地址
	IfPMacOid = ".1.3.6.1.2.1.2.2.1.6"
	// IfMacOid [Walk] 接口的物理地址
	IfMacOid = "1.3.6.1.2.1.17.4.3.1.1"
	// IfMacPortOid [BulkWalk] 接口地址对应端口
	IfMacPortOid = ".1.3.6.1.2.1.17.4.3.1.2"
	// IfStatusOid [Walk] 接口当前操作状态
	IfStatusOid = ".1.3.6.1.2.1.2.2.1.8"
	// IfInOctetOid [Walk] 接口收到的字节数
	IfInOctetOid = ".1.3.6.1.2.1.2.2.1.10"
	// IfOutOctetOid [Walk] 接口发送的字节数
	IfOutOctetOid = ".1.3.6.1.2.1.2.2.1.16"
	// IfInUcastPktsOid [Walk] 接口收到的数据包个数
	IfInUcastPktsOid = ".1.3.6.1.2.1.2.2.1.11"
	// IfOutUcastPktsOid [Walk] 接口发送的数据包个数
	IfOutUcastPktsOid = ".1.3.6.1.2.1.2.2.1.17"

	// OccupiedPortOid [Walk] 交换机占用的端口
	OccupiedPortOid = ".1.3.6.1.4.1.3320.127.1.4.2.1.4"
	// IndexRemoteIPOid [GetNext] 交换机某端口的远程 IP
	IndexRemoteIPOid = "1.3.6.1.4.1.3320.127.1.4.2.1.2."
	// IndexRemoteIDOid [GetNext] 交换机某端口的远程端口 ID
	IndexRemoteIDOid = "1.3.6.1.4.1.3320.127.1.4.1.1.7."
	// IndexRemoteDesOid [GetNext] 交换机某端口的远程端口描述
	IndexRemoteDesOid = "1.3.6.1.4.1.3320.127.1.4.1.1.8."
	// IndexLocalPortOid [GetNext] 交换机某端口的本地端口
	IndexLocalPortOid = "1.3.6.1.4.1.3320.127.1.4.1.1.2."
	// IndexLocalIDOid [Get] 交换机某端口的本地端口 ID
	IndexLocalIDOid = "1.3.6.1.4.1.3320.127.1.3.7.1.3."
	// IndexLocalDesOid [Get] 交换机某端口的本地端口描述
	IndexLocalDesOid = "1.3.6.1.4.1.3320.127.1.3.7.1.4."
)

Variables

View Source
var NoneErr = errors.New("not result")

Functions

func Run

func Run(ips ...string) []byte

Run 获取 <ips> 地址交换机接口信息

func RunWithSpeed

func RunWithSpeed(ips ...string) []byte

RunWithSpeed 获取 <ips> 地址交换机接口信息

Types

type Equ

type Equ struct {
	ID   string
	IP   string
	Mac  string
	Type string
	Name string
}

type EquEngine

type EquEngine struct {
	Scheduler   Scheduler
	WorkerCount int
}

func (*EquEngine) Get

func (e *EquEngine) Get() (*Equs, error)

type EquScheduler

type EquScheduler struct {
	// contains filtered or unexported fields
}

func (*EquScheduler) ConfigureWorkerChan

func (e *EquScheduler) ConfigureWorkerChan(c chan string)

func (*EquScheduler) Submit

func (e *EquScheduler) Submit(header string)

type Equs

type Equs struct {
	Map  map[string]int
	Data []*Equ
}

func Get

func Get() (*Equs, error)

type IfUnit

type IfUnit struct {
	ID          string
	IP          string
	Description string
	Type        string
	Name        string
	Mac         string
	Speed       int
	InSpeed     int
	OutSpeed    int
	Status      int
}

func Fetch

func Fetch(ip string) ([]IfUnit, error)

Fetch 根据 <IP> 获取对应交换机的接口信息

func FetchWithSpeed

func FetchWithSpeed(ip string) ([]IfUnit, error)

type Result

type Result struct {
	gosnmp.SnmpPDU
}

func (Result) Int

func (r Result) Int() int

func (Result) MacString

func (r Result) MacString() string

func (Result) String

func (r Result) String() string

func (Result) Uint

func (r Result) Uint() uint

type SNMP

type SNMP struct {
	*gosnmp.GoSNMP
}

func NewSNMP

func NewSNMP(ip string) (*SNMP, error)

func (*SNMP) BulkWalk

func (s *SNMP) BulkWalk(oid string) ([]Result, error)

func (*SNMP) BulkWalkFunc

func (s *SNMP) BulkWalkFunc(oid string, fun gosnmp.WalkFunc) error

func (*SNMP) Close

func (s *SNMP) Close() error

func (*SNMP) Get

func (s *SNMP) Get(oid string) (Result, error)

func (*SNMP) GetAll

func (s *SNMP) GetAll(oids []string) ([]Result, error)

func (*SNMP) GetIfNumber

func (s *SNMP) GetIfNumber() (int, error)

GetIfNumber 获取交换机端口个数

func (*SNMP) GetMacAddress

func (s *SNMP) GetMacAddress() (map[int]string, error)

GetMacAddress 获取连接接口的设备的 MAC 地址 返回值为 接口索引 ==> mac 地址,一个端口的 mac 地址可能有多个

func (*SNMP) GetNext

func (s *SNMP) GetNext(oid string) (Result, error)

func (*SNMP) GetNextAll

func (s *SNMP) GetNextAll(oids []string) ([]Result, error)

func (*SNMP) Walk

func (s *SNMP) Walk(oid string) ([]Result, error)

func (*SNMP) WalkFunc

func (s *SNMP) WalkFunc(oid string, fun gosnmp.WalkFunc) error

type Scheduler

type Scheduler interface {
	Submit(string)
	ConfigureWorkerChan(chan string)
}

Jump to

Keyboard shortcuts

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