monimon/plugins/ping.py

14 lines
368 B
Python

import os
import subprocess
def ping(host):
response = subprocess.run(["ping","-c","1",host],
stdout = subprocess.DEVNULL, stderr = subprocess.PIPE)
if response.returncode == 0:
return [True, ""]
elif response.stderr:
return [False, response.stderr.decode("UTF-8")]
else:
return [False, ""]