mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-29 16:45:04 +02:00
fix(generic-snmp): fix issues with snmp get
This commit is contained in:
parent
535064daa8
commit
49a82c49df
@ -16,19 +16,20 @@
|
||||
"compute": {
|
||||
"metrics": [
|
||||
{
|
||||
"name": "core.mem.usage.percent",
|
||||
"value": "100 * (1 - {free}/{cpu})",
|
||||
"name": "core.mem.usage.percent1",
|
||||
"value": "100 * (1 - {free} / {total})",
|
||||
"uom": "%",
|
||||
"min": 0,
|
||||
"max": 100,
|
||||
"threshold-suffix": "mem"
|
||||
},
|
||||
{
|
||||
"name": "avg.cpu.usage.percent",
|
||||
"value": "Average({cpu})",
|
||||
"name": "core.mem.usage.percent",
|
||||
"value": "100 * (1 - {free}/{total})",
|
||||
"uom": "%",
|
||||
"min": 0,
|
||||
"max": 100
|
||||
"max": 100,
|
||||
"threshold-suffix": "mem"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
use snmp::{SnmpItem, SnmpResult};
|
||||
use std::str;
|
||||
use log::debug;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Expr<'input> {
|
||||
@ -226,14 +227,17 @@ impl<'input> Expr<'input> {
|
||||
match self {
|
||||
Expr::Number(n) => ExprResult::Scalar(*n),
|
||||
Expr::Id(key) => {
|
||||
println!("Evaluation of Id '{}'", str::from_utf8(key).unwrap());
|
||||
for result in collect {
|
||||
let k = str::from_utf8(key).unwrap();
|
||||
let item = &result.items[k];
|
||||
match item {
|
||||
SnmpItem::Nbr(n) => {
|
||||
if n.len() == 1 {
|
||||
println!("value {}", n[0]);
|
||||
return ExprResult::Scalar(n[0]);
|
||||
} else {
|
||||
println!("value {:?}", n);
|
||||
return ExprResult::Vector(n.clone());
|
||||
}
|
||||
}
|
||||
|
@ -209,6 +209,23 @@ mod Test {
|
||||
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]
|
||||
fn function() {
|
||||
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() {
|
||||
let name = match &metric.prefix {
|
||||
Some(prefix) => {
|
||||
@ -146,12 +152,6 @@ impl Command {
|
||||
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 {
|
||||
status: Status::Unknown,
|
||||
output: "No result".to_string(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user