aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs36
1 files changed, 8 insertions, 28 deletions
diff --git a/src/main.rs b/src/main.rs
index 706effe..67df74e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,4 @@
+#![feature(exit_status_error)]
pub mod check;
pub mod log;
pub mod mail;
@@ -6,15 +7,11 @@ pub mod web;
use ::log::error;
use anyhow::{anyhow, Result};
use axum::{routing::get, Router};
-use check::check_loop;
+use check::{check_loop, Check};
+use chrono::{DateTime, Utc};
use mail::MailConfig;
use serde::Deserialize;
-use std::{
- collections::BTreeMap,
- net::SocketAddr,
- sync::Arc,
- time::{Duration, SystemTime},
-};
+use std::{collections::BTreeMap, net::SocketAddr, sync::Arc};
use tokio::{fs::read_to_string, sync::RwLock};
use web::send_html_page;
@@ -44,30 +41,13 @@ pub struct Service {
checks: Vec<Check>,
}
-#[derive(Debug, Deserialize)]
-#[serde(rename_all = "snake_case")]
-pub enum Check {
- Systemd(String),
- Http { title: Option<String>, url: String },
- Shell { title: String, command: String },
-}
-
#[derive(Debug, Clone)]
-pub struct Success {
- pub latency: Option<Duration>,
- pub updated: SystemTime,
-}
-impl Default for Success {
- fn default() -> Self {
- Self {
- latency: None,
- updated: SystemTime::now(),
- }
- }
+pub struct Status {
+ pub time: DateTime<Utc>,
+ pub status: Result<String, String>,
}
-static STATUS: RwLock<BTreeMap<(usize, usize), Result<Success>>> =
- RwLock::const_new(BTreeMap::new());
+static STATUS: RwLock<BTreeMap<(usize, usize), Status>> = RwLock::const_new(BTreeMap::new());
async fn run() -> anyhow::Result<()> {
let config = std::env::args()