#[cfg(target_os = "linux")]
use bestool_tamanu::systemd;
use super::SweepContext;
use crate::doctor::check::Check;
const NAME: &str = "munin";
#[cfg(target_os = "linux")]
const UNIT: &str = "munin-node.service";
pub async fn run(_ctx: SweepContext) -> Check {
build(detect().await)
}
fn build(detected: bool) -> Check {
let summary = if detected {
"munin-node present"
} else {
"munin-node not installed"
};
Check::pass(NAME, summary).with_payload_extra("munin", detected)
}
#[cfg(target_os = "linux")]
async fn detect() -> bool {
if systemd::unit_file_exists(UNIT).await.unwrap_or(false) {
return true;
}
binary_on_path("munin-node")
}
#[cfg(not(target_os = "linux"))]
async fn detect() -> bool {
false
}
#[cfg(target_os = "linux")]
fn binary_on_path(name: &str) -> bool {
let Some(path) = std::env::var_os("PATH") else {
return false;
};
std::env::split_paths(&path).any(|dir| dir.join(name).is_file())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn reports_the_munin_bool_fact() {
for detected in [true, false] {
let check = build(detected);
assert_eq!(check.name, "munin");
assert_eq!(
check.payload_extras.get("munin").and_then(|v| v.as_bool()),
Some(detected)
);
}
}
}