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
|
|
|
|
|
|
|
|
2019-03-28 12:21:15 +02:00
|
|
|
PING_DEFAULTS = {
|
|
|
|
'hosts': list(), 'title': 'PING', 'timeout': 150
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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)
|
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
|
2019-03-28 12:21:15 +02:00
|
|
|
if state == 'up':
|
2016-10-25 19:48:40 +03:00
|
|
|
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
|
2019-03-28 12:21:15 +02:00
|
|
|
self.format_status('down')
|