ZKT26/noc-docker/probe/probe.py
2026-03-31 22:49:35 +02:00

28 lines
675 B
Python

import time
import subprocess
import requests
BACKEND = "http://backend:5000/report"
TARGETS = ["147.232.22.34", "147.232.22.35", "147.232.205.116"]
def ping(target):
try:
output = subprocess.check_output(["ping", "-c", "1", target]).decode()
latency = float(output.split("time=")[1].split(" ")[0])
return latency, "UP"
except:
return 0, "DOWN"
while True:
for t in TARGETS:
latency, status = ping(t)
try:
requests.post(BACKEND, json={
"target": t,
"latency": latency,
"status": status
})
except:
pass
time.sleep(5)