Adding heartbeats to the unified data
This commit is contained in:
parent
7270249ef6
commit
1c4077ffc3
2 changed files with 24 additions and 2 deletions
|
|
@ -1,9 +1,11 @@
|
|||
use crate::data::heartbeat::model::{HeartbeatResponse, UptimeData};
|
||||
use crate::data::heartbeat;
|
||||
use crate::data::heartbeat::model::{HeartbeatEntry, HeartbeatResponse, UptimeData};
|
||||
use crate::data::status_page::model::{MonitorInfo, StatusPageResponse};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct UnifiedMonitorData {
|
||||
pub monitor_info: MonitorInfo,
|
||||
pub heartbeats: Vec<HeartbeatEntry>,
|
||||
pub uptime_data: Option<UptimeData>,
|
||||
}
|
||||
|
||||
|
|
@ -20,9 +22,17 @@ pub fn unify_data(status_page: &StatusPageResponse, heartbeat: &HeartbeatRespons
|
|||
for monitor_info in &group.monitor_list {
|
||||
let uptime_data = heartbeat.get_uptime(monitor_info.id, 24).cloned();
|
||||
|
||||
let heartbeats = heartbeat
|
||||
.monitors
|
||||
.iter()
|
||||
.find(|m| m.monitor_id == monitor_info.id)
|
||||
.map(|m| m.heartbeats.clone())
|
||||
.unwrap_or_else(Vec::new);
|
||||
|
||||
monitors.push(UnifiedMonitorData {
|
||||
monitor_info: monitor_info.clone(),
|
||||
uptime_data: uptime_data,
|
||||
heartbeats,
|
||||
uptime_data,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
12
src/main.rs
12
src/main.rs
|
|
@ -60,6 +60,18 @@ fn main() -> Result<()> {
|
|||
"Uptime Service: {}",
|
||||
monitor.uptime_data.expect("Formgen?").get_perc_formated()
|
||||
);
|
||||
println!(
|
||||
"Status atual: {}",
|
||||
monitor
|
||||
.heartbeats
|
||||
.last()
|
||||
.map(|h| if h.status == 1 {
|
||||
"✅ Online"
|
||||
} else {
|
||||
"❌ Offline"
|
||||
})
|
||||
.unwrap_or("❓ Sem dados")
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue