summaryrefslogtreecommitdiff
path: root/plugins/ping.py
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/ping.py')
-rw-r--r--plugins/ping.py31
1 files changed, 12 insertions, 19 deletions
diff --git a/plugins/ping.py b/plugins/ping.py
index 8e6a391..e919dea 100644
--- a/plugins/ping.py
+++ b/plugins/ping.py
@@ -1,33 +1,26 @@
import os
+import subprocess
import random
import plugins
PING_DEFAULTS = {
- 'hosts': list(), 'title': 'PING', 'timeout': 150
+ 'hosts': tuple(), 'title': 'PING', 'timeout': 150
}
class PluginThread(plugins.PluginThreadCommon):
def __init__(self, config):
super(PluginThread, self).__init__(config, PING_DEFAULTS)
- self.format_status('n/a')
-
- def format_status(self, state):
- self.status['full_text'] = self.conf['title'] + ': ' + state
- if state == 'up':
- self.status['urgent'] = False
- self.hide = True
- else:
- self.status['urgent'] = True
+ self.ping_cmd = ('fping', '-c1', '-qt' + str(self.conf['timeout']))
def main(self):
- random.shuffle(self.conf['hosts'])
- for host in self.conf['hosts']:
- fping = 'fping -qc1t' + str(self.conf['timeout'])\
- + ' ' + host + ' &>/dev/null'
- response = os.system(fping)
- if response == 0:
- self.format_status('on')
- break
- self.format_status('down')
+ host = random.choice(self.conf['hosts'])
+ fping = subprocess.run(
+ (*self.ping_cmd, host),
+ stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
+ )
+ if fping.returncode == 0:
+ self.format_status('up')
+ else:
+ self.format_status('down', urgent=True)