2016-10-19 20:06:19 +03:00
|
|
|
import os
|
|
|
|
import random
|
|
|
|
import time
|
|
|
|
import threading
|
|
|
|
|
|
|
|
|
2016-10-22 05:50:11 +03:00
|
|
|
class PluginThread(threading.Thread):
|
|
|
|
def __init__(self, section, config, thread_id):
|
2016-10-19 20:06:19 +03:00
|
|
|
threading.Thread.__init__(self)
|
2016-10-22 05:50:11 +03:00
|
|
|
self.threadID = thread_id
|
|
|
|
self.hosts = config.get(section, 'hosts').split(',')
|
|
|
|
self.title = config.get(section, 'title')
|
|
|
|
self.status = dict()
|
|
|
|
self.freq = 5
|
|
|
|
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-19 20:06:19 +03:00
|
|
|
|
|
|
|
def run(self):
|
|
|
|
while True:
|
|
|
|
random.shuffle(self.hosts)
|
|
|
|
try:
|
|
|
|
for host in self.hosts:
|
|
|
|
fping = 'fping -q -c1 -t100 ' + host + ' &>/dev/null'
|
|
|
|
response = os.system(fping)
|
|
|
|
if response == 0:
|
2016-10-22 05:50:11 +03:00
|
|
|
self.format_status('on')
|
2016-10-19 20:06:19 +03:00
|
|
|
break
|
2016-10-22 05:50:11 +03:00
|
|
|
self.format_status('off')
|
2016-10-19 20:06:19 +03:00
|
|
|
|
|
|
|
except (KeyboardInterrupt, SystemExit):
|
|
|
|
break
|
|
|
|
time.sleep(self.freq)
|