fix(inputs.ipset): Parse lines with timeout (#14262)
This commit is contained in:
parent
d644ffd3d2
commit
7d79111135
|
|
@ -73,18 +73,31 @@ func (i *Ipset) Gather(acc telegraf.Accumulator) error {
|
||||||
"set": data[1],
|
"set": data[1],
|
||||||
"rule": data[2],
|
"rule": data[2],
|
||||||
}
|
}
|
||||||
packetsTotal, err := strconv.ParseUint(data[4], 10, 64)
|
|
||||||
|
fields := make(map[string]interface{}, 3)
|
||||||
|
for i, field := range data {
|
||||||
|
switch field {
|
||||||
|
case "timeout":
|
||||||
|
val, err := strconv.ParseUint(data[i+1], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(err)
|
acc.AddError(err)
|
||||||
}
|
}
|
||||||
bytesTotal, err := strconv.ParseUint(data[6], 10, 64)
|
fields["timeout"] = val
|
||||||
|
case "packets":
|
||||||
|
val, err := strconv.ParseUint(data[i+1], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(err)
|
acc.AddError(err)
|
||||||
}
|
}
|
||||||
fields := map[string]interface{}{
|
fields["packets_total"] = val
|
||||||
"packets_total": packetsTotal,
|
case "bytes":
|
||||||
"bytes_total": bytesTotal,
|
val, err := strconv.ParseUint(data[i+1], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
acc.AddError(err)
|
||||||
}
|
}
|
||||||
|
fields["bytes_total"] = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
acc.AddCounter(measurement, fields, tags)
|
acc.AddCounter(measurement, fields, tags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,22 @@ func TestIpset(t *testing.T) {
|
||||||
{map[string]interface{}{"packets_total": uint64(3), "bytes_total": uint64(222)}},
|
{map[string]interface{}{"packets_total": uint64(3), "bytes_total": uint64(222)}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Sets with and without timeouts",
|
||||||
|
value: `create counter-test hash:ip family inet hashsize 1024 maxelem 65536 timeout 1800 counters
|
||||||
|
add counter-test 192.168.1.1 timeout 1792 packets 8 bytes 672
|
||||||
|
create counter-test2 hash:ip family inet hashsize 1024 maxelem 65536 counters
|
||||||
|
add counter-test2 192.168.1.1 packets 18 bytes 673
|
||||||
|
`,
|
||||||
|
tags: []map[string]string{
|
||||||
|
{"set": "counter-test", "rule": "192.168.1.1"},
|
||||||
|
{"set": "counter-test2", "rule": "192.168.1.1"},
|
||||||
|
},
|
||||||
|
fields: [][]map[string]interface{}{
|
||||||
|
{map[string]interface{}{"packets_total": uint64(8), "bytes_total": uint64(672), "timeout": uint64(1792)}},
|
||||||
|
{map[string]interface{}{"packets_total": uint64(18), "bytes_total": uint64(673)}},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tt := range tests {
|
for i, tt := range tests {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue