vdstatus/plugins/ping.py

31 lines
1,018 B
Python
Raw Normal View History

import os
import random
import plugins.common
class PluginThread(plugins.common.PluginThreadCommon):
def __init__(self, section, config, thread_id):
super(PluginThread, self).__init__(section, config)
self.hosts = config.get(section, 'hosts').split(',')
self.title = config.get(section, 'title')
2016-10-22 19:27:28 +03:00
self.timeout = config.get(section, 'timeout', fallback='150')
self.format_status('n/a')
def format_status(self, state):
self.status['full_text'] = self.title + ': ' + state
if state == 'on':
self.status['urgent'] = False
self.hide = True
else:
self.status['urgent'] = True
2016-10-22 19:27:28 +03:00
def main(self):
random.shuffle(self.hosts)
for host in self.hosts:
2016-10-23 12:09:06 +03:00
fping = 'fping -qc1t' + self.timeout + ' ' + host + ' &>/dev/null'
2016-10-22 19:27:28 +03:00
response = os.system(fping)
if response == 0:
self.format_status('on')
break
self.format_status('off')