diff --git a/experimental/src/compute/mod.rs b/experimental/src/compute/mod.rs index 475da4f14..6c8212466 100644 --- a/experimental/src/compute/mod.rs +++ b/experimental/src/compute/mod.rs @@ -17,7 +17,8 @@ pub struct Metric { pub name: String, pub prefix: Option, pub value: String, - uom: Option, + #[serde(default = "empty_string")] + pub uom: String, pub min_expr: Option, pub min: Option, pub max_expr: Option, @@ -28,6 +29,10 @@ pub struct Metric { pub critical: Option, } +fn empty_string() -> String { + "".to_string() +} + #[derive(Deserialize, Debug)] pub struct Compute { pub metrics: Vec, diff --git a/experimental/src/generic/mod.rs b/experimental/src/generic/mod.rs index 6c0dd68ce..9abe69f00 100644 --- a/experimental/src/generic/mod.rs +++ b/experimental/src/generic/mod.rs @@ -17,6 +17,7 @@ use crate::snmp::SnmpResult; pub struct Perfdata<'p> { pub name: String, pub value: f64, + pub uom: &'p str, pub min: Option, pub max: Option, pub warning: Option<&'p str>, @@ -170,7 +171,12 @@ impl Command { } } - fn execute_collect(&self, target: &str, version: &str, community: &str) -> Vec { + fn execute_snmp_collect( + &self, + target: &str, + version: &str, + community: &str, + ) -> Vec { let mut collect: Vec = Vec::new(); let mut to_get = Vec::new(); let mut get_name = Vec::new(); @@ -202,7 +208,7 @@ impl Command { } pub fn execute(&self, target: &str, version: &str, community: &str) -> Result { - let mut collect = self.execute_collect(target, version, community); + let mut collect = self.execute_snmp_collect(target, version, community); let mut idx: u32 = 0; let mut metrics = vec![]; @@ -264,6 +270,7 @@ impl Command { let m = Perfdata { name, value: *item, + uom: &metric.uom, min: compute_threshold(i, &min), max: compute_threshold(i, &max), warning: w, @@ -297,6 +304,7 @@ impl Command { let m = Perfdata { name, value: *s, + uom: &metric.uom, min: compute_threshold(0, &min), max: compute_threshold(0, &max), warning: w, @@ -375,6 +383,7 @@ impl Command { let m = Perfdata { name, value: *item, + uom: &metric.uom, min, max, warning: w, @@ -399,6 +408,7 @@ impl Command { let m = Perfdata { name: name.to_string(), value: *s, + uom: &metric.uom, min, max, warning: w, diff --git a/experimental/src/output/mod.rs b/experimental/src/output/mod.rs index b51034b5a..3c223f4ab 100644 --- a/experimental/src/output/mod.rs +++ b/experimental/src/output/mod.rs @@ -99,9 +99,10 @@ impl<'a> OutputFormatter<'a> { .iter() .map(|m| { format!( - "{}={};{};{};{};{}", + "{}={}{};{};{};{};{}", m.name, float_string(&m.value), + m.uom, m.warning.unwrap_or(""), m.critical.unwrap_or(""), match m.min {