mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-30 00:55:18 +02:00
fix(generic-snmp): fix issues with snmp get
This commit is contained in:
parent
535064daa8
commit
49a82c49df
@ -16,19 +16,20 @@
|
|||||||
"compute": {
|
"compute": {
|
||||||
"metrics": [
|
"metrics": [
|
||||||
{
|
{
|
||||||
"name": "core.mem.usage.percent",
|
"name": "core.mem.usage.percent1",
|
||||||
"value": "100 * (1 - {free}/{cpu})",
|
"value": "100 * (1 - {free} / {total})",
|
||||||
"uom": "%",
|
"uom": "%",
|
||||||
"min": 0,
|
"min": 0,
|
||||||
"max": 100,
|
"max": 100,
|
||||||
"threshold-suffix": "mem"
|
"threshold-suffix": "mem"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "avg.cpu.usage.percent",
|
"name": "core.mem.usage.percent",
|
||||||
"value": "Average({cpu})",
|
"value": "100 * (1 - {free}/{total})",
|
||||||
"uom": "%",
|
"uom": "%",
|
||||||
"min": 0,
|
"min": 0,
|
||||||
"max": 100
|
"max": 100,
|
||||||
|
"threshold-suffix": "mem"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use snmp::{SnmpItem, SnmpResult};
|
use snmp::{SnmpItem, SnmpResult};
|
||||||
use std::str;
|
use std::str;
|
||||||
|
use log::debug;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Expr<'input> {
|
pub enum Expr<'input> {
|
||||||
@ -226,14 +227,17 @@ impl<'input> Expr<'input> {
|
|||||||
match self {
|
match self {
|
||||||
Expr::Number(n) => ExprResult::Scalar(*n),
|
Expr::Number(n) => ExprResult::Scalar(*n),
|
||||||
Expr::Id(key) => {
|
Expr::Id(key) => {
|
||||||
|
println!("Evaluation of Id '{}'", str::from_utf8(key).unwrap());
|
||||||
for result in collect {
|
for result in collect {
|
||||||
let k = str::from_utf8(key).unwrap();
|
let k = str::from_utf8(key).unwrap();
|
||||||
let item = &result.items[k];
|
let item = &result.items[k];
|
||||||
match item {
|
match item {
|
||||||
SnmpItem::Nbr(n) => {
|
SnmpItem::Nbr(n) => {
|
||||||
if n.len() == 1 {
|
if n.len() == 1 {
|
||||||
|
println!("value {}", n[0]);
|
||||||
return ExprResult::Scalar(n[0]);
|
return ExprResult::Scalar(n[0]);
|
||||||
} else {
|
} else {
|
||||||
|
println!("value {:?}", n);
|
||||||
return ExprResult::Vector(n.clone());
|
return ExprResult::Vector(n.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,6 +209,23 @@ mod Test {
|
|||||||
assert!(res.is_err());
|
assert!(res.is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn two_identifiers() {
|
||||||
|
let lexer = lexer::Lexer::new("100 * (1 - {free}/{total})");
|
||||||
|
let res = grammar::ExprParser::new().parse(lexer);
|
||||||
|
assert!(res.is_ok());
|
||||||
|
let items = HashMap::from([
|
||||||
|
("free".to_string(), SnmpItem::Nbr(vec![29600_f64])),
|
||||||
|
("total".to_string(), SnmpItem::Nbr(vec![747712_f64])),
|
||||||
|
]);
|
||||||
|
let snmp_result = vec![SnmpResult::new(items)];
|
||||||
|
let res = res.unwrap().eval(&snmp_result);
|
||||||
|
match res {
|
||||||
|
ExprResult::Scalar(n) => assert!(n == 96.04125652657707_f64),
|
||||||
|
_ => panic!("Expected a scalar value"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn function() {
|
fn function() {
|
||||||
let lexer = lexer::Lexer::new("Average({abc})");
|
let lexer = lexer::Lexer::new("Average({abc})");
|
||||||
|
@ -130,6 +130,12 @@ impl Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !to_get.is_empty() {
|
||||||
|
let r = snmp_bulk_get(target, version, community, 1, 1, &to_get, &get_name);
|
||||||
|
collect.push(r);
|
||||||
|
}
|
||||||
|
println!("{:#?}", collect);
|
||||||
|
|
||||||
for (i, metric) in self.compute.metrics.iter().enumerate() {
|
for (i, metric) in self.compute.metrics.iter().enumerate() {
|
||||||
let name = match &metric.prefix {
|
let name = match &metric.prefix {
|
||||||
Some(prefix) => {
|
Some(prefix) => {
|
||||||
@ -146,12 +152,6 @@ impl Command {
|
|||||||
println!("value result: {:?}", value);
|
println!("value result: {:?}", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !to_get.is_empty() {
|
|
||||||
let r = snmp_bulk_get(target, version, community, 1, 1, &to_get, &get_name);
|
|
||||||
collect.push(r);
|
|
||||||
}
|
|
||||||
println!("{:#?}", collect);
|
|
||||||
|
|
||||||
CmdResult {
|
CmdResult {
|
||||||
status: Status::Unknown,
|
status: Status::Unknown,
|
||||||
output: "No result".to_string(),
|
output: "No result".to_string(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user