diff --git a/Cargo.lock b/Cargo.lock index 1d3a91a..98a33c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -279,7 +279,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" [[package]] name = "cm-dashboard" -version = "0.1.231" +version = "0.1.232" dependencies = [ "anyhow", "chrono", @@ -301,7 +301,7 @@ dependencies = [ [[package]] name = "cm-dashboard-agent" -version = "0.1.231" +version = "0.1.232" dependencies = [ "anyhow", "async-trait", @@ -325,7 +325,7 @@ dependencies = [ [[package]] name = "cm-dashboard-shared" -version = "0.1.231" +version = "0.1.232" dependencies = [ "chrono", "serde", diff --git a/agent/Cargo.toml b/agent/Cargo.toml index 8173adb..9c4988e 100644 --- a/agent/Cargo.toml +++ b/agent/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-agent" -version = "0.1.231" +version = "0.1.232" edition = "2021" [dependencies] diff --git a/agent/src/collectors/systemd.rs b/agent/src/collectors/systemd.rs index 6b7571f..af9ee5c 100644 --- a/agent/src/collectors/systemd.rs +++ b/agent/src/collectors/systemd.rs @@ -159,6 +159,19 @@ impl SystemdCollector { } } + if service_name.contains("openvpn-vpn-connection") && status_info.active_state == "active" { + if let Some(external_ip) = self.get_vpn_external_ip() { + let metrics = Vec::new(); + + sub_services.push(SubServiceData { + name: format!("IP: {}", external_ip), + service_status: Status::Ok, + metrics, + service_type: "vpn_route".to_string(), + }); + } + } + // Create complete service data let service_data = ServiceData { name: service_name.clone(), @@ -836,6 +849,36 @@ impl SystemdCollector { _ => value, // Assume bytes if no unit } } + + /// Get VPN external IP by querying through the openvpn-namespace + fn get_vpn_external_ip(&self) -> Option { + let output = Command::new("timeout") + .args(&[ + "5", + "ip", + "netns", + "exec", + "openvpn-namespace", + "curl", + "-s", + "--max-time", + "4", + "https://ifconfig.me" + ]) + .output() + .ok()?; + + if output.status.success() { + let ip = String::from_utf8_lossy(&output.stdout).trim().to_string(); + if !ip.is_empty() && ip.contains('.') { + debug!("VPN external IP: {}", ip); + return Some(ip); + } + } + + debug!("Failed to get VPN external IP"); + None + } } #[async_trait] diff --git a/dashboard/Cargo.toml b/dashboard/Cargo.toml index 97f4c9f..1fa155d 100644 --- a/dashboard/Cargo.toml +++ b/dashboard/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard" -version = "0.1.231" +version = "0.1.232" edition = "2021" [dependencies] diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 9e0da4b..65bc62f 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-shared" -version = "0.1.231" +version = "0.1.232" edition = "2021" [dependencies]