fix: now one device is one datapoint, it's way better to store it that way

Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
Louis Vallat 2022-07-02 14:27:16 +02:00
parent da1fa96505
commit d72d1530dc
No known key found for this signature in database
GPG Key ID: 0C87282F76E61283

View File

@ -123,24 +123,20 @@ async fn devices_to_datapoints(devices: &Vec<Device>, hostname: &String)
-> Vec<DataPoint> {
let mut datapoints = vec![];
for d in devices {
datapoints.append(&mut vec![
DataPoint::builder("devices").tag("hostname", hostname)
.field("name", d.name.clone()).tag("key", d.key.clone()).build().unwrap(),
DataPoint::builder("devices").tag("hostname", hostname)
.field("discovery_source", d.discovery_source.clone()).tag("key", d.key.clone()).build().unwrap(),
DataPoint::builder("devices").tag("hostname", hostname)
.field("active", d.active).tag("key", d.key.clone()).build().unwrap(),
DataPoint::builder("devices").tag("hostname", hostname)
.field("device_type", d.device_type.clone()).tag("key", d.key.clone()).build().unwrap(),
DataPoint::builder("devices").tag("hostname", hostname)
.field("tags", d.tags.clone()).tag("key", d.key.clone()).build().unwrap(),
DataPoint::builder("devices").tag("hostname", hostname)
.field("ip_address", d.ip_address.clone().unwrap_or("N/A".to_string())).tag("key", d.key.clone()).build().unwrap(),
DataPoint::builder("devices").tag("hostname", hostname)
.field("ssid", d.ssid.clone().unwrap_or("N/A".to_string())).tag("key", d.key.clone()).build().unwrap(),
DataPoint::builder("devices").tag("hostname", hostname)
.field("channel", d.channel.unwrap_or(0) as i64).tag("key", d.key.clone()).build().unwrap(),
]);
datapoints.push(
DataPoint::builder("devices")
.tag("hostname", hostname)
.tag("key", d.key.clone())
.field("name", d.name.clone())
.field("discovery_source", d.discovery_source.clone())
.field("active", d.active)
.field("device_type", d.device_type.clone())
.field("tags", d.tags.clone())
.field("ip_address", d.ip_address.clone().unwrap_or("N/A".to_string()))
.field("ssid", d.ssid.clone().unwrap_or("N/A".to_string()))
.field("channel", d.channel.unwrap_or(0) as i64).tag("key", d.key.clone())
.build().unwrap(),
);
}
return datapoints;
}