unifly_api/legacy/
events.rs1use serde_json::json;
7use tracing::debug;
8
9use crate::error::Error;
10use crate::legacy::client::LegacyClient;
11use crate::legacy::models::{LegacyAlarm, LegacyEvent};
12
13impl LegacyClient {
14 pub async fn list_events(&self, count: Option<u32>) -> Result<Vec<LegacyEvent>, Error> {
21 let path = match count {
22 Some(n) => format!("stat/event?_limit={n}"),
23 None => "stat/event".to_string(),
24 };
25 let url = self.site_url(&path);
26 debug!(?count, "listing events");
27 self.get(url).await
28 }
29
30 pub async fn list_alarms(&self) -> Result<Vec<LegacyAlarm>, Error> {
34 let url = self.site_url("stat/alarm");
35 debug!("listing alarms");
36 self.get(url).await
37 }
38
39 pub async fn archive_alarm(&self, id: &str) -> Result<(), Error> {
43 let url = self.site_url("cmd/evtmgr");
44 debug!(id, "archiving alarm");
45 let _: Vec<serde_json::Value> = self
46 .post(
47 url,
48 &json!({
49 "cmd": "archive-alarm",
50 "_id": id,
51 }),
52 )
53 .await?;
54 Ok(())
55 }
56
57 pub async fn archive_all_alarms(&self) -> Result<(), Error> {
61 let url = self.site_url("cmd/evtmgr");
62 debug!("archiving all alarms");
63 let _: Vec<serde_json::Value> = self
64 .post(
65 url,
66 &json!({
67 "cmd": "archive-all-alarms",
68 }),
69 )
70 .await?;
71 Ok(())
72 }
73}