diff --git a/config.toml b/config.toml index a5b5ce4..5fa91ec 100644 --- a/config.toml +++ b/config.toml @@ -5,27 +5,27 @@ command = "ping -c 1 -t 3 {{ host }}" # -t should be -w on linux environments. command = "curl --head --connect-timeout {{ host }}" -[[hosts]] +[[checks]] name = "Cloudflare/APNIC DNS (primary)" command = "ping" host = "1.1.1.1" -[[hosts]] +[[checks]] name = "Cloudflare/APNIC DNS (secondary)" command = "ping" host = "1.0.0.1" -[[hosts]] +[[checks]] name = "Google DNS (primary)" command = "ping" host = "8.8.8.8" -[[hosts]] +[[checks]] name = "Google DNS (secondary)" command = "ping" host = "8.8.4.4" -[[hosts]] +[[checks]] name = "Google.com" command = "curl" host = "http://www.google.com/" diff --git a/src/main.rs b/src/main.rs index 5fa67bd..158c4ff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,14 +24,14 @@ use subprocess::{Exec, NullFile}; #[derive(StructOpt)] #[structopt(name = "ips-uptime")] struct Opt { - #[structopt(parse(from_os_str))] + #[structopt(short = "c", long = "config", parse(from_os_str))] config: PathBuf, } #[derive(Debug, Deserialize)] struct Config { command: HashMap, - hosts: Vec, + checks: Vec, } #[derive(Debug, Deserialize)] @@ -40,7 +40,7 @@ struct Command { } #[derive(Debug, Deserialize)] -struct Host { +struct Check { name: String, command: String, #[serde(flatten)] @@ -49,7 +49,7 @@ struct Host { cmd: String, } -impl Host { +impl Check { fn status(&self) -> bool { let result = Exec::shell(&self.cmd) .stdout(NullFile) @@ -76,15 +76,15 @@ fn main() { handlebars.set_strict_mode(true); - for host in &mut config.hosts { + for check in &mut config.checks { let command = config .command - .get(&host.command) + .get(&check.command) .map(|command| &command.command) - .unwrap_or(&host.command); + .unwrap_or(&check.command); - host.cmd = handlebars - .render_template(command, &host.args) + check.cmd = handlebars + .render_template(command, &check.args) .expect("failed to register template"); } @@ -96,10 +96,9 @@ fn main() { let now = Local::now(); let result = config - .hosts + .checks .iter() - // .inspect(|host| println!("{}", host.name)) - .find(|host| host.status()); + .find(|check| check.status()); if result.is_some() { if let Some(down) = status { diff --git a/test.toml b/test.toml index c497be4..cc1aae7 100644 --- a/test.toml +++ b/test.toml @@ -2,7 +2,7 @@ command = "(( RANDOM % {{ range }} != 0 ))" -[[hosts]] +[[checks]] name = "Test (1/10)" command = "random" range = "10"