Update heartbeat.py

当ping为0时,将其设为1
This commit is contained in:
yshtcn 2023-08-04 16:06:00 +08:00 committed by GitHub
parent f3652294ac
commit 25bdf4b764
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -76,12 +76,16 @@ def ping(host):
ping_result = ''.join(filter(str.isdigit, time_str)) ping_result = ''.join(filter(str.isdigit, time_str))
if ping_result.isdigit() and int(ping_result) < 10000: if ping_result.isdigit() and int(ping_result) < 10000:
# If ping result is 0, change it to 1
if int(ping_result) == 0:
ping_result = '1'
return ping_result return ping_result
logger.info(f"{datetime.now()} Ping command output: {repr(stdout)}") logger.info(f"{datetime.now()} Ping command output: {repr(stdout)}")
return "ping failed" return "ping failed"
def heartbeat(interval, heartbeat_url, session, ping_host): def heartbeat(interval, heartbeat_url, session, ping_host):
while not stop_heartbeat.is_set(): while not stop_heartbeat.is_set():
try: try: