vdstatus/plugins/ping.py

27 lines
707 B
Python
Raw Normal View History

import os
import subprocess
import random
import plugins
PING_DEFAULTS = {
'hosts': tuple(), 'title': 'PING', 'timeout': 150
}
class PluginThread(plugins.PluginThreadCommon):
def __init__(self, config):
super(PluginThread, self).__init__(config, PING_DEFAULTS)
self.ping_cmd = ('fping', '-c1', '-qt' + str(self.conf['timeout']))
2016-10-22 19:27:28 +03:00
def main(self):
host = random.choice(self.conf['hosts'])
fping = subprocess.run(
(*self.ping_cmd, host),
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
)
if fping.returncode == 0:
self.format_status('up')
else:
self.format_status('down', urgent=True)