enh(generic-snmp): apply code suggestion from cargo build

This commit is contained in:
evan Adam 2025-06-13 16:28:55 +02:00 committed by David Boucher
parent c0a4bf0e85
commit 59c9ec1512
6 changed files with 34 additions and 33 deletions

View File

@ -156,7 +156,7 @@ impl<'input> Iterator for Lexer<'input> {
}
mod test {
use super::*;
use crate::compute::lexer::{Lexer, Tok};
fn init() {
let _ = env_logger::builder().is_test(true).try_init();

View File

@ -99,8 +99,9 @@ impl<'a> Parser<'a> {
}
mod test {
use super::*;
use log::info;
use crate::compute::{Parser, ast::ExprResult, grammar, lexer};
use crate::snmp::SnmpResult;
use log::{debug, info};
use std::collections::HashMap;
fn init() {

View File

@ -1,5 +1,4 @@
use crate::generic::error::Error;
use log::{debug, error, info, trace, warn};
use std::f64::INFINITY;
pub struct Threshold {
@ -108,17 +107,14 @@ impl Threshold {
return true;
}
}
if self.negation {
true
} else {
false
}
if self.negation { true } else { false }
}
}
mod test {
use super::*;
use crate::compute::threshold::Threshold;
use crate::generic::error::Error;
use std::f64::INFINITY;
#[test]
fn test_parse_value() {
let expr = "1.2";
@ -302,8 +298,10 @@ mod test {
panic!("The threshold '{}' should not be valid", expr);
}
Err(err) => {
assert_eq!(err.to_string(),
"Threshold: This syntax is a shortcut of '0:-12', so -12 must be greater than 0.");
assert_eq!(
err.to_string(),
"Threshold: This syntax is a shortcut of '0:-12', so -12 must be greater than 0."
);
}
}
}

View File

@ -16,8 +16,8 @@ mod output;
mod snmp;
use env_logger::Env;
use generic::error::*;
use generic::Command;
use generic::error::*;
use lalrpop_util::lalrpop_mod;
use lexopt::Arg;
use log::trace;

View File

@ -125,25 +125,27 @@ impl<'a> OutputFormatter<'a> {
let parser = Parser::new(&self.collect);
let res = parser.eval_str(&self.output_formatter.ok);
let output = match res {
Ok(output) => {
match output {
ExprResult::Str(output) => output,
ExprResult::Number(_) => {
error!("Output expression evaluated to a number, expected a string");
Ok(output) => match output {
ExprResult::Str(output) => output,
ExprResult::Number(_) => {
error!(
"Output expression evaluated to a number, expected a string"
);
return "".to_string();
}
ExprResult::StrVector(v) => {
if v.len() == 1 {
let output = v[0].clone();
output
} else {
error!(
"Output expression evaluated to a vector with more than one element, expected a single string"
);
return "".to_string();
}
ExprResult::StrVector(v) => {
if v.len() == 1 {
let output = v[0].clone();
output
} else {
error!("Output expression evaluated to a vector with more than one element, expected a single string");
return "".to_string();
}
}
_ => "".to_string(),
}
}
_ => "".to_string(),
},
Err(err) => {
error!("Error evaluating output expression: {:?}", err);
self.output_formatter.ok.clone()

View File

@ -10,7 +10,7 @@ use rasn_snmp::v2::BulkPdu;
use rasn_snmp::v2::Pdus;
use rasn_snmp::v2::VarBind;
use rasn_snmp::v2::VarBindValue;
use rasn_snmp::v2::{GetBulkRequest, GetNextRequest, GetRequest};
use rasn_snmp::v2::GetBulkRequest;
use rasn_snmp::v2c::Message;
use std::collections::HashMap;
use std::convert::TryInto;
@ -173,7 +173,7 @@ pub fn snmp_bulk_get<'a>(
oid: &Vec<&str>,
names: &Vec<&str>,
) -> SnmpResult {
let mut oids_tab = oid
let oids_tab = oid
.iter()
.map(|x| {
x.split('.')
@ -186,7 +186,7 @@ pub fn snmp_bulk_get<'a>(
items: HashMap::new(),
last_oid: Vec::new(),
};
let mut request_id: i32 = 1;
let request_id: i32 = 1;
let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
socket.connect(target).expect("connect function failed");