35f658b573
Collapse the three former check types into a single core `Monitor` entity
with one management surface (/monitors), one result table (monitor_results),
and a single scheduled task. Every type can now watch a free-standing custom
destination (optional host_id) — not just a registered Host.
- models: Monitor + MonitorResult replace PingResult/DnsResult; Host loses its
ping/dns facet columns (now Monitor rows linked by host_id).
- checks: monitors/{ping,dns,http}.py pure probes + runner.run_monitor
dispatcher; one monitor_check scheduler with a per-monitor due-filter.
- status: single monitor_status_source replaces the three sources.
- UI: /monitors blueprint (type-aware add/edit/list/widget); host hub shows a
host's linked monitors + "add monitor for this host"; nav + widget registry
+ alert metric catalog rewired. http plugin folded into core and removed.
- migration 0022 merges the http branch, data-migrates host facets +
http_monitors + all three result histories, drops the old tables/columns.
Resolves the per-host ping/dns auto-attach issue (#275): monitors are now
explicit, never auto-added to every host.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016Jg27rgypiW2efULXJDtMC
44 lines
1.6 KiB
Python
44 lines
1.6 KiB
Python
"""DNS resolution check — pure probe returning a result dict."""
|
|
from __future__ import annotations
|
|
import asyncio
|
|
import logging
|
|
import socket
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
async def dns_check(address: str, expected_ip: str | None = None) -> dict:
|
|
"""Resolve `address`. Returns {is_up, resolved_ip, error_msg}.
|
|
|
|
Up = resolution succeeded AND (no expected_ip, or at least one returned
|
|
record matches expected_ip). resolved_ip is the first A/AAAA record.
|
|
"""
|
|
result = await _resolve(address)
|
|
if not result["resolved"]:
|
|
return {"is_up": False, "resolved_ip": None, "error_msg": "Resolution failed"}
|
|
|
|
resolved_ip = result["ip"]
|
|
if expected_ip and expected_ip not in result["all_ips"]:
|
|
return {
|
|
"is_up": False,
|
|
"resolved_ip": resolved_ip,
|
|
"error_msg": f"Expected {expected_ip} not in {', '.join(result['all_ips'])}",
|
|
}
|
|
return {"is_up": True, "resolved_ip": resolved_ip, "error_msg": None}
|
|
|
|
|
|
async def _resolve(address: str) -> dict:
|
|
"""Resolve hostname. Returns all A/AAAA records; first is the resolved_ip."""
|
|
try:
|
|
loop = asyncio.get_running_loop()
|
|
infos = await loop.run_in_executor(
|
|
None, socket.getaddrinfo, address, None, socket.AF_UNSPEC, socket.SOCK_STREAM
|
|
)
|
|
if infos:
|
|
all_ips = [info[4][0] for info in infos]
|
|
return {"resolved": True, "ip": all_ips[0], "all_ips": all_ips}
|
|
return {"resolved": False, "ip": None, "all_ips": []}
|
|
except Exception as exc:
|
|
logger.debug("DNS resolution failed for %s: %s", address, exc)
|
|
return {"resolved": False, "ip": None, "all_ips": []}
|