towerops-agent/src/tui/events.rs
Graham McIntire cd45e9ff51
feat: add agent-side ICMP ping health monitoring
Implements health monitoring in the agent using ICMP ping, allowing
devices assigned to local (non-cloud) agents to be monitored.

Changes:
- Add surge-ping library for async ICMP ping operations
- Create ping.rs module with ping_device() function (5s timeout)
- Rename JobType::MONITOR to JobType::PING in protobuf
- Add monitoring_check channels for result communication
- Implement execute_ping_job() to handle PING jobs
- Update TUI to display ping result events

The agent now receives PING jobs from Phoenix, executes ICMP pings,
and sends MonitoringCheck results back for storage in the database.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-08 13:44:09 -06:00

72 lines
1.4 KiB
Rust

use tokio::sync::broadcast;
#[derive(Debug, Clone)]
pub enum AgentEvent {
Connected {
agent_id: String,
},
Disconnected,
JobReceived {
job_id: String,
device_id: String,
job_type: String,
},
JobCompleted {
job_id: String,
device_id: String,
duration_ms: u64,
},
JobFailed {
job_id: String,
device_id: String,
error: String,
},
SnmpResultSent {
device_id: String,
oid_count: usize,
},
MikrotikResultSent {
device_id: String,
sentence_count: usize,
},
MonitoringCheckSent {
device_id: String,
status: String,
},
PollerCreated {
device_ip: String,
total_count: usize,
},
PollerRemoved {
device_ip: String,
total_count: usize,
},
HeartbeatSent,
PhxHeartbeatSent,
Error {
message: String,
},
}
#[derive(Clone)]
pub struct EventBus {
tx: broadcast::Sender<AgentEvent>,
}
impl EventBus {
pub fn new(capacity: usize) -> Self {
let (tx, _) = broadcast::channel(capacity);
Self { tx }
}
pub fn subscribe(&self) -> broadcast::Receiver<AgentEvent> {
self.tx.subscribe()
}
pub fn send(
&self,
event: AgentEvent,
) -> Result<usize, broadcast::error::SendError<AgentEvent>> {
self.tx.send(event)
}
}