Creating blank Monitor objects
This commit is contained in:
25
src/api.rs
25
src/api.rs
@@ -14,10 +14,18 @@ macro_rules! endpoints {
|
|||||||
($slug:expr) => { format!("{}/api/status-page/{}", crate::api::BASE_URL, $slug) }
|
($slug:expr) => { format!("{}/api/status-page/{}", crate::api::BASE_URL, $slug) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct HeartBeat {
|
||||||
|
status: i64,
|
||||||
|
time: String,
|
||||||
|
msg: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct KumaMonitor {
|
pub struct KumaMonitor {
|
||||||
id: i64,
|
id: i64,
|
||||||
name: String,
|
name: String,
|
||||||
|
heartbeats: Option<Vec<HeartBeat>>
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -28,15 +36,23 @@ pub struct KumaStatusPage {
|
|||||||
monitors: Vec<KumaMonitor>
|
monitors: Vec<KumaMonitor>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl KumaMonitor {
|
||||||
|
pub fn blank(val: &Value) -> Self {
|
||||||
|
Self {
|
||||||
|
id: val["id"].as_i64().unwrap_or(0),
|
||||||
|
name: val["name"].to_string(),
|
||||||
|
heartbeats: None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
impl KumaStatusPage {
|
impl KumaStatusPage {
|
||||||
fn get_monitors(json: &Value) -> Vec<KumaMonitor> {
|
fn get_monitors(json: &Value) -> Vec<KumaMonitor> {
|
||||||
let mut monitors = vec![];
|
let mut monitors = vec![];
|
||||||
for group in json["publicGroupList"].as_array().unwrap_or(&vec![]) {
|
for group in json["publicGroupList"].as_array().unwrap_or(&vec![]) {
|
||||||
for monitor in group["monitorList"].as_array().unwrap_or(&vec![]) {
|
for monitor in group["monitorList"].as_array().unwrap_or(&vec![]) {
|
||||||
monitors.push(KumaMonitor {
|
monitors.push(KumaMonitor::blank(&monitor));
|
||||||
id: monitor["id"].as_i64().unwrap_or(0),
|
|
||||||
name: monitor["name"].to_string()
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return monitors;
|
return monitors;
|
||||||
@@ -53,3 +69,4 @@ impl KumaStatusPage {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user