added should_err endpoint config option

This commit is contained in:
Edward Shen 2019-05-01 22:36:14 -04:00
parent 18a95cb3cd
commit 57574993b6
Signed by: edward
GPG key ID: F350507060ED6C90
3 changed files with 20 additions and 8 deletions

View file

@ -8,6 +8,7 @@ pub struct EndpointConfig {
pub code: Option<u16>, pub code: Option<u16>,
pub body: Option<String>, pub body: Option<String>,
pub follow_redirects: Option<bool>, pub follow_redirects: Option<bool>,
pub should_err: Option<bool>,
} }
#[derive(Deserialize, Serialize, Debug, Clone)] #[derive(Deserialize, Serialize, Debug, Clone)]

View file

@ -33,7 +33,7 @@ pub type State = Arc<RwLock<QueryResults>>;
fn main() { fn main() {
System::run(move || { System::run(move || {
let config = from_str::<Config>( let config = from_str::<Config>(
&read_to_string("./endstat_conf.ron").expect("Could not find config file"), &read_to_string("./endstat_conf.ron").expect("finding ./endstat_conf.ron"),
) )
.unwrap(); .unwrap();
let bind_addr = config.bind_address.clone(); let bind_addr = config.bind_address.clone();

View file

@ -3,7 +3,7 @@ use crate::{
handlers::{EndpointStatus, StatusGroup}, handlers::{EndpointStatus, StatusGroup},
State, State,
}; };
use chrono::prelude::*; use chrono::prelude::Utc;
use reqwest::{Client, RedirectPolicy, Url, UrlError}; use reqwest::{Client, RedirectPolicy, Url, UrlError};
use std::time::Duration; use std::time::Duration;
@ -84,12 +84,23 @@ fn get_result(
error, error,
} }
} }
Err(e) => EndpointStatus { Err(e) => {
status: 2, if let Some(true) = endpoint.should_err {
location: url, EndpointStatus {
endpoint: label, status: 0,
error: Some(format!("{}", e)), location: url,
}, endpoint: label,
error: None,
}
} else {
EndpointStatus {
status: 2,
location: url,
endpoint: label,
error: Some(format!("{}", e)),
}
}
}
} }
} }