The Ping plugin provides network host monitoring capabilities through ICMP ping commands. It can track multiple hosts simultaneously, generate events based on host availability, and provide detailed status information about monitored hosts.
pub struct HostMonitor {
name: String,
friendly_name: String,
ping_delay: Duration,
event_config: EventConfig,
monitor_thread: Option<JoinHandle<()>>,
status: Arc<Mutex<HostStatus>>,
}
impl HostMonitor {
pub fn start_monitoring(&mut self) -> Result<(), Error> {
// Initialize monitoring thread
// Configure ping parameters
// Start status checks
}
}
pub struct PingManager {
hosts: HashMap<String, HostMonitor>,
event_emitter: Arc<dyn EventEmitter>,
ping_config: PingConfig,
}
impl PingManager {
pub fn add_host(&mut self, config: HostConfig) -> Result<(), Error> {
// Create host monitor
// Configure events
// Start monitoring
}
}
pub struct EventHandler {
delay_config: DelayConfig,
event_queue: Arc<Mutex<VecDeque<HostEvent>>>,
}
impl EventHandler {
pub fn handle_status_change(&mut self, status: HostStatus) -> Result<(), Error> {
// Process status change
// Apply event delays
// Generate events
}
}
- Host Monitoring - Multiple host tracking - Configurable ping delays - Status change detection - Friendly name support - Host status queries
- Event System - Host alive events - Host dead events - Delayed event triggering - Custom event names - Status change notifications
- Configuration Options - Ping parameters - Event delays - Host properties - Monitor settings - Status reporting
- Management Functions - Add hosts - Remove hosts - One-time pings - Status queries - Host configuration
- Network Integration - ICMP implementation - Thread management - Status tracking - Event coordination
- Platform Support - Windows API usage - Command execution - Process handling - Resource management
Host Management .. code-block:: rust
- impl PingPlugin {
- pub fn monitor_host(&mut self, config: HostConfig) -> Result<(), Error> {
- let monitor = HostMonitor::new(
config.name, config.friendly_name, config.ping_delay,
);
monitor.set_event_config(config.events)?; monitor.start_monitoring()?;
self.hosts.insert(config.name.clone(), monitor); Ok(())
}
- pub fn remove_host(&mut self, name: &str) -> Result<(), Error> {
- if let Some(monitor) = self.hosts.remove(name) {
monitor.stop_monitoring()?; monitor.wait_for_completion()?;
} Ok(())
}
}
Status Monitoring .. code-block:: rust
- impl HostMonitor {
- pub fn check_status(&mut self) -> Result<HostStatus, Error> {
- let output = Command::new("ping")
.arg(&self.name) .arg("-n") .arg("1") .arg("-w") .arg(self.ping_delay.as_millis().to_string()) .output()?;
self.process_ping_result(output)
}
- pub fn process_status_change(&mut self, status: HostStatus) -> Result<(), Error> {
- match status {
HostStatus::Alive => self.handle_alive_status()?, HostStatus::Dead => self.handle_dead_status()?,
}
self.notify_status_change(status)
}
}
- Unit Tests - Ping execution - Status processing - Event generation - Configuration validation
- Integration Tests - Host monitoring - Event handling - Thread management - Resource cleanup
- Performance Tests - Multiple hosts - Network latency - Resource usage - Event throughput
- Network Errors - Ping failures - Host unreachable - Timeout handling - Command errors
- Thread Management - Start/stop errors - Resource cleanup - State transitions - Deadlock prevention
- Event Processing - Event queuing - Delay handling - Status tracking - Resource cleanup
- Windows Integration - ICMP implementation - Command execution - Process handling - Security context
- Resource Management - Thread pools - Process limits - Memory usage - Network resources