Change tag-srtting to recursive by field

This will properly set e.g. arrays
f_docker
Ruakij 3 years ago
parent 2646c9787e
commit 4ad5eba7e0

@ -42,8 +42,11 @@ class PacketInfluxPointFactory extends Transform{
let point = new Point(measurement); // Create point let point = new Point(measurement); // Create point
// Set tags // Set tags
TAG_LIST.filter(tag => Object.keys(packet).includes(tag)) TAG_LIST.filter(tag => Object.keys(packet).includes(tag)) // Filter tags available on object
.forEach(tag => point.tag(tag, packet[tag])); .filter(tag => packet[tag] != null) // Filter tags not falsy on object
.forEach(tag => {
tagObjectRecursively(point, tag, packet[tag]);
});
point.setField('value', packet[objKey]); // Set field point.setField('value', packet[objKey]); // Set field
@ -54,6 +57,15 @@ class PacketInfluxPointFactory extends Transform{
} }
} }
function tagObjectRecursively(point, tag, field, suffix = ""){
if(typeof(field) == "object"){
// TODO: Convert boolean-arrays like "packet.flags" to key: value
Object.entries(field).map(([key, value]) => {
tagObjectRecursively(point, tag, value, `_${key}${suffix}`);
});
}
else point.tag(tag+suffix, field);
}
/** Mapping for type -> field-method */ /** Mapping for type -> field-method */
const POINT_FIELD_TYPE = new Map([ const POINT_FIELD_TYPE = new Map([

Loading…
Cancel
Save