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):
|
2017-12-16 01:55:28 +02:00
|
|
|
def __init__(self, config):
|
|
|
|
defaults = {'hosts': list(), 'title': 'PING', 'timeout': 150}
|
|
|
|
super(PluginThread, self).__init__(config, defaults)
|
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):
|
2017-12-16 01:55:28 +02:00
|
|
|
self.status['full_text'] = self.conf['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):
|
2017-12-16 01:55:28 +02:00
|
|
|
random.shuffle(self.conf['hosts'])
|
|
|
|
for host in self.conf['hosts']:
|
|
|
|
fping = 'fping -qc1t' + str(self.conf['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')
|