mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-31 01:24:35 +02:00
enh(generic-snm): uom available in the output
This commit is contained in:
parent
4a20038a42
commit
5a3aa41887
@ -17,7 +17,8 @@ pub struct Metric {
|
|||||||
pub name: String,
|
pub name: String,
|
||||||
pub prefix: Option<String>,
|
pub prefix: Option<String>,
|
||||||
pub value: String,
|
pub value: String,
|
||||||
uom: Option<String>,
|
#[serde(default = "empty_string")]
|
||||||
|
pub uom: String,
|
||||||
pub min_expr: Option<String>,
|
pub min_expr: Option<String>,
|
||||||
pub min: Option<f64>,
|
pub min: Option<f64>,
|
||||||
pub max_expr: Option<String>,
|
pub max_expr: Option<String>,
|
||||||
@ -28,6 +29,10 @@ pub struct Metric {
|
|||||||
pub critical: Option<String>,
|
pub critical: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn empty_string() -> String {
|
||||||
|
"".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
pub struct Compute {
|
pub struct Compute {
|
||||||
pub metrics: Vec<Metric>,
|
pub metrics: Vec<Metric>,
|
||||||
|
@ -17,6 +17,7 @@ use crate::snmp::SnmpResult;
|
|||||||
pub struct Perfdata<'p> {
|
pub struct Perfdata<'p> {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub value: f64,
|
pub value: f64,
|
||||||
|
pub uom: &'p str,
|
||||||
pub min: Option<f64>,
|
pub min: Option<f64>,
|
||||||
pub max: Option<f64>,
|
pub max: Option<f64>,
|
||||||
pub warning: Option<&'p str>,
|
pub warning: Option<&'p str>,
|
||||||
@ -170,7 +171,12 @@ impl Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn execute_collect(&self, target: &str, version: &str, community: &str) -> Vec<SnmpResult> {
|
fn execute_snmp_collect(
|
||||||
|
&self,
|
||||||
|
target: &str,
|
||||||
|
version: &str,
|
||||||
|
community: &str,
|
||||||
|
) -> Vec<SnmpResult> {
|
||||||
let mut collect: Vec<SnmpResult> = Vec::new();
|
let mut collect: Vec<SnmpResult> = Vec::new();
|
||||||
let mut to_get = Vec::new();
|
let mut to_get = Vec::new();
|
||||||
let mut get_name = 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<CmdResult> {
|
pub fn execute(&self, target: &str, version: &str, community: &str) -> Result<CmdResult> {
|
||||||
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 idx: u32 = 0;
|
||||||
let mut metrics = vec![];
|
let mut metrics = vec![];
|
||||||
@ -264,6 +270,7 @@ impl Command {
|
|||||||
let m = Perfdata {
|
let m = Perfdata {
|
||||||
name,
|
name,
|
||||||
value: *item,
|
value: *item,
|
||||||
|
uom: &metric.uom,
|
||||||
min: compute_threshold(i, &min),
|
min: compute_threshold(i, &min),
|
||||||
max: compute_threshold(i, &max),
|
max: compute_threshold(i, &max),
|
||||||
warning: w,
|
warning: w,
|
||||||
@ -297,6 +304,7 @@ impl Command {
|
|||||||
let m = Perfdata {
|
let m = Perfdata {
|
||||||
name,
|
name,
|
||||||
value: *s,
|
value: *s,
|
||||||
|
uom: &metric.uom,
|
||||||
min: compute_threshold(0, &min),
|
min: compute_threshold(0, &min),
|
||||||
max: compute_threshold(0, &max),
|
max: compute_threshold(0, &max),
|
||||||
warning: w,
|
warning: w,
|
||||||
@ -375,6 +383,7 @@ impl Command {
|
|||||||
let m = Perfdata {
|
let m = Perfdata {
|
||||||
name,
|
name,
|
||||||
value: *item,
|
value: *item,
|
||||||
|
uom: &metric.uom,
|
||||||
min,
|
min,
|
||||||
max,
|
max,
|
||||||
warning: w,
|
warning: w,
|
||||||
@ -399,6 +408,7 @@ impl Command {
|
|||||||
let m = Perfdata {
|
let m = Perfdata {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
value: *s,
|
value: *s,
|
||||||
|
uom: &metric.uom,
|
||||||
min,
|
min,
|
||||||
max,
|
max,
|
||||||
warning: w,
|
warning: w,
|
||||||
|
@ -99,9 +99,10 @@ impl<'a> OutputFormatter<'a> {
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|m| {
|
.map(|m| {
|
||||||
format!(
|
format!(
|
||||||
"{}={};{};{};{};{}",
|
"{}={}{};{};{};{};{}",
|
||||||
m.name,
|
m.name,
|
||||||
float_string(&m.value),
|
float_string(&m.value),
|
||||||
|
m.uom,
|
||||||
m.warning.unwrap_or(""),
|
m.warning.unwrap_or(""),
|
||||||
m.critical.unwrap_or(""),
|
m.critical.unwrap_or(""),
|
||||||
match m.min {
|
match m.min {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user