Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dcd350ec2c | |||
| a34b095857 |
6
Cargo.lock
generated
6
Cargo.lock
generated
@@ -279,7 +279,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
|
||||
|
||||
[[package]]
|
||||
name = "cm-dashboard"
|
||||
version = "0.1.271"
|
||||
version = "0.1.273"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
@@ -301,7 +301,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cm-dashboard-agent"
|
||||
version = "0.1.271"
|
||||
version = "0.1.273"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
@@ -325,7 +325,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cm-dashboard-shared"
|
||||
version = "0.1.271"
|
||||
version = "0.1.273"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"serde",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cm-dashboard-agent"
|
||||
version = "0.1.272"
|
||||
version = "0.1.274"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -233,23 +233,22 @@ impl SystemdCollector {
|
||||
if service_name == "nfs-server" && status_info.active_state == "active" {
|
||||
// Add NFS exports as sub-services
|
||||
let exports = self.get_nfs_exports();
|
||||
for (export_path, options) in exports {
|
||||
let metrics = Vec::new();
|
||||
let display = if !options.is_empty() {
|
||||
format!("{} ({})", export_path, options)
|
||||
for (export_path, info) in exports {
|
||||
let display = if !info.is_empty() {
|
||||
format!("{} {}", export_path, info)
|
||||
} else {
|
||||
export_path
|
||||
};
|
||||
sub_services.push(SubServiceData {
|
||||
name: display,
|
||||
service_status: Status::Info,
|
||||
metrics,
|
||||
metrics: Vec::new(),
|
||||
service_type: "nfs_export".to_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if service_name == "smbd" && status_info.active_state == "active" {
|
||||
if (service_name == "smbd" || service_name == "samba-smbd") && status_info.active_state == "active" {
|
||||
// Add SMB shares as sub-services
|
||||
let shares = self.get_smb_shares();
|
||||
for (share_name, share_path) in shares {
|
||||
@@ -1045,62 +1044,72 @@ impl SystemdCollector {
|
||||
}
|
||||
|
||||
/// Get NFS exports from exportfs
|
||||
/// Returns a list of (export_path, options) tuples
|
||||
/// Returns a list of (export_path, info_string) tuples
|
||||
fn get_nfs_exports(&self) -> Vec<(String, String)> {
|
||||
match Command::new("timeout")
|
||||
let output = match Command::new("timeout")
|
||||
.args(["2", "exportfs", "-v"])
|
||||
.output()
|
||||
{
|
||||
Ok(output) if output.status.success() => {
|
||||
let exports_output = String::from_utf8_lossy(&output.stdout);
|
||||
let mut exports_map: std::collections::HashMap<String, String> = std::collections::HashMap::new();
|
||||
|
||||
for line in exports_output.lines() {
|
||||
let line = line.trim();
|
||||
if line.is_empty() || line.starts_with('#') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Format: "/path/to/export hostname(options)" or "/path/to/export 192.168.1.0/24(options)"
|
||||
// exportfs -v shows each export once per client/network
|
||||
// We want to deduplicate by path and just show one entry
|
||||
let parts: Vec<&str> = line.split_whitespace().collect();
|
||||
if parts.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let export_path = parts[0].to_string();
|
||||
|
||||
// Extract options from parentheses (from the client specification)
|
||||
let options = if parts.len() > 1 {
|
||||
let client_spec = parts[1];
|
||||
if let Some(start) = client_spec.find('(') {
|
||||
if let Some(end) = client_spec.find(')') {
|
||||
client_spec[start+1..end].to_string()
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
} else {
|
||||
String::new()
|
||||
Ok(output) if output.status.success() => output,
|
||||
_ => return Vec::new(),
|
||||
};
|
||||
|
||||
// Only store the first occurrence of each path (deduplicates multiple clients)
|
||||
exports_map.entry(export_path).or_insert(options);
|
||||
let exports_output = String::from_utf8_lossy(&output.stdout);
|
||||
let mut exports_map: std::collections::HashMap<String, Vec<(String, String)>> =
|
||||
std::collections::HashMap::new();
|
||||
let mut current_path: Option<String> = None;
|
||||
|
||||
for line in exports_output.lines() {
|
||||
let trimmed = line.trim();
|
||||
|
||||
if trimmed.is_empty() || trimmed.starts_with('#') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Convert HashMap to Vec
|
||||
let mut exports: Vec<(String, String)> = exports_map.into_iter().collect();
|
||||
// Sort by path for consistent display
|
||||
if trimmed.starts_with('/') {
|
||||
// New export path line
|
||||
current_path = trimmed.split_whitespace().next().map(|s| s.to_string());
|
||||
} else if let Some(ref path) = current_path {
|
||||
// Continuation line with network and options
|
||||
// Format: "192.168.0.0/16(options...)"
|
||||
if let Some(paren_pos) = trimmed.find('(') {
|
||||
let network = trimmed[..paren_pos].trim();
|
||||
|
||||
// Extract ro/rw from options
|
||||
if let Some(end_paren) = trimmed.find(')') {
|
||||
let options = &trimmed[paren_pos+1..end_paren];
|
||||
let mode = if options.contains(",rw,") || options.ends_with(",rw") {
|
||||
"rw"
|
||||
} else {
|
||||
"ro"
|
||||
};
|
||||
|
||||
exports_map.entry(path.clone())
|
||||
.or_insert_with(Vec::new)
|
||||
.push((network.to_string(), mode.to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Build display strings: "path: mode [networks]"
|
||||
let mut exports: Vec<(String, String)> = exports_map
|
||||
.into_iter()
|
||||
.map(|(path, mut entries)| {
|
||||
if entries.is_empty() {
|
||||
return (path, String::new());
|
||||
}
|
||||
|
||||
let mode = entries[0].1.clone();
|
||||
let networks: Vec<String> = entries.drain(..).map(|(n, _)| n).collect();
|
||||
let info = format!("{} [{}]", mode, networks.join(", "));
|
||||
(path, info)
|
||||
})
|
||||
.collect();
|
||||
|
||||
exports.sort_by(|a, b| a.0.cmp(&b.0));
|
||||
|
||||
exports
|
||||
}
|
||||
_ => Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get SMB shares from smb.conf
|
||||
/// Returns a list of (share_name, share_path) tuples
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cm-dashboard"
|
||||
version = "0.1.272"
|
||||
version = "0.1.274"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cm-dashboard-shared"
|
||||
version = "0.1.272"
|
||||
version = "0.1.274"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
Reference in New Issue
Block a user