Testing
This commit is contained in:
@@ -449,7 +449,7 @@ impl ServiceCollector {
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_service_description_throttled(&self, service: &str) -> Option<String> {
|
||||
async fn get_service_description_throttled(&self, service: &str) -> Option<Vec<String>> {
|
||||
// Simple time-based throttling - only run expensive descriptions every ~30 seconds
|
||||
// Use a hash of the current time to spread out when different services get described
|
||||
let now = std::time::SystemTime::now()
|
||||
@@ -472,14 +472,14 @@ impl ServiceCollector {
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_service_description(&self, service: &str) -> Option<String> {
|
||||
async fn get_service_description(&self, service: &str) -> Option<Vec<String>> {
|
||||
match service {
|
||||
"sshd" | "ssh" => self.get_ssh_active_users().await,
|
||||
"nginx" => self.get_web_server_connections().await, // Use same method for now
|
||||
"apache2" | "httpd" => self.get_web_server_connections().await,
|
||||
"docker" => self.get_docker_containers().await,
|
||||
"postgresql" | "postgres" => self.get_postgres_connections().await,
|
||||
"mysql" | "mariadb" => self.get_mysql_connections().await,
|
||||
"sshd" | "ssh" => self.get_ssh_active_users().await.map(|s| vec![s]),
|
||||
"nginx" => self.get_nginx_sites().await,
|
||||
"apache2" | "httpd" => self.get_web_server_connections().await.map(|s| vec![s]),
|
||||
"docker" => self.get_docker_containers().await.map(|s| vec![s]),
|
||||
"postgresql" | "postgres" => self.get_postgres_connections().await.map(|s| vec![s]),
|
||||
"mysql" | "mariadb" => self.get_mysql_connections().await.map(|s| vec![s]),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -620,6 +620,79 @@ impl ServiceCollector {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_nginx_sites(&self) -> Option<Vec<String>> {
|
||||
// Check enabled sites in sites-enabled directory
|
||||
let sites_enabled_dir = "/etc/nginx/sites-enabled";
|
||||
|
||||
let mut entries = match fs::read_dir(sites_enabled_dir).await {
|
||||
Ok(entries) => entries,
|
||||
Err(_) => return None,
|
||||
};
|
||||
|
||||
let mut sites = Vec::new();
|
||||
|
||||
while let Ok(Some(entry)) = entries.next_entry().await {
|
||||
let path = entry.path();
|
||||
|
||||
// Skip if it's not a file or is a symlink to default
|
||||
if !path.is_file() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let filename = path.file_name()?.to_string_lossy();
|
||||
|
||||
// Skip default site unless it's the only one
|
||||
if filename == "default" {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Try to extract server names from the config file
|
||||
if let Ok(config_content) = fs::read_to_string(&path).await {
|
||||
let mut server_names = Vec::new();
|
||||
|
||||
for line in config_content.lines() {
|
||||
let trimmed = line.trim();
|
||||
if trimmed.starts_with("server_name") {
|
||||
// Extract server names from "server_name example.com www.example.com;"
|
||||
if let Some(names_part) = trimmed.strip_prefix("server_name") {
|
||||
let names_clean = names_part.trim().trim_end_matches(';');
|
||||
for name in names_clean.split_whitespace() {
|
||||
if name != "_" && !name.is_empty() {
|
||||
server_names.push(name.to_string());
|
||||
break; // Only take the first valid server name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !server_names.is_empty() {
|
||||
sites.push(server_names[0].clone());
|
||||
} else {
|
||||
// Fallback to filename if no server_name found
|
||||
sites.push(filename.to_string());
|
||||
}
|
||||
} else {
|
||||
// Fallback to filename if can't read config
|
||||
sites.push(filename.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
// If no sites found, check for default
|
||||
if sites.is_empty() {
|
||||
let default_path = format!("{}/default", sites_enabled_dir);
|
||||
if fs::metadata(&default_path).await.is_ok() {
|
||||
sites.push("default".to_string());
|
||||
}
|
||||
}
|
||||
|
||||
if sites.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(sites)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -755,7 +828,7 @@ struct ServiceData {
|
||||
sandbox_limit: Option<f32>,
|
||||
disk_used_gb: f32,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
description: Option<String>,
|
||||
description: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
|
||||
Reference in New Issue
Block a user