Skip to content

Commit

Permalink
fix: nil map panic when use snmp_trap with netsnmp translator
Browse files Browse the repository at this point in the history
  • Loading branch information
PapaPiya committed Jul 21, 2022
1 parent 08c895d commit ba50ece
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion plugins/inputs/snmp_trap/netsnmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ func (s *netsnmpTranslator) snmptranslate(oid string) (e snmp.MibEntry, err erro
return e, nil
}

func newNetsnmpTranslator() *netsnmpTranslator {
func newNetsnmpTranslator(timeout config.Duration) *netsnmpTranslator {
return &netsnmpTranslator{
execCmd: realExecCmd,
cache: make(map[string]snmp.MibEntry),
Timeout: timeout,
}
}
5 changes: 4 additions & 1 deletion plugins/inputs/snmp_trap/snmp_trap.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"github.com/influxdata/telegraf/plugins/inputs"
)

var defaultTimeout = config.Duration(time.Second * 5)

// DO NOT REMOVE THE NEXT TWO LINES! This is required to embed the sampleConfig data.
//go:embed sample.conf
var sampleConfig string
Expand Down Expand Up @@ -68,6 +70,7 @@ func init() {
return &SnmpTrap{
timeFunc: time.Now,
ServiceAddress: "udp://:162",
Timeout: defaultTimeout,
Path: []string{"/usr/share/snmp/mibs"},
Version: "2c",
}
Expand All @@ -87,7 +90,7 @@ func (s *SnmpTrap) Init() error {
return err
}
case "netsnmp":
s.translator = newNetsnmpTranslator()
s.translator = newNetsnmpTranslator(s.Timeout)
default:
return fmt.Errorf("invalid translator value")
}
Expand Down

0 comments on commit ba50ece

Please sign in to comment.