Skip to content

Commit

Permalink
Fix null interface panic on empty capture group from multistringparse…
Browse files Browse the repository at this point in the history
…r tag
  • Loading branch information
sbengo committed Mar 18, 2018
1 parent 52572e7 commit 0b3a040
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 12 additions & 2 deletions pkg/config/snmpmetriccfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,24 @@ func (m *SnmpMetricCfg) GetMultiStringTagFieldMap() ([]*MetricMultiMap, error) {
if iType == "F" {
iConv = "INT"
}
if len(itcfg) > 2 {
if len(itcfg) > 2 && iType == "F" {
switch itcfg[2] {
case "STR":
case "BL":
case "INT":
case "FP":
default:
str := fmt.Sprintf("MultiString Parse Config error on Metric %s Conversion Type (%s) should be of type STR|INT|FP|BL", m.ID, itcfg[2])
str := fmt.Sprintf("MultiString Parse Config error on Metric %s Conversion Type (%s) for FIELD should be of type STR|INT|FP|BL", m.ID, itcfg[2])
log.Errorf(str)
return nil, errors.New(str)
}
iConv = itcfg[2]
}
if len(itcfg) > 2 && iType == "T" {
switch itcfg[2] {
case "STR":
default:
str := fmt.Sprintf("MultiString Parse Config error on Metric %s Conversion Type (%s) for TAG should be of type STR", m.ID, itcfg[2])
log.Errorf(str)
return nil, errors.New(str)
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/data/metric/snmpmetric.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ func (s *SnmpMetric) computeMultiStringParserValues() {
}
if err != nil {
s.log.Warnf("Error for Metric %s MULTISTRINGPARSER Field [%s|%s|%s] Coversion from [%s] error: %s", s.cfg.ID, i.IType, i.IName, i.IConv, bitstr, err)
i.Value = nil
}
}
}
Expand All @@ -550,10 +551,12 @@ func (s *SnmpMetric) addMultiStringParserValues(tags map[string]string, fields m
for _, i := range s.mm {
switch i.IType {
case "T":
if i.Value == nil {
continue
}
tags[i.IName] = i.Value.(string)
case "F":
fields[i.IName] = i.Value

}
}
return fErrors
Expand Down

0 comments on commit 0b3a040

Please sign in to comment.