diff options
author | metamuffin <metamuffin@disroot.org> | 2024-05-24 14:12:16 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-05-24 14:12:16 +0200 |
commit | 4c9c8de0c9f1f03f44ae60c088f506c1e4a51d26 (patch) | |
tree | 7842f99be53a073daa3ea6ec29cfb85570ffb816 /src/check.rs | |
parent | 7f33cca687bd63947570a56f2026066f5936c2e9 (diff) | |
download | statuspage-4c9c8de0c9f1f03f44ae60c088f506c1e4a51d26.tar statuspage-4c9c8de0c9f1f03f44ae60c088f506c1e4a51d26.tar.bz2 statuspage-4c9c8de0c9f1f03f44ae60c088f506c1e4a51d26.tar.zst |
option to show shell command output
Diffstat (limited to 'src/check.rs')
-rw-r--r-- | src/check.rs | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/src/check.rs b/src/check.rs index a979e96..cbcc839 100644 --- a/src/check.rs +++ b/src/check.rs @@ -15,8 +15,16 @@ use tokio::{ pub enum Check { Systemd(String), Pacman(String), - Http { title: Option<String>, url: String }, - Shell { title: String, command: String }, + Http { + title: Option<String>, + url: String, + }, + Shell { + title: String, + command: String, + #[serde(default)] + output: bool, + }, } pub async fn check_loop(config: Arc<Config>, i: usize) { @@ -94,17 +102,31 @@ impl Check { Ok(s) } } - Check::Shell { command, .. } => { + Check::Shell { + command, output, .. + } => { let args = shlex::split(&command).ok_or(anyhow!("command syntax invalid"))?; let status = Command::new(args.get(0).ok_or(anyhow!("argv0 missing"))?) .args(&args[1..]) - .status() + .output() .await; - match status { - Ok(status) if status.success() => Ok(Default::default()), - Ok(status) => bail!("failed with code {}", status.code().unwrap_or(1)), - Err(e) => bail!("command failed to execute: {e}"), + if *output { + match status { + Ok(status) if status.status.success() => { + Ok(String::from_utf8_lossy(&status.stdout).to_string()) + } + Ok(status) => bail!("{}", String::from_utf8_lossy(&status.stdout)), + Err(e) => bail!("command failed to execute: {e}"), + } + } else { + match status { + Ok(status) if status.status.success() => Ok(Default::default()), + Ok(status) => { + bail!("failed with code {}", status.status.code().unwrap_or(1)) + } + Err(e) => bail!("command failed to execute: {e}"), + } } } Check::Http { url, .. } => { |