fix(inputs.snmp_trap): nil map panic when use snmp_trap with netsnmp translator (#11534)
This commit is contained in:
parent
9f3a7414a9
commit
79235cb224
|
|
@ -82,8 +82,10 @@ func (s *netsnmpTranslator) snmptranslate(oid string) (e snmp.MibEntry, err erro
|
||||||
return e, nil
|
return e, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newNetsnmpTranslator() *netsnmpTranslator {
|
func newNetsnmpTranslator(timeout config.Duration) *netsnmpTranslator {
|
||||||
return &netsnmpTranslator{
|
return &netsnmpTranslator{
|
||||||
execCmd: realExecCmd,
|
execCmd: realExecCmd,
|
||||||
|
cache: make(map[string]snmp.MibEntry),
|
||||||
|
Timeout: timeout,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@ import (
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"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.
|
// DO NOT REMOVE THE NEXT TWO LINES! This is required to embed the sampleConfig data.
|
||||||
//go:embed sample.conf
|
//go:embed sample.conf
|
||||||
var sampleConfig string
|
var sampleConfig string
|
||||||
|
|
@ -68,6 +70,7 @@ func init() {
|
||||||
return &SnmpTrap{
|
return &SnmpTrap{
|
||||||
timeFunc: time.Now,
|
timeFunc: time.Now,
|
||||||
ServiceAddress: "udp://:162",
|
ServiceAddress: "udp://:162",
|
||||||
|
Timeout: defaultTimeout,
|
||||||
Path: []string{"/usr/share/snmp/mibs"},
|
Path: []string{"/usr/share/snmp/mibs"},
|
||||||
Version: "2c",
|
Version: "2c",
|
||||||
}
|
}
|
||||||
|
|
@ -87,7 +90,7 @@ func (s *SnmpTrap) Init() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case "netsnmp":
|
case "netsnmp":
|
||||||
s.translator = newNetsnmpTranslator()
|
s.translator = newNetsnmpTranslator(s.Timeout)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("invalid translator value")
|
return fmt.Errorf("invalid translator value")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue