diff options
Diffstat (limited to 'src/check.rs')
-rw-r--r-- | src/check.rs | 38 |
1 files changed, 12 insertions, 26 deletions
diff --git a/src/check.rs b/src/check.rs index a922055..42812c9 100644 --- a/src/check.rs +++ b/src/check.rs @@ -10,11 +10,18 @@ use tokio::{ time::{sleep, timeout}, }; +use crate::dbus::*; + #[derive(Debug, Deserialize)] #[serde(rename_all = "kebab-case")] pub enum Check { Systemd(String), SystemdGlobal, +// SystemdUser { +// user: String, +// name: String, +// }, + SystemdUserGlobal(String), Pacman(String), Http { title: Option<String>, @@ -104,32 +111,10 @@ impl Check { } } Check::SystemdGlobal => { - let output = Command::new("systemctl") - .arg("show") - .arg("--no-pager") - .output() - .await?; - let output = String::from_utf8(output.stdout).context("systemctl output")?; - - let mut nfailed = 0; - for line in output.split("\n") { - if let Some((key, value)) = line.split_once("=") { - match key { - "NFailedUnits" => { - nfailed = value.parse().context("systemctl nfailed output")? - } - _ => (), - } - } - } - if nfailed > 0 { - Err(anyhow!( - "{nfailed} unit{} failed", - if nfailed > 1 { "s" } else { "" } - )) - } else { - Ok("running".to_string()) - } + check_systemd_all(None).await + } + Check::SystemdUserGlobal(username) => { + check_systemd_all(Some(username)).await } Check::Shell { command, output, .. @@ -183,6 +168,7 @@ impl Check { Check::Shell { title, .. } => title.to_owned(), Check::Pacman(_) => "Installed".to_string(), Check::SystemdGlobal => "System Services".to_string(), + Check::SystemdUserGlobal(username) => format!("User services for {username}"), } } } |