Update dependencies
This commit is contained in:
2181
Cargo.lock
generated
2181
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
25
Cargo.toml
25
Cargo.toml
@ -19,24 +19,7 @@ duplicate = "0.2"
|
|||||||
handlebars = "3"
|
handlebars = "3"
|
||||||
http = "0.2"
|
http = "0.2"
|
||||||
ron = "0.6.4"
|
ron = "0.6.4"
|
||||||
|
rocket = { version = "0.5", features = ["secrets"] }
|
||||||
[dependencies.rocket]
|
rocket_dyn_templates = { version = "0.1.0", features = ["handlebars"] }
|
||||||
#version = "0.4"
|
tokio = { version = "1", features = ["fs"] }
|
||||||
git = "https://github.com/SergioBenitez/Rocket"
|
reqwest = { version = "0.11", default-features = false, features = ["rustls-tls"] }
|
||||||
branch = "master"
|
|
||||||
features = ["secrets"]
|
|
||||||
|
|
||||||
[dependencies.rocket_contrib]
|
|
||||||
#version = "0.4"
|
|
||||||
git = "https://github.com/SergioBenitez/Rocket"
|
|
||||||
branch = "master"
|
|
||||||
features = ["handlebars_templates", "uuid"]
|
|
||||||
|
|
||||||
[dependencies.tokio]
|
|
||||||
version = "1"
|
|
||||||
features = ["fs"]
|
|
||||||
|
|
||||||
[dependencies.reqwest]
|
|
||||||
version = "0.11"
|
|
||||||
default-features = false
|
|
||||||
features = ["rustls-tls"]
|
|
||||||
|
|||||||
@ -69,8 +69,8 @@ impl HealthState {
|
|||||||
last_update: Mutex::new(None),
|
last_update: Mutex::new(None),
|
||||||
health: config
|
health: config
|
||||||
.services
|
.services
|
||||||
.iter()
|
.keys()
|
||||||
.map(|(id, _config)| (id.clone(), Mutex::new(None)))
|
.map(|id| (id.clone(), Mutex::new(None)))
|
||||||
.collect(),
|
.collect(),
|
||||||
config,
|
config,
|
||||||
}
|
}
|
||||||
@ -109,7 +109,7 @@ impl HttpHealthCheckMode {
|
|||||||
.map_err(|e| error!("invalid status code: {}", e))
|
.map_err(|e| error!("invalid status code: {}", e))
|
||||||
.ok()
|
.ok()
|
||||||
.filter(|status| status == &actual)
|
.filter(|status| status == &actual)
|
||||||
.and_then(|_| if_valid),
|
.and(if_valid),
|
||||||
PartialStatusCode::Status5XX if actual.is_server_error() => if_valid,
|
PartialStatusCode::Status5XX if actual.is_server_error() => if_valid,
|
||||||
PartialStatusCode::Status4XX if actual.is_server_error() => if_valid,
|
PartialStatusCode::Status4XX if actual.is_server_error() => if_valid,
|
||||||
PartialStatusCode::Status3XX if actual.is_redirection() => if_valid,
|
PartialStatusCode::Status3XX if actual.is_redirection() => if_valid,
|
||||||
@ -123,13 +123,13 @@ impl HttpHealthCheckMode {
|
|||||||
let check_up = self
|
let check_up = self
|
||||||
.up_status_codes
|
.up_status_codes
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|up_code| validate_status(&up_code, response_status, HealthStatus::Up));
|
.flat_map(|up_code| validate_status(up_code, response_status, HealthStatus::Up));
|
||||||
|
|
||||||
// Check if response status matches expected status codes for Down
|
// Check if response status matches expected status codes for Down
|
||||||
let check_down = self
|
let check_down = self
|
||||||
.down_status_codes
|
.down_status_codes
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|down_code| validate_status(&down_code, response_status, HealthStatus::Down));
|
.flat_map(|down_code| validate_status(down_code, response_status, HealthStatus::Down));
|
||||||
|
|
||||||
// Compute status, defaulting to Errored if neigher Up nor Down matched
|
// Compute status, defaulting to Errored if neigher Up nor Down matched
|
||||||
check_up
|
check_up
|
||||||
|
|||||||
12
src/main.rs
12
src/main.rs
@ -3,8 +3,8 @@ mod routes;
|
|||||||
|
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
use health::HealthState;
|
use health::HealthState;
|
||||||
use rocket_contrib::serve::StaticFiles;
|
use rocket::fs::FileServer;
|
||||||
use rocket_contrib::templates::Template;
|
use rocket_dyn_templates::Template;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::{env, io};
|
use std::{env, io};
|
||||||
@ -31,15 +31,11 @@ async fn main() -> io::Result<()> {
|
|||||||
let config = ron::from_str(&config).expect("failed to parse config file");
|
let config = ron::from_str(&config).expect("failed to parse config file");
|
||||||
let state = Arc::new(HealthState::new(config));
|
let state = Arc::new(HealthState::new(config));
|
||||||
|
|
||||||
let rocket = rocket::ignite()
|
let rocket = rocket::build()
|
||||||
//.attach(Template::custom(|engines| {
|
|
||||||
//handlebars_util::register_helpers(engines)
|
|
||||||
//}))
|
|
||||||
.attach(Template::fairing())
|
.attach(Template::fairing())
|
||||||
.manage(Arc::clone(&state))
|
.manage(Arc::clone(&state))
|
||||||
.mount("/static", StaticFiles::from("static"))
|
.mount("/static", FileServer::from("static"))
|
||||||
.mount("/", rocket::routes![routes::pages::dashboard]);
|
.mount("/", rocket::routes![routes::pages::dashboard]);
|
||||||
//.register(rocket::catchers![auth::login_page,]);
|
|
||||||
|
|
||||||
start_poller(state);
|
start_poller(state);
|
||||||
|
|
||||||
|
|||||||
@ -2,12 +2,12 @@ use crate::health::HealthState;
|
|||||||
use crate::health::HealthStatus;
|
use crate::health::HealthStatus;
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use rocket::{get, State};
|
use rocket::{get, State};
|
||||||
use rocket_contrib::templates::Template;
|
use rocket_dyn_templates::Template;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
pub async fn dashboard(state: State<'_, Arc<HealthState>>) -> Template {
|
pub async fn dashboard(state: &State<Arc<HealthState>>) -> Template {
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
struct Service {
|
struct Service {
|
||||||
name: String,
|
name: String,
|
||||||
@ -27,7 +27,7 @@ pub async fn dashboard(state: State<'_, Arc<HealthState>>) -> Template {
|
|||||||
last_update: last_update
|
last_update: last_update
|
||||||
.map(|last_update| {
|
.map(|last_update| {
|
||||||
let now = Utc::now();
|
let now = Utc::now();
|
||||||
if now.date() == last_update.date() {
|
if now.date_naive() == last_update.date_naive() {
|
||||||
format!("UTC {}", last_update.format("%H:%M:%S"))
|
format!("UTC {}", last_update.format("%H:%M:%S"))
|
||||||
} else {
|
} else {
|
||||||
format!("UTC {}", last_update.format("%Y-%m-%d %H:%M:%S"))
|
format!("UTC {}", last_update.format("%Y-%m-%d %H:%M:%S"))
|
||||||
@ -43,8 +43,7 @@ pub async fn dashboard(state: State<'_, Arc<HealthState>>) -> Template {
|
|||||||
Some(HealthStatus::Down) => ("red", "DOWN"),
|
Some(HealthStatus::Down) => ("red", "DOWN"),
|
||||||
Some(HealthStatus::Errored) => ("orange", "ERRORED"),
|
Some(HealthStatus::Errored) => ("orange", "ERRORED"),
|
||||||
None => ("#5b5b5b", "UNKNOWN"),
|
None => ("#5b5b5b", "UNKNOWN"),
|
||||||
}
|
};
|
||||||
.into();
|
|
||||||
|
|
||||||
context.services.push(Service {
|
context.services.push(Service {
|
||||||
name: id.clone(),
|
name: id.clone(),
|
||||||
|
|||||||
Reference in New Issue
Block a user