diff --git a/monitor.py b/monitor.py index 3aaa0e4..4e79e10 100644 --- a/monitor.py +++ b/monitor.py @@ -488,6 +488,7 @@ def main() -> None: "comment": comment, "status": "unknown", "rtt": None, "down_since": None, "last_seen": None, "last_notify": None, + "fail_count": 0, } else: hosts_state[ip]["comment"] = comment @@ -507,6 +508,7 @@ def main() -> None: log.info("✅ %-34s %.1f ms", label, rtt) state["rtt"] = rtt state["last_seen"] = now + state["fail_count"] = 0 if state["status"] == "down": ds = state.get("down_since") @@ -524,10 +526,11 @@ def main() -> None: state["status"] = "up" else: - log.warning("❌ %-34s нет ответа", label) + state["fail_count"] = state.get("fail_count", 0) + 1 + log.warning("❌ %-34s нет ответа (%d/%d)", label, state["fail_count"], FAILURE_THRESHOLD) state["rtt"] = None - if state["status"] != "down": + if state["fail_count"] >= FAILURE_THRESHOLD and state["status"] != "down": state.update({"status": "down", "down_since": now, "last_notify": now}) notify( f"{obj_prefix()}"