aboutsummaryrefslogtreecommitdiff
path: root/src/check.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/check.rs')
-rw-r--r--src/check.rs38
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, .. } => {