fix live and scheduled polling

This commit is contained in:
Graham McIntire 2026-02-05 12:45:13 -06:00
parent d44682ce9c
commit 8c969401fb
No known key found for this signature in database
5 changed files with 29 additions and 9 deletions

View file

@ -162,6 +162,7 @@ message SnmpResult {
JobType job_type = 2;
map<string, string> oid_values = 3;
int64 timestamp = 4;
string job_id = 5;
}
message AgentHeartbeat {

View file

@ -2,9 +2,9 @@ use crate::config::{AgentConfig, HeartbeatMetadata};
use crate::metrics::Metric;
use crate::proto::agent;
use prost::Message;
use serde_json::json;
use std::time::Duration;
use thiserror::Error;
use tracing::debug;
#[derive(Debug, Error)]
pub enum ApiError {
@ -49,15 +49,19 @@ impl ApiClient {
.map_err(|e| ApiError::RequestFailed(e.to_string()))?;
let status = response.status();
debug!("fetch_config response: status={}", status);
if status != 200 {
return Err(ApiError::StatusError(status));
}
let config: AgentConfig = response
.into_json()
let body = response
.into_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
.map_err(|e| ApiError::JoinError(e.to_string()))??;
@ -100,10 +104,17 @@ impl ApiClient {
.map_err(|e| ApiError::RequestFailed(e.to_string()))?;
let status = response.status();
debug!("submit_metrics response: status={}", status);
if status != 200 {
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(())
})
.await
@ -125,10 +136,17 @@ impl ApiClient {
.map_err(|e| ApiError::RequestFailed(e.to_string()))?;
let status = response.status();
debug!("heartbeat response: status={}", status);
if status != 200 {
return Err(ApiError::StatusError(status));
}
let body = response
.into_string()
.map_err(|e| ApiError::RequestFailed(e.to_string()))?;
debug!("heartbeat response body: {}", body);
Ok(())
})
.await

View file

@ -3,10 +3,10 @@ use crate::secret::SecretString;
use snmp2::SyncSession;
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
// 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
#[derive(Clone)]

View file

@ -6,10 +6,10 @@ use std::str::FromStr;
use std::time::Duration;
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
// 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
#[derive(Debug)]

View file

@ -647,8 +647,9 @@ async fn execute_snmp_job(
// Build result
let result = SnmpResult {
device_id: job.device_id,
device_id: job.device_id.clone(),
job_type: job.job_type,
job_id: job.job_id.clone(),
oid_values,
timestamp: std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)?