这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/scollector/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ type Conf struct {
// UserAgentMessage is an optional message that is appended to the User Agent
UserAgentMessage string

// SNMPTimeout is the number of seconds to wait for SNMP responses (default 30)
SNMPTimeout int

HAProxy []HAProxy
SNMP []SNMP
MIBS map[string]MIB
Expand Down
4 changes: 4 additions & 0 deletions cmd/scollector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"bosun.org/metadata"
"bosun.org/opentsdb"
"bosun.org/slog"
"bosun.org/snmp"
"bosun.org/util"
"github.com/BurntSushi/toml"
"github.com/facebookgo/httpcontrol"
Expand Down Expand Up @@ -123,6 +124,9 @@ func main() {
if conf.ColDir != "" {
collectors.InitPrograms(conf.ColDir)
}
if conf.SNMPTimeout > 0 {
snmp.Timeout = conf.SNMPTimeout
}
var err error
check := func(e error) {
if e != nil {
Expand Down
5 changes: 4 additions & 1 deletion snmp/snmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (
"bosun.org/snmp/asn1"
)

//Timeout is the number of seconds to use for conn.SetReadDeadline
var Timeout = 30

// reserved binding values.
var (
null = asn1.RawValue{Class: 0, Tag: 5}
Expand Down Expand Up @@ -236,7 +239,7 @@ func (s *SNMP) do(req *request) (*response, error) {
return nil, err
}
buf = make([]byte, 10000, 10000)
if err := conn.SetReadDeadline(time.Now().Add(5 * time.Second)); err != nil {
if err := conn.SetReadDeadline(time.Now().Add(time.Duration(Timeout) * time.Second)); err != nil {
return nil, err
}
n, err := conn.Read(buf)
Expand Down