Clean up unused imports and fix build warnings

- Remove unused imports (Duration, HashMap, SharedError, DateTime, etc.)
- Fix unused variables by prefixing with underscore
- Remove redundant dashboard.toml config file
- Update theme imports to use only needed components
- Maintain all functionality while reducing warnings
- Add srv02 to predefined hosts configuration
- Remove unused broadcast_command methods
This commit is contained in:
2025-10-18 23:12:07 +02:00
parent f0eec38655
commit 7f85a6436e
21 changed files with 27 additions and 150 deletions

View File

@@ -2,7 +2,6 @@ use anyhow::Result;
use cm_dashboard_shared::{MetricMessage, MessageEnvelope, MessageType};
use tracing::{info, error, debug, warn};
use zmq::{Context, Socket, SocketType};
use std::time::Duration;
use crate::config::ZmqConfig;
@@ -80,11 +79,6 @@ impl ZmqConsumer {
Ok(())
}
/// Get list of newly connected hosts since last check
pub fn get_newly_connected_hosts(&self) -> Vec<String> {
// For now, return all connected hosts (could be enhanced with state tracking)
self.connected_hosts.iter().cloned().collect()
}
/// Receive metrics from any connected agent (non-blocking)
pub async fn receive_metrics(&mut self) -> Result<Option<MetricMessage>> {
@@ -128,32 +122,21 @@ impl ZmqConsumer {
}
}
/// Get list of connected hosts
pub fn get_connected_hosts(&self) -> Vec<String> {
self.connected_hosts.iter().cloned().collect()
}
/// Check if connected to any hosts
pub fn has_connections(&self) -> bool {
!self.connected_hosts.is_empty()
}
}
/// ZMQ command sender for sending commands to agents
pub struct ZmqCommandSender {
context: Context,
config: ZmqConfig,
}
impl ZmqCommandSender {
pub fn new(config: &ZmqConfig) -> Result<Self> {
pub fn new(_config: &ZmqConfig) -> Result<Self> {
let context = Context::new();
info!("ZMQ command sender initialized");
Ok(Self {
context,
config: config.clone(),
})
}
@@ -181,24 +164,4 @@ impl ZmqCommandSender {
// Socket will be automatically closed when dropped
Ok(())
}
/// Send a command to all connected hosts
pub async fn broadcast_command(&self, hosts: &[String], command: AgentCommand) -> Result<Vec<String>> {
let mut failed_hosts = Vec::new();
for hostname in hosts {
if let Err(e) = self.send_command(hostname, command.clone()).await {
error!("Failed to send command to {}: {}", hostname, e);
failed_hosts.push(hostname.clone());
}
}
if failed_hosts.is_empty() {
info!("Successfully broadcast command {:?} to {} hosts", command, hosts.len());
} else {
warn!("Failed to send command to {} hosts: {:?}", failed_hosts.len(), failed_hosts);
}
Ok(failed_hosts)
}
}