diff options
author | metamuffin <metamuffin@disroot.org> | 2024-09-01 22:01:21 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-09-01 22:01:21 +0200 |
commit | 7e1614f35bfb0e5ee6ef75a260acac1fe57fee49 (patch) | |
tree | b4483c3dca6052f5ebdcb183084d29f9d9d7eede | |
parent | 243a9eabe185661fa7c35fec59482c215fc8dc4f (diff) | |
download | statuspage-7e1614f35bfb0e5ee6ef75a260acac1fe57fee49.tar statuspage-7e1614f35bfb0e5ee6ef75a260acac1fe57fee49.tar.bz2 statuspage-7e1614f35bfb0e5ee6ef75a260acac1fe57fee49.tar.zst |
systemd-global check
-rw-r--r-- | src/check.rs | 43 | ||||
-rw-r--r-- | src/web.rs | 13 |
2 files changed, 43 insertions, 13 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(), + } + } +} @@ -1,4 +1,4 @@ -use crate::{log::LOG, Check, Config, Service, Status, STATUS}; +use crate::{log::LOG, Config, Service, Status, STATUS}; use chrono::{SubsecRound, Utc}; use markup::{doctype, Render}; use std::{collections::BTreeMap, ops::Deref, sync::Arc}; @@ -99,14 +99,3 @@ markup::define!( } } ); - -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(), - } - } -} |