diff options
Diffstat (limited to 'src/check.rs')
-rw-r--r-- | src/check.rs | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/src/check.rs b/src/check.rs index cbcc839..a922055 100644 --- a/src/check.rs +++ b/src/check.rs @@ -11,9 +11,10 @@ use tokio::{ }; #[derive(Debug, Deserialize)] -#[serde(rename_all = "snake_case")] +#[serde(rename_all = "kebab-case")] pub enum Check { Systemd(String), + SystemdGlobal, Pacman(String), Http { title: Option<String>, @@ -102,6 +103,34 @@ impl Check { Ok(s) } } + 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::Shell { command, output, .. } => { @@ -145,3 +174,15 @@ impl Check { } } } + +impl Check { + pub fn display(&self) -> String { + match self { + Check::Systemd(_) => "Service".to_string(), + Check::Http { title, .. } => title.clone().unwrap_or("HTTP".to_string()), + Check::Shell { title, .. } => title.to_owned(), + Check::Pacman(_) => "Installed".to_string(), + Check::SystemdGlobal => "System Services".to_string(), + } + } +} |