Fix TUI
This commit is contained in:
parent
6275562f35
commit
2111453653
4 changed files with 25 additions and 17 deletions
|
|
@ -51,15 +51,20 @@ impl PollerRegistry {
|
||||||
|
|
||||||
/// Remove a device poller (shutdown thread)
|
/// Remove a device poller (shutdown thread)
|
||||||
/// Called when a device is deleted or no longer needs polling
|
/// Called when a device is deleted or no longer needs polling
|
||||||
pub fn remove(&self, device_id: &str) {
|
/// Returns the device IP if the poller was found
|
||||||
|
pub fn remove(&self, device_id: &str) -> Option<String> {
|
||||||
let mut pollers = self.pollers.write().unwrap();
|
let mut pollers = self.pollers.write().unwrap();
|
||||||
if let Some(poller) = pollers.remove(device_id) {
|
if let Some(poller) = pollers.remove(device_id) {
|
||||||
|
let ip = poller.config().ip.clone();
|
||||||
poller.shutdown();
|
poller.shutdown();
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
"Removed device poller for {} (remaining: {})",
|
"Removed device poller for {} (remaining: {})",
|
||||||
device_id,
|
device_id,
|
||||||
pollers.len()
|
pollers.len()
|
||||||
);
|
);
|
||||||
|
Some(ip)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -121,8 +126,9 @@ mod tests {
|
||||||
assert_eq!(poller.device_id(), "test-device");
|
assert_eq!(poller.device_id(), "test-device");
|
||||||
|
|
||||||
// Remove the poller
|
// Remove the poller
|
||||||
registry.remove("test-device");
|
let removed_ip = registry.remove("test-device");
|
||||||
assert_eq!(registry.count(), 0);
|
assert_eq!(registry.count(), 0);
|
||||||
|
assert_eq!(removed_ip, Some("127.0.0.1".to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
|
|
@ -30,11 +30,11 @@ pub enum AgentEvent {
|
||||||
sentence_count: usize,
|
sentence_count: usize,
|
||||||
},
|
},
|
||||||
PollerCreated {
|
PollerCreated {
|
||||||
device_id: String,
|
device_ip: String,
|
||||||
total_count: usize,
|
total_count: usize,
|
||||||
},
|
},
|
||||||
PollerRemoved {
|
PollerRemoved {
|
||||||
device_id: String,
|
device_ip: String,
|
||||||
total_count: usize,
|
total_count: usize,
|
||||||
},
|
},
|
||||||
HeartbeatSent,
|
HeartbeatSent,
|
||||||
|
|
|
||||||
|
|
@ -106,27 +106,27 @@ impl AgentState {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
AgentEvent::PollerCreated {
|
AgentEvent::PollerCreated {
|
||||||
device_id,
|
device_ip,
|
||||||
total_count,
|
total_count,
|
||||||
} => {
|
} => {
|
||||||
self.active_pollers = *total_count;
|
self.active_pollers = *total_count;
|
||||||
if !self.active_devices.contains(device_id) {
|
if !self.active_devices.contains(device_ip) {
|
||||||
self.active_devices.push(device_id.clone());
|
self.active_devices.push(device_ip.clone());
|
||||||
}
|
}
|
||||||
format!(
|
format!(
|
||||||
"Poller created for {} ({} total pollers)",
|
"Poller created for {} ({} total pollers)",
|
||||||
device_id, total_count
|
device_ip, total_count
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
AgentEvent::PollerRemoved {
|
AgentEvent::PollerRemoved {
|
||||||
device_id,
|
device_ip,
|
||||||
total_count,
|
total_count,
|
||||||
} => {
|
} => {
|
||||||
self.active_pollers = *total_count;
|
self.active_pollers = *total_count;
|
||||||
self.active_devices.retain(|d| d != device_id);
|
self.active_devices.retain(|d| d != device_ip);
|
||||||
format!(
|
format!(
|
||||||
"Poller removed for {} ({} total pollers)",
|
"Poller removed for {} ({} total pollers)",
|
||||||
device_id, total_count
|
device_ip, total_count
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
AgentEvent::HeartbeatSent => {
|
AgentEvent::HeartbeatSent => {
|
||||||
|
|
|
||||||
|
|
@ -471,14 +471,16 @@ impl AgentClient {
|
||||||
"Removing poller for device no longer in job list: {}",
|
"Removing poller for device no longer in job list: {}",
|
||||||
device_id
|
device_id
|
||||||
);
|
);
|
||||||
self.poller_registry.remove(&device_id);
|
let device_ip = self.poller_registry.remove(&device_id);
|
||||||
|
|
||||||
#[cfg(feature = "tui")]
|
#[cfg(feature = "tui")]
|
||||||
if let Some(ref bus) = self.event_bus {
|
if let Some(ref bus) = self.event_bus {
|
||||||
let _ = bus.send(crate::tui::AgentEvent::PollerRemoved {
|
if let Some(ip) = device_ip {
|
||||||
device_id: device_id.clone(),
|
let _ = bus.send(crate::tui::AgentEvent::PollerRemoved {
|
||||||
total_count: self.poller_registry.count(),
|
device_ip: ip,
|
||||||
});
|
total_count: self.poller_registry.count(),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -873,7 +875,7 @@ async fn execute_snmp_job(
|
||||||
if count_after > count_before {
|
if count_after > count_before {
|
||||||
if let Some(ref bus) = event_bus {
|
if let Some(ref bus) = event_bus {
|
||||||
let _ = bus.send(crate::tui::AgentEvent::PollerCreated {
|
let _ = bus.send(crate::tui::AgentEvent::PollerCreated {
|
||||||
device_id: job.device_id.clone(),
|
device_ip: snmp_device.ip.clone(),
|
||||||
total_count: count_after,
|
total_count: count_after,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue