diff --git a/checkers/ping.py b/checkers/ping.py index 20c2326..ebd3939 100644 --- a/checkers/ping.py +++ b/checkers/ping.py @@ -4,8 +4,8 @@ Checker Ping. Vérifie la disponibilité d'un hôte via ICMP ping. """ +import re import subprocess -import time import platform from .base import BaseChecker, CheckResult @@ -41,7 +41,6 @@ class PingChecker(BaseChecker): else: cmd = ["ping", "-c", str(count), "-W", str(timeout), host] - start = time.time() try: result = subprocess.run( cmd, @@ -49,9 +48,12 @@ class PingChecker(BaseChecker): text=True, timeout=timeout + 5 ) - response_time = (time.time() - start) * 1000 # ms if result.returncode == 0: + # Parse RTT from ping output (e.g., "time=0.32 ms" or "time=0.32ms") + match = re.search(r"time[=<]([\d.]+)\s*ms", result.stdout) + response_time = float(match.group(1)) if match else None + return CheckResult( success=True, message="Host is reachable",