Remove dead code: unused functions, constants, methods, and enum variant
This commit is contained in:
parent
23ccd24210
commit
36f89ddef3
3 changed files with 0 additions and 105 deletions
|
|
@ -8,7 +8,6 @@ type SecretString = Zeroizing<String>;
|
||||||
|
|
||||||
const SNMP_TIMEOUT_SECS: i64 = 10;
|
const SNMP_TIMEOUT_SECS: i64 = 10;
|
||||||
const SNMP_RETRIES: i32 = 2;
|
const SNMP_RETRIES: i32 = 2;
|
||||||
const MAX_OID_LEN: usize = 128;
|
|
||||||
|
|
||||||
// C structs and functions
|
// C structs and functions
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
|
@ -543,94 +542,6 @@ impl Drop for SnmpSession {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper functions
|
|
||||||
|
|
||||||
unsafe fn parse_variable(var: *mut Struct_variable_list) -> SnmpResult<SnmpValue> {
|
|
||||||
if var.is_null() {
|
|
||||||
return Err(SnmpError::RequestFailed("Null variable".into()));
|
|
||||||
}
|
|
||||||
|
|
||||||
let var_type = (*var)._type;
|
|
||||||
|
|
||||||
match var_type {
|
|
||||||
ASN_OCTET_STR => {
|
|
||||||
let len = (*var).val_len;
|
|
||||||
let string_ptr_ptr = (*var).val.string();
|
|
||||||
let string_ptr = *string_ptr_ptr;
|
|
||||||
let data = std::slice::from_raw_parts(string_ptr, len);
|
|
||||||
Ok(SnmpValue::OctetString(data.to_vec()))
|
|
||||||
}
|
|
||||||
ASN_INTEGER => {
|
|
||||||
let int_ptr_ptr = (*var).val.integer();
|
|
||||||
let int_ptr = *int_ptr_ptr;
|
|
||||||
let value = *int_ptr;
|
|
||||||
Ok(SnmpValue::Integer(value))
|
|
||||||
}
|
|
||||||
ASN_COUNTER => {
|
|
||||||
let int_ptr_ptr = (*var).val.integer();
|
|
||||||
let int_ptr = *int_ptr_ptr;
|
|
||||||
let value = *int_ptr as u32;
|
|
||||||
Ok(SnmpValue::Counter32(value))
|
|
||||||
}
|
|
||||||
ASN_GAUGE => {
|
|
||||||
let int_ptr_ptr = (*var).val.integer();
|
|
||||||
let int_ptr = *int_ptr_ptr;
|
|
||||||
let value = *int_ptr as u32;
|
|
||||||
Ok(SnmpValue::Gauge32(value))
|
|
||||||
}
|
|
||||||
ASN_TIMETICKS => {
|
|
||||||
let int_ptr_ptr = (*var).val.integer();
|
|
||||||
let int_ptr = *int_ptr_ptr;
|
|
||||||
let value = *int_ptr as u32;
|
|
||||||
Ok(SnmpValue::TimeTicks(value))
|
|
||||||
}
|
|
||||||
ASN_COUNTER64 => {
|
|
||||||
let counter64_ptr_ptr = (*var).val.counter64();
|
|
||||||
let counter64_ptr = *counter64_ptr_ptr;
|
|
||||||
let high = (*counter64_ptr).high;
|
|
||||||
let low = (*counter64_ptr).low;
|
|
||||||
let value = (high << 32) | low;
|
|
||||||
Ok(SnmpValue::Counter64(value))
|
|
||||||
}
|
|
||||||
ASN_IPADDRESS => {
|
|
||||||
let len = (*var).val_len;
|
|
||||||
let string_ptr_ptr = (*var).val.string();
|
|
||||||
let string_ptr = *string_ptr_ptr;
|
|
||||||
let data = std::slice::from_raw_parts(string_ptr, len);
|
|
||||||
if len == 4 {
|
|
||||||
let ip_str = format!("{}.{}.{}.{}", data[0], data[1], data[2], data[3]);
|
|
||||||
Ok(SnmpValue::IpAddress(ip_str))
|
|
||||||
} else {
|
|
||||||
Ok(SnmpValue::OctetString(data.to_vec()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ASN_OBJECT_ID => {
|
|
||||||
let oid_len = (*var).val_len / std::mem::size_of::<oid>();
|
|
||||||
let oid_ptr_ptr = (*var).val.objid();
|
|
||||||
let oid_ptr = *oid_ptr_ptr;
|
|
||||||
let oid_str = oid_to_string(oid_ptr, oid_len);
|
|
||||||
Ok(SnmpValue::Oid(oid_str))
|
|
||||||
}
|
|
||||||
ASN_NULL => Ok(SnmpValue::Null),
|
|
||||||
SNMP_NOSUCHOBJECT | SNMP_NOSUCHINSTANCE | SNMP_ENDOFMIBVIEW => {
|
|
||||||
Err(SnmpError::RequestFailed("No such object".into()))
|
|
||||||
}
|
|
||||||
_ => Err(SnmpError::RequestFailed(format!(
|
|
||||||
"Unknown type: {}",
|
|
||||||
var_type
|
|
||||||
))),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe fn oid_to_string(oid_ptr: *const oid, oid_len: usize) -> String {
|
|
||||||
let oid_slice = std::slice::from_raw_parts(oid_ptr, oid_len);
|
|
||||||
oid_slice
|
|
||||||
.iter()
|
|
||||||
.map(|n| n.to_string())
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(".")
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
||||||
|
|
@ -123,21 +123,11 @@ impl DevicePoller {
|
||||||
let _ = self.request_tx.send(SnmpRequest::Shutdown);
|
let _ = self.request_tx.send(SnmpRequest::Shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the device ID
|
|
||||||
pub fn device_id(&self) -> &str {
|
|
||||||
&self.device_id
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the device config
|
/// Get the device config
|
||||||
pub fn config(&self) -> &DeviceConfig {
|
pub fn config(&self) -> &DeviceConfig {
|
||||||
&self.config
|
&self.config
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update the device configuration
|
|
||||||
pub fn update_config(&mut self, new_config: DeviceConfig) {
|
|
||||||
self.config = new_config;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Log the status of this poller (for debugging)
|
/// Log the status of this poller (for debugging)
|
||||||
pub fn log_status(&self) {
|
pub fn log_status(&self) {
|
||||||
tracing::debug!(
|
tracing::debug!(
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ pub enum SnmpError {
|
||||||
RequestFailed(String),
|
RequestFailed(String),
|
||||||
InvalidOid(String),
|
InvalidOid(String),
|
||||||
Timeout,
|
Timeout,
|
||||||
AuthFailure,
|
|
||||||
NetworkUnreachable,
|
NetworkUnreachable,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -13,7 +12,6 @@ impl std::fmt::Display for SnmpError {
|
||||||
Self::RequestFailed(msg) => write!(f, "SNMP request failed: {}", msg),
|
Self::RequestFailed(msg) => write!(f, "SNMP request failed: {}", msg),
|
||||||
Self::InvalidOid(oid) => write!(f, "Invalid OID: {}", oid),
|
Self::InvalidOid(oid) => write!(f, "Invalid OID: {}", oid),
|
||||||
Self::Timeout => write!(f, "Timeout"),
|
Self::Timeout => write!(f, "Timeout"),
|
||||||
Self::AuthFailure => write!(f, "Authentication failure"),
|
|
||||||
Self::NetworkUnreachable => write!(f, "Network unreachable"),
|
Self::NetworkUnreachable => write!(f, "Network unreachable"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -74,10 +72,6 @@ mod tests {
|
||||||
"Invalid OID: 1.2.3"
|
"Invalid OID: 1.2.3"
|
||||||
);
|
);
|
||||||
assert_eq!(format!("{}", SnmpError::Timeout), "Timeout");
|
assert_eq!(format!("{}", SnmpError::Timeout), "Timeout");
|
||||||
assert_eq!(
|
|
||||||
format!("{}", SnmpError::AuthFailure),
|
|
||||||
"Authentication failure"
|
|
||||||
);
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
format!("{}", SnmpError::NetworkUnreachable),
|
format!("{}", SnmpError::NetworkUnreachable),
|
||||||
"Network unreachable"
|
"Network unreachable"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue