Gettign monitors from status page API
This commit is contained in:
18
src/api.rs
18
src/api.rs
@@ -30,14 +30,16 @@ pub struct KumaStatusPage {
|
|||||||
|
|
||||||
impl KumaStatusPage {
|
impl KumaStatusPage {
|
||||||
fn get_monitors(json: &Value) -> Vec<KumaMonitor> {
|
fn get_monitors(json: &Value) -> Vec<KumaMonitor> {
|
||||||
let monitor_list = &json["publicGroupList"]["monitorList"];
|
let mut monitors = vec![];
|
||||||
return match monitor_list.as_array() {
|
for group in json["publicGroupList"].as_array().unwrap_or(&vec![]) {
|
||||||
Some(list) => list.iter().map(|mon| KumaMonitor {
|
for monitor in group["monitorList"].as_array().unwrap_or(&vec![]) {
|
||||||
id: mon["id"].as_i64().unwrap_or(0),
|
monitors.push(KumaMonitor {
|
||||||
name: mon["name"].to_string()
|
id: monitor["id"].as_i64().unwrap_or(0),
|
||||||
}).collect(),
|
name: monitor["name"].to_string()
|
||||||
None => vec![]
|
});
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
return monitors;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get(slug: &str) -> Result<Self, Error> {
|
pub async fn get(slug: &str) -> Result<Self, Error> {
|
||||||
|
|||||||
Reference in New Issue
Block a user