Initial testing of Kuma API
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
5204
Cargo.lock
generated
Normal file
5204
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
11
Cargo.toml
Normal file
11
Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "monitor"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
iced = "0.14.0"
|
||||
reqwest = { version = "0.13.2", features = ["json"] }
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
serde_json = "1.0.149"
|
||||
tokio = { version = "1.52.1", features = ["full"] }
|
||||
53
src/api.rs
Normal file
53
src/api.rs
Normal file
@@ -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
src/data.rs
Normal file
24
src/data.rs
Normal file
@@ -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
src/main.rs
Normal file
14
src/main.rs
Normal file
@@ -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