Compare commits

...

3 Commits

Author SHA1 Message Date
Edward Shen 5aa57864d7
templates now generate relative to cwd
added more examples to conf
2019-05-01 23:47:05 -04:00
Edward Shen 25ed4f0acb
made helper functions for EndpointStatus 2019-05-01 22:47:11 -04:00
Edward Shen 57574993b6
added should_err endpoint config option 2019-05-01 22:36:14 -04:00
6 changed files with 48 additions and 17 deletions

View File

@ -24,8 +24,9 @@
label: "Even more stuff!",
endpoints: [
(label: "Or expect different reponse codes (like 418)", endpoint: "http://error418.net/", code: 418),
(label: "Or bodies!", endpoint: "http://urlecho.appspot.com/echo", body: "None"),
(label: "Or response checking!", endpoint: "http://urlecho.appspot.com/echo", body: "None"),
(label: "Or both!", endpoint: "http://urlecho.appspot.com/echo?status=503&Content-Type=text%2Fhtml&body=None", body: "None", code: 503),
(label: "Or expect the endpoint to fail entirely!", endpoint: "http://lol.arpa", should_err: true),
],
),
(
@ -33,7 +34,7 @@
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: "Here's an error", endpoint: "https://some-invalid-website.arpa")
(label: "Here's an error:", endpoint: "https://some-invalid-website.arpa")
]
),
]

View File

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

View File

@ -15,6 +15,35 @@ pub struct EndpointStatus {
pub error: Option<String>,
}
impl EndpointStatus {
pub fn ok(location: String, endpoint: String) -> Self {
EndpointStatus {
status: 0,
location,
endpoint,
error: None,
}
}
pub fn warn(location: String, endpoint: String, error: Option<String>) -> Self {
EndpointStatus {
status: 1,
location,
endpoint,
error,
}
}
pub fn error(location: String, endpoint: String, error: Option<String>) -> Self {
EndpointStatus {
status: 2,
location,
endpoint,
error,
}
}
}
#[derive(Serialize, Debug)]
pub struct StatusGroup {
pub label: String,

View File

@ -33,7 +33,7 @@ pub type State = Arc<RwLock<QueryResults>>;
fn main() {
System::run(move || {
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();
let bind_addr = config.bind_address.clone();
@ -51,7 +51,7 @@ fn main() {
let clone_state = Arc::clone(&state);
HttpServer::new(move || {
let tera = compile_templates!(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/**/*"));
let tera = compile_templates!("./templates/**/*");
let state = Arc::clone(&state);
App::new()

View File

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

View File

@ -3,7 +3,7 @@
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Endstat</title>
<title>endstat</title>
<link href="https://fonts.googleapis.com/css?family=Montserrat:200|Source+Code+Pro:400" rel="stylesheet">
<style>
body {