Initial testing of Kuma API
This commit is contained in:
commit
61ae0359a8
6 files changed
+5307
No files matched your search
+53
@@ -0,0 +1,53 @@
|
||||
use serde_json::Value;
|
||||
use reqwest::{self, Error};
|
||||
|
||||
pub const BASE_URL: &str = "https://uptime.shockrah.xyz";
|
||||
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! heartbeat {
|
||||
($slug:expr) => { format!("{}/api/status-page/heartbeat/{}", crate::api::BASE_URL, $slug) }
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! endpoints {
|
||||
($slug:expr) => { format!("{}/api/status-page/{}", crate::api::BASE_URL, $slug) }
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct KumaMonitor {
|
||||
id: i64,
|
||||
name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct KumaStatusPage {
|
||||
slug: String,
|
||||
title: String,
|
||||
description: String,
|
||||
monitors: Vec<KumaMonitor>
|
||||
}
|
||||
|
||||
impl KumaStatusPage {
|
||||
fn get_monitors(json: &Value) -> Vec<KumaMonitor> {
|
||||
let monitor_list = &json["publicGroupList"]["monitorList"];
|
||||
return match monitor_list.as_array() {
|
||||
Some(list) => list.iter().map(|mon| KumaMonitor {
|
||||
id: mon["id"].as_i64().unwrap_or(0),
|
||||
name: mon["name"].to_string()
|
||||
}).collect(),
|
||||
None => vec![]
|
||||
};
|
||||
}
|
||||
|
||||
pub async fn get(slug: &str) -> Result<Self, Error> {
|
||||
let endpoint = endpoints!(slug);
|
||||
let resp: Value = reqwest::get(&endpoint).await?.json().await?;
|
||||
return Ok(KumaStatusPage {
|
||||
slug: resp["config"]["slug"].to_string(),
|
||||
title: resp["config"]["title"].to_string(),
|
||||
description: resp["config"]["description"].to_string(),
|
||||
monitors: KumaStatusPage::get_monitors(&resp)
|
||||
})
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
#[derive(Debug)]
|
||||
pub struct HeartBeat {
|
||||
status: i32,
|
||||
time: String,
|
||||
ping: i32,
|
||||
msg: String
|
||||
}
|
||||
|
||||
struct Tag {
|
||||
name: String,
|
||||
value: Option<String>
|
||||
}
|
||||
|
||||
struct Monitor {
|
||||
host: String,
|
||||
id: i32,
|
||||
tags: Vec<Tag>,
|
||||
cert_expires_in: i32
|
||||
}
|
||||
|
||||
pub struct StatusPage {
|
||||
title: String,
|
||||
description: String,
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
mod data;
|
||||
mod api;
|
||||
|
||||
use reqwest::{self, Error};
|
||||
use crate::api::KumaStatusPage;
|
||||
|
||||
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Error> {
|
||||
let page = KumaStatusPage::get("pub").await?;
|
||||
println!("{page:?}");
|
||||
Ok(())
|
||||
}
|
||||
Reference in new issue
Block a user