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> { -> Vec<DataPoint> {
let mut datapoints = vec![]; let mut datapoints = vec![];
for d in devices { for d in devices {
datapoints.append(&mut vec![ datapoints.push(
DataPoint::builder("devices").tag("hostname", hostname) DataPoint::builder("devices")
.field("name", d.name.clone()).tag("key", d.key.clone()).build().unwrap(), .tag("hostname", hostname)
DataPoint::builder("devices").tag("hostname", hostname) .tag("key", d.key.clone())
.field("discovery_source", d.discovery_source.clone()).tag("key", d.key.clone()).build().unwrap(), .field("name", d.name.clone())
DataPoint::builder("devices").tag("hostname", hostname) .field("discovery_source", d.discovery_source.clone())
.field("active", d.active).tag("key", d.key.clone()).build().unwrap(), .field("active", d.active)
DataPoint::builder("devices").tag("hostname", hostname) .field("device_type", d.device_type.clone())
.field("device_type", d.device_type.clone()).tag("key", d.key.clone()).build().unwrap(), .field("tags", d.tags.clone())
DataPoint::builder("devices").tag("hostname", hostname) .field("ip_address", d.ip_address.clone().unwrap_or("N/A".to_string()))
.field("tags", d.tags.clone()).tag("key", d.key.clone()).build().unwrap(), .field("ssid", d.ssid.clone().unwrap_or("N/A".to_string()))
DataPoint::builder("devices").tag("hostname", hostname) .field("channel", d.channel.unwrap_or(0) as i64).tag("key", d.key.clone())
.field("ip_address", d.ip_address.clone().unwrap_or("N/A".to_string())).tag("key", d.key.clone()).build().unwrap(), .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(),
]);
} }
return datapoints; return datapoints;
} }