mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-09-22 09:17:55 +02:00
enh(generic-snmp): snmp version has the snmp version propagated to the execute function
This commit is contained in:
parent
9e284207b7
commit
a0ca6650f6
@ -155,7 +155,13 @@ fn build_metrics<'a>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Command {
|
impl Command {
|
||||||
pub fn execute(&self, target: &str, ext: &CommandExt) -> CmdResult {
|
pub fn execute(
|
||||||
|
&self,
|
||||||
|
target: &str,
|
||||||
|
version: &str,
|
||||||
|
community: &str,
|
||||||
|
ext: &CommandExt,
|
||||||
|
) -> CmdResult {
|
||||||
let mut agregation = ("", 0, Operation::None);
|
let mut agregation = ("", 0, Operation::None);
|
||||||
let mut res: Option<(&str, SnmpResult)> = None;
|
let mut res: Option<(&str, SnmpResult)> = None;
|
||||||
for (idx, entry) in self.leaf.entries.iter().enumerate() {
|
for (idx, entry) in self.leaf.entries.iter().enumerate() {
|
||||||
@ -165,7 +171,10 @@ impl Command {
|
|||||||
}
|
}
|
||||||
Entry::Query(query) => match query.query {
|
Entry::Query(query) => match query.query {
|
||||||
QueryType::Walk => {
|
QueryType::Walk => {
|
||||||
res = Some((&query.name, r_snmp_bulk_walk(target, &query.oid)));
|
res = Some((
|
||||||
|
&query.name,
|
||||||
|
r_snmp_bulk_walk(target, version, community, &query.oid),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ extern crate log;
|
|||||||
extern crate rasn;
|
extern crate rasn;
|
||||||
extern crate rasn_smi;
|
extern crate rasn_smi;
|
||||||
extern crate rasn_snmp;
|
extern crate rasn_snmp;
|
||||||
extern crate regex;
|
|
||||||
|
|
||||||
use log::{info, trace, warn};
|
use log::{info, trace, warn};
|
||||||
use rasn::types::ObjectIdentifier;
|
use rasn::types::ObjectIdentifier;
|
||||||
@ -12,7 +11,6 @@ use rasn_snmp::v2::VarBindValue;
|
|||||||
use rasn_snmp::v2::{BulkPdu, Pdu};
|
use rasn_snmp::v2::{BulkPdu, Pdu};
|
||||||
use rasn_snmp::v2::{GetBulkRequest, GetNextRequest, GetRequest};
|
use rasn_snmp::v2::{GetBulkRequest, GetNextRequest, GetRequest};
|
||||||
use rasn_snmp::v2c::Message;
|
use rasn_snmp::v2c::Message;
|
||||||
use regex::Regex;
|
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::net::UdpSocket;
|
use std::net::UdpSocket;
|
||||||
@ -274,10 +272,9 @@ pub fn r_snmp_walk(target: &str, oid: &str) -> SnmpResult {
|
|||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
/// use snmp_rust::r_snmp_bulk_walk;
|
/// use snmp_rust::r_snmp_bulk_walk;
|
||||||
/// let result = r_snmp_bulk_walk("127.0.0.1:161", "1.3.6.1.2.1.25.3.3.1.2");
|
/// let result = r_snmp_bulk_walk("127.0.0.1:161", "2c", "public", "1.3.6.1.2.1.25.3.3.1.2");
|
||||||
/// ```
|
/// ```
|
||||||
pub fn r_snmp_bulk_walk(target: &str, oid: &str) -> SnmpResult {
|
pub fn r_snmp_bulk_walk(target: &str, version: &str, community: &str, oid: &str) -> SnmpResult {
|
||||||
let community = "public";
|
|
||||||
let oid_tab = oid
|
let oid_tab = oid
|
||||||
.split('.')
|
.split('.')
|
||||||
.map(|x| x.parse::<u32>().unwrap())
|
.map(|x| x.parse::<u32>().unwrap())
|
||||||
@ -301,7 +298,7 @@ pub fn r_snmp_bulk_walk(target: &str, oid: &str) -> SnmpResult {
|
|||||||
|
|
||||||
let message: Message<GetBulkRequest> = Message {
|
let message: Message<GetBulkRequest> = Message {
|
||||||
version: 1.into(),
|
version: 1.into(),
|
||||||
community: community.into(),
|
community: community.to_string().into(),
|
||||||
data: get_request.into(),
|
data: get_request.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -417,7 +414,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_snmp_bulk_walk() {
|
fn test_snmp_bulk_walk() {
|
||||||
let result = r_snmp_bulk_walk("127.0.0.1:161", "1.3.6.1.2.1.25.3.3.1.2");
|
let result = r_snmp_bulk_walk("127.0.0.1:161", "2c", "public", "1.3.6.1.2.1.25.3.3.1.2");
|
||||||
let re = Regex::new(r"[0-9]+").unwrap();
|
let re = Regex::new(r"[0-9]+").unwrap();
|
||||||
assert!(result.variables.len() > 0);
|
assert!(result.variables.len() > 0);
|
||||||
for v in result.variables.iter() {
|
for v in result.variables.iter() {
|
||||||
|
@ -70,7 +70,7 @@ fn main() {
|
|||||||
warning_agregation: cli.warning_agregation,
|
warning_agregation: cli.warning_agregation,
|
||||||
critical_agregation: cli.critical_agregation,
|
critical_agregation: cli.critical_agregation,
|
||||||
};
|
};
|
||||||
let result = cmd.execute(&url, &cli.community, &ext);
|
let result = cmd.execute(&url, &cli.snmp_version, &cli.community, &ext);
|
||||||
println!("{}", result.output);
|
println!("{}", result.output);
|
||||||
std::process::exit(result.status);
|
std::process::exit(result.status);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user