Browse Source

a functional ping plugin, but needs moar exceptions and sanity checks

master
Von Random 6 years ago
parent
commit
d77dbeb1de
  1. 14
      conf.ini
  2. 2
      plugins/date.py
  3. 49
      plugins/ping.py
  4. 4
      vdstatus.py
  5. 13
      vdstatus_i3

14
conf.ini

@ -1,10 +1,20 @@
[main]
[ping_ext]
plugin = ping
hosts = de-ber-as20647.anchors.atlas.ripe.net,nl-ams-as1101.anchors.atlas.ripe.net,uk-boh-as196745.anchors.atlas.ripe.net
title = NET:
[ping_local]
plugin = ping
hosts = 127.0.0.1,127.0.0.2
title = LOCAL:
[day]
plugin = date
color = red
color = #FF0000
format = %%A %%d
[time]
plugin = date
format = %%H:%%M
format = %%H:%%M

2
plugins/date.py

@ -1,7 +1,7 @@
import time
def run(config, section):
def execute(config, section):
fmt = config.get(section, 'format')
result = dict()
if config.has_option(section, 'color'):

49
plugins/ping.py

@ -0,0 +1,49 @@
import os
import random
import time
import threading
class ConnTest(threading.Thread):
def __init__(self, threadID, name):
threading.Thread.__init__(self)
self.threadID = threadID
self.name = name
self.hosts = list()
self.status = 'n/a'
self.freq = int()
def configure(self, hosts, freq=5):
self.hosts = hosts.split(',')
self.freq = freq
def run(self):
global is_running
is_running = True
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:
self.status = 'on'
break
self.status = 'off'
except (KeyboardInterrupt, SystemExit):
break
time.sleep(self.freq)
is_running = False
ping_object = ConnTest(1, 'test_network')
def execute(config, section):
result = dict()
global ping_object
if is_running is False:
ping_object.configure(config.get(section, 'hosts'), 10)
ping_object.start()
result['full_text'] = config.get(section, 'title') + ' ' + ping_object.status
return result

4
vdstatus.py

@ -18,5 +18,5 @@ def run_plugins():
continue
plugin_name = '.' + configuration.get(section, 'plugin')
plugin_module = importlib.import_module(plugin_name, 'plugins')
outputs.append(plugin_module.run(configuration, section))
print(json.dumps(outputs) + ',')
outputs.append(plugin_module.execute(configuration, section))
return outputs

13
vdstatus_i3

@ -1 +1,12 @@
#!/usr/bin/env python3 -u
#!/usr/bin/python3 -u
import json
import vdstatus
import time
print('{"version":1}')
print('[')
while True:
output = vdstatus.run_plugins()
print(json.dumps(output) + ',')
time.sleep(1)

Loading…
Cancel
Save