2016-10-19 20:06:19 +03:00
|
|
|
import os
|
|
|
|
import random
|
2016-11-28 13:48:11 +02:00
|
|
|
import plugins
|
2016-10-19 20:06:19 +03:00
|
|
|
|
|
|
|
|
2016-11-28 13:48:11 +02:00
|
|
|
class PluginThread(plugins.PluginThreadCommon):
|
2016-11-21 12:34:32 +02:00
|
|
|
def __init__(self, section, config):
|
2016-11-19 17:44:40 +02:00
|
|
|
super(PluginThread, self).__init__(section, config)
|
2016-10-22 05:50:11 +03:00
|
|
|
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')
|
2016-10-22 05:50:11 +03:00
|
|
|
self.format_status('n/a')
|
2016-10-19 20:06:19 +03:00
|
|
|
|
2016-10-22 05:50:11 +03:00
|
|
|
def format_status(self, state):
|
|
|
|
self.status['full_text'] = self.title + ': ' + state
|
2016-10-25 19:48:40 +03:00
|
|
|
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')
|