This commit is contained in:
Christoffer Martinsson 2025-10-13 10:23:42 +02:00
parent 42aaebf6a7
commit bb69f0f31b
2 changed files with 39 additions and 88 deletions

View File

@ -208,9 +208,9 @@ impl SystemCollector {
}
fn determine_cpu_status(&self, cpu_load_5: f32) -> String {
if cpu_load_5 >= 8.0 {
if cpu_load_5 >= 10.0 {
"critical".to_string()
} else if cpu_load_5 >= 5.0 {
} else if cpu_load_5 >= 9.0 {
"warning".to_string()
} else {
"ok".to_string()

View File

@ -208,15 +208,22 @@ impl App {
.filter_map(|host| {
self.host_states
.get(&host.name)
.map(|state| HostDisplayData {
name: host.name.clone(),
last_success: state.last_success.clone(),
last_error: state.last_error.clone(),
connection_status: state.connection_status.clone(),
smart: state.smart.clone(),
services: state.services.clone(),
system: state.system.clone(),
backup: state.backup.clone(),
.and_then(|state| {
// Only show hosts that have successfully connected at least once
if state.last_success.is_some() {
Some(HostDisplayData {
name: host.name.clone(),
last_success: state.last_success.clone(),
last_error: state.last_error.clone(),
connection_status: state.connection_status.clone(),
smart: state.smart.clone(),
services: state.services.clone(),
system: state.system.clone(),
backup: state.backup.clone(),
})
} else {
None
}
})
})
.collect()
@ -410,91 +417,35 @@ impl App {
}
}
fn select_hosts(host: Option<&String>, config: Option<&AppConfig>) -> Vec<HostTarget> {
fn select_hosts(host: Option<&String>, _config: Option<&AppConfig>) -> Vec<HostTarget> {
let mut targets = Vec::new();
// Known CMTEC infrastructure hosts for auto-discovery
let known_hosts = vec![
"cmbox", "labbox", "simonbox", "steambox", "srv01"
];
if let Some(filter) = host {
let normalized = filter.to_lowercase();
if let Some(config) = config {
if let Some(entry) = config.hosts.hosts.iter().find(|candidate| {
candidate.enabled && candidate.name.to_lowercase() == normalized
}) {
return vec![entry.clone()];
}
}
// If specific host requested, only connect to that one
return vec![HostTarget::from_name(filter.clone())];
}
let local_host = Self::local_hostname();
if let Some(config) = config {
if let Some(local) = local_host.as_ref() {
if let Some(entry) = config.hosts.hosts.iter().find(|candidate| {
candidate.enabled && candidate.name.eq_ignore_ascii_case(local)
}) {
targets.push(entry.clone());
} else {
targets.push(HostTarget::from_name(local.clone()));
}
}
for entry in &config.hosts.hosts {
if !entry.enabled {
continue;
}
if targets
.iter()
.any(|existing| existing.name.eq_ignore_ascii_case(&entry.name))
{
continue;
}
targets.push(entry.clone());
}
if targets.len() <= 1 {
if let Some(default_host) = &config.hosts.default_host {
if !targets
.iter()
.any(|existing| existing.name.eq_ignore_ascii_case(default_host))
{
if let Some(entry) = config.hosts.hosts.iter().find(|candidate| {
candidate.enabled && candidate.name.eq_ignore_ascii_case(default_host)
}) {
targets.push(entry.clone());
}
}
}
}
if targets.is_empty() {
if let Some(local) = local_host {
targets.push(HostTarget::from_name(local));
}
}
} else {
// No config file - use auto-discovery with known CMTEC hosts
let known_hosts = vec![
"cmbox", "labbox", "simonbox", "steambox", "srv01"
];
if let Some(local) = local_host.as_ref() {
targets.push(HostTarget::from_name(local.clone()));
}
// Add all known hosts for auto-discovery
for hostname in known_hosts {
if targets
.iter()
.any(|existing| existing.name.eq_ignore_ascii_case(hostname))
{
continue;
}
targets.push(HostTarget::from_name(hostname.to_string()));
// Always use auto-discovery - skip config files
if let Some(local) = local_host.as_ref() {
targets.push(HostTarget::from_name(local.clone()));
}
// Add all known hosts for auto-discovery
for hostname in known_hosts {
if targets
.iter()
.any(|existing| existing.name.eq_ignore_ascii_case(hostname))
{
continue;
}
targets.push(HostTarget::from_name(hostname.to_string()));
}
if targets.is_empty() {