fix(json_v2): allow multiple optional objects (#10777)

This commit is contained in:
Reimer Prochnow 2022-03-08 15:55:30 +01:00 committed by GitHub
parent e9eab1f397
commit 03d7c4693e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 1 deletions

View File

@ -416,7 +416,7 @@ func (p *Parser) processObjects(input []byte, objects []JSONObject, timestamp ti
if c.Optional {
// If path is marked as optional don't error if path doesn't return a result
p.Log.Debugf(GJSONPathNUllErrorMSG)
return nil, nil
continue
}
return nil, fmt.Errorf(GJSONPathNUllErrorMSG)

View File

@ -0,0 +1,3 @@
file,Meter_number=12344 Power_curr=168,Total_in=2769.492 1646326975000000000
file Humidity=63.3,Pressure=1020.6,Temperature=22.5 1646335555000000000
file Illuminance=2.022 1646335555000000000

View File

@ -0,0 +1 @@
{"Time":"2022-03-03T17:02:55","MT681":{"Power_curr":168,"Total_in":2769.492,"Meter_number":"12344"}}

View File

@ -0,0 +1 @@
{"Time":"2022-03-03T19:25:55","BME280":{"Temperature":22.5,"Humidity":63.3,"DewPoint":15.1,"Pressure":1020.6,"SeaPressure":1024.1},"TSL2561":{"Illuminance":2.022,"IR":16,"Broadband":78},"PressureUnit":"hPa","TempUnit":"C"}

View File

@ -0,0 +1,21 @@
# Parse different objects
[[inputs.file]]
files = ["./testdata/optional_objects/input_1.json", "./testdata/optional_objects/input_2.json"]
data_format = "json_v2"
[[inputs.file.json_v2]]
timestamp_path = "Time"
timestamp_format = "2006-01-02T15:04:05"
[[inputs.file.json_v2.object]]
path = "BME280"
included_keys = ["Humidity", "Pressure", "Temperature"]
optional = true
[[inputs.file.json_v2.object]]
path = "TSL2561"
included_keys = ["Illuminance"]
optional = true
[[inputs.file.json_v2.object]]
path = "MT681"
optional = true
tags = ["Meter_number"]