fix live and scheduled polling
This commit is contained in:
parent
d44682ce9c
commit
8c969401fb
5 changed files with 29 additions and 9 deletions
|
|
@ -162,6 +162,7 @@ message SnmpResult {
|
||||||
JobType job_type = 2;
|
JobType job_type = 2;
|
||||||
map<string, string> oid_values = 3;
|
map<string, string> oid_values = 3;
|
||||||
int64 timestamp = 4;
|
int64 timestamp = 4;
|
||||||
|
string job_id = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
message AgentHeartbeat {
|
message AgentHeartbeat {
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@ use crate::config::{AgentConfig, HeartbeatMetadata};
|
||||||
use crate::metrics::Metric;
|
use crate::metrics::Metric;
|
||||||
use crate::proto::agent;
|
use crate::proto::agent;
|
||||||
use prost::Message;
|
use prost::Message;
|
||||||
use serde_json::json;
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
use tracing::debug;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum ApiError {
|
pub enum ApiError {
|
||||||
|
|
@ -49,15 +49,19 @@ impl ApiClient {
|
||||||
.map_err(|e| ApiError::RequestFailed(e.to_string()))?;
|
.map_err(|e| ApiError::RequestFailed(e.to_string()))?;
|
||||||
|
|
||||||
let status = response.status();
|
let status = response.status();
|
||||||
|
debug!("fetch_config response: status={}", status);
|
||||||
|
|
||||||
if status != 200 {
|
if status != 200 {
|
||||||
return Err(ApiError::StatusError(status));
|
return Err(ApiError::StatusError(status));
|
||||||
}
|
}
|
||||||
|
|
||||||
let config: AgentConfig = response
|
let body = response
|
||||||
.into_json()
|
.into_string()
|
||||||
.map_err(|e| ApiError::RequestFailed(e.to_string()))?;
|
.map_err(|e| ApiError::RequestFailed(e.to_string()))?;
|
||||||
|
debug!("fetch_config response body: {}", body);
|
||||||
|
|
||||||
Ok(config)
|
let config: AgentConfig = serde_json::from_str(&body)
|
||||||
|
.map_err(|e| ApiError::RequestFailed(e.to_string()))?;
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.map_err(|e| ApiError::JoinError(e.to_string()))??;
|
.map_err(|e| ApiError::JoinError(e.to_string()))??;
|
||||||
|
|
@ -100,10 +104,17 @@ impl ApiClient {
|
||||||
.map_err(|e| ApiError::RequestFailed(e.to_string()))?;
|
.map_err(|e| ApiError::RequestFailed(e.to_string()))?;
|
||||||
|
|
||||||
let status = response.status();
|
let status = response.status();
|
||||||
|
debug!("submit_metrics response: status={}", status);
|
||||||
|
|
||||||
if status != 200 {
|
if status != 200 {
|
||||||
return Err(ApiError::StatusError(status));
|
return Err(ApiError::StatusError(status));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let body = response
|
||||||
|
.into_string()
|
||||||
|
.map_err(|e| ApiError::RequestFailed(e.to_string()))?;
|
||||||
|
debug!("submit_metrics response body: {}", body);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
|
|
@ -125,10 +136,17 @@ impl ApiClient {
|
||||||
.map_err(|e| ApiError::RequestFailed(e.to_string()))?;
|
.map_err(|e| ApiError::RequestFailed(e.to_string()))?;
|
||||||
|
|
||||||
let status = response.status();
|
let status = response.status();
|
||||||
|
debug!("heartbeat response: status={}", status);
|
||||||
|
|
||||||
if status != 200 {
|
if status != 200 {
|
||||||
return Err(ApiError::StatusError(status));
|
return Err(ApiError::StatusError(status));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let body = response
|
||||||
|
.into_string()
|
||||||
|
.map_err(|e| ApiError::RequestFailed(e.to_string()))?;
|
||||||
|
debug!("heartbeat response body: {}", body);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@ use crate::secret::SecretString;
|
||||||
use snmp2::SyncSession;
|
use snmp2::SyncSession;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
// SNMP timeout in seconds - increased to 90s for SNMPv3 operations
|
// SNMP timeout in seconds - increased to 120s for SNMPv3 operations
|
||||||
// SNMPv3 has significant encryption/auth overhead, especially for large walks
|
// SNMPv3 has significant encryption/auth overhead, especially for large walks
|
||||||
// Full discovery can take 50+ seconds with complete MikroTik OID tree traversal
|
// Full discovery can take 50+ seconds with complete MikroTik OID tree traversal
|
||||||
const SNMP_TIMEOUT_SECS: u64 = 90;
|
const SNMP_TIMEOUT_SECS: u64 = 120;
|
||||||
|
|
||||||
/// SNMPv3 configuration bundle
|
/// SNMPv3 configuration bundle
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,10 @@ use std::str::FromStr;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::sync::{mpsc, oneshot};
|
use tokio::sync::{mpsc, oneshot};
|
||||||
|
|
||||||
// SNMP timeout in seconds - increased to 90s for SNMPv3 operations
|
// SNMP timeout in seconds - increased to 120s for SNMPv3 operations
|
||||||
// SNMPv3 has significant encryption/auth overhead
|
// SNMPv3 has significant encryption/auth overhead
|
||||||
// Full discovery can take 50+ seconds with complete MikroTik OID tree traversal
|
// Full discovery can take 50+ seconds with complete MikroTik OID tree traversal
|
||||||
const SNMP_TIMEOUT_SECS: u64 = 90;
|
const SNMP_TIMEOUT_SECS: u64 = 120;
|
||||||
|
|
||||||
/// Request to perform an SNMP operation
|
/// Request to perform an SNMP operation
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
||||||
|
|
@ -647,8 +647,9 @@ async fn execute_snmp_job(
|
||||||
|
|
||||||
// Build result
|
// Build result
|
||||||
let result = SnmpResult {
|
let result = SnmpResult {
|
||||||
device_id: job.device_id,
|
device_id: job.device_id.clone(),
|
||||||
job_type: job.job_type,
|
job_type: job.job_type,
|
||||||
|
job_id: job.job_id.clone(),
|
||||||
oid_values,
|
oid_values,
|
||||||
timestamp: std::time::SystemTime::now()
|
timestamp: std::time::SystemTime::now()
|
||||||
.duration_since(std::time::UNIX_EPOCH)?
|
.duration_since(std::time::UNIX_EPOCH)?
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue