aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/check.rs43
-rw-r--r--src/web.rs13
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(),
+ }
+ }
+}
diff --git a/src/web.rs b/src/web.rs
index 001585a..f9bed5e 100644
--- a/src/web.rs
+++ b/src/web.rs
@@ -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(),
- }
- }
-}