This commit is contained in:
Mateusz Gruszczyński
2026-08-24 23:20:06 +02:00
parent 76a6f050ae
commit 7de006e841
10 changed files with 34 additions and 26 deletions
+5 -3
View File
@@ -230,13 +230,15 @@ async fn poll_device(state: &AppState, device: &mut Device) {
log_poll_health_transition(state, device, previous_failures).await;
}
async fn log_poll_health_transition(state: &AppState, device: &Device, previous_failures: u32) {
async fn log_poll_health_transition(state: &AppState, device: &Device, previous_failures: u8) {
let threshold = state.settings.read().await.notifications.communication_failure_threshold.max(2);
if device.communication_failures >= threshold && previous_failures < threshold {
let current_failures = u32::from(device.communication_failures);
let previous_failures = u32::from(previous_failures);
if current_failures >= threshold && previous_failures < threshold {
state.log("warn", "device.offline", &format!("{} did not respond {} times in a row", device.name, device.communication_failures), json!({
"device_id": device.id, "consecutive_failures": device.communication_failures, "threshold": threshold
}));
} else if device.communication_failures == 0 && previous_failures >= threshold {
} else if current_failures == 0 && previous_failures >= threshold {
state.log("info", "device.recovered", &format!("{} is responding again", device.name), json!({"device_id": device.id}));
}
}