Compare commits

...

3 commits

Author SHA1 Message Date
5aa57864d7
templates now generate relative to cwd
added more examples to conf
2019-05-01 23:47:05 -04:00
25ed4f0acb
made helper functions for EndpointStatus 2019-05-01 22:47:11 -04:00
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!", label: "Even more stuff!",
endpoints: [ endpoints: [
(label: "Or expect different reponse codes (like 418)", endpoint: "http://error418.net/", code: 418), (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 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:[ endpoints:[
(label: "The code doesn't match!", endpoint: "http://example.com/", code: 204), (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: "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 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

@ -15,6 +15,35 @@ pub struct EndpointStatus {
pub error: Option<String>, 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)] #[derive(Serialize, Debug)]
pub struct StatusGroup { pub struct StatusGroup {
pub label: String, pub label: String,

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();
@ -51,7 +51,7 @@ fn main() {
let clone_state = Arc::clone(&state); let clone_state = Arc::clone(&state);
HttpServer::new(move || { HttpServer::new(move || {
let tera = compile_templates!(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/**/*")); let tera = compile_templates!("./templates/**/*");
let state = Arc::clone(&state); let state = Arc::clone(&state);
App::new() App::new()

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;
@ -77,19 +77,19 @@ fn get_result(
}); });
} }
EndpointStatus { if error.is_some() {
status: if error.is_some() { 1 } else { 0 }, EndpointStatus::warn(url, label, error)
location: url, } else {
endpoint: label, EndpointStatus::ok(url, label)
error, }
}
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"> <html lang="en">
<head> <head>
<meta charset="utf-8"/> <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"> <link href="https://fonts.googleapis.com/css?family=Montserrat:200|Source+Code+Pro:400" rel="stylesheet">
<style> <style>
body { body {