2016-10-19 20:06:19 +03:00
|
|
|
import os
|
2019-07-05 18:24:46 +03:00
|
|
|
import subprocess
|
2016-10-19 20:06:19 +03:00
|
|
|
import random
|
2016-11-28 13:48:11 +02:00
|
|
|
import plugins
|
2016-10-19 20:06:19 +03:00
|
|
|
|
|
|
|
|
2019-03-28 12:21:15 +02:00
|
|
|
PING_DEFAULTS = {
|
2019-07-05 18:24:46 +03:00
|
|
|
'hosts': tuple(), 'title': 'PING', 'timeout': 150
|
2019-03-28 12:21:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-28 13:48:11 +02:00
|
|
|
class PluginThread(plugins.PluginThreadCommon):
|
2017-12-16 01:55:28 +02:00
|
|
|
def __init__(self, config):
|
2019-03-28 12:21:15 +02:00
|
|
|
super(PluginThread, self).__init__(config, PING_DEFAULTS)
|
2019-07-05 18:24:46 +03:00
|
|
|
self.ping_cmd = ('fping', '-c1', '-qt' + str(self.conf['timeout']))
|
2016-10-22 19:27:28 +03:00
|
|
|
|
|
|
|
def main(self):
|
2019-07-05 18:24:46 +03:00
|
|
|
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:
|
2019-07-08 14:19:05 +03:00
|
|
|
self.format_status('down', True)
|