diff --git a/config/endstat_conf.example.ron b/config/endstat_conf.example.ron index c8e6210..42f8002 100644 --- a/config/endstat_conf.example.ron +++ b/config/endstat_conf.example.ron @@ -35,7 +35,8 @@ endpoints:[ (label: "The code doesn't match!", endpoint: "http://example.com/", code: 204), (label: "The body doesn't match!", endpoint: "http://example.com/", body: "asdf"), - (label: "Slow reponse time", endpoint: "http://slowwly.robertomurray.co.uk/delay/2000/url/"), + (label: "Slow reponse time", endpoint: "http://slowwly.robertomurray.co.uk/delay/2000/url/", max_rtt: 1337), + (label: "Plethora of issues!", endpoint: "http://slowwly.robertomurray.co.uk/delay/1000/url/", body: "asdf", code: 418, max_rtt: 50), (label: "Here's an error:", endpoint: "https://some-invalid-website.arpa") ] ), diff --git a/src/config.rs b/src/config.rs index b3c4df2..89621b8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -9,6 +9,7 @@ pub struct EndpointConfig { pub body: Option, pub body_hash: Option, pub follow_redirects: Option, + pub max_rtt: Option, pub should_err: Option, } diff --git a/src/updater.rs b/src/updater.rs index f5524a5..659074d 100644 --- a/src/updater.rs +++ b/src/updater.rs @@ -68,7 +68,7 @@ fn get_result( error = append_err_msg( error, format!( - "Status code mismatch: {} != {}.", + "Status code mismatch: {} != {}", res.status().as_u16(), code ), @@ -84,12 +84,17 @@ fn get_result( } else if !body.is_empty() && res_body != body { error = append_err_msg( error, - format!("Body mismatch: {} != {}.", res_body.len(), body.len()), + format!("Body mismatch: {} != {}", res_body.len(), body.len()), ); } - if rtt.num_seconds() >= 2 { - error = append_err_msg(error, format!("RTT too long: {}", rtt_string)); + if let Some(max_rtt) = endpoint.max_rtt { + if rtt.num_milliseconds() > max_rtt { + error = append_err_msg( + error, + format!("RTT too long: {} > {}s", rtt_string, max_rtt as f64 / 1000.), + ); + } } if error.is_some() { @@ -122,7 +127,7 @@ fn get_url(base: &Option, path: &String, port: Option) -> Result, to_append: String) -> Option { Some(match optional { - Some(e) => format!("{} {}", e, to_append), + Some(e) => format!("{}\n{}", e, to_append), None => to_append, }) }