A simple replacement for i3status that is both extensible and customizable.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ping.py 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import os
  2. import random
  3. import time
  4. import threading
  5. class ConnTest(threading.Thread):
  6. def __init__(self, threadID, name):
  7. threading.Thread.__init__(self)
  8. self.threadID = threadID
  9. self.name = name
  10. self.hosts = list()
  11. self.status = 'n/a'
  12. self.freq = int()
  13. def configure(self, hosts, freq=5):
  14. self.hosts = hosts.split(',')
  15. self.freq = freq
  16. def run(self):
  17. global is_running
  18. is_running = True
  19. while True:
  20. random.shuffle(self.hosts)
  21. try:
  22. for host in self.hosts:
  23. fping = 'fping -q -c1 -t100 ' + host + ' &>/dev/null'
  24. response = os.system(fping)
  25. if response == 0:
  26. self.status = 'on'
  27. break
  28. self.status = 'off'
  29. except (KeyboardInterrupt, SystemExit):
  30. break
  31. time.sleep(self.freq)
  32. is_running = False
  33. ping_object = ConnTest(1, 'test_network')
  34. def execute(config, section):
  35. result = dict()
  36. global ping_object
  37. if is_running is False:
  38. ping_object.configure(config.get(section, 'hosts'), 10)
  39. ping_object.start()
  40. result['full_text'] = config.get(section, 'title') + ' ' + ping_object.status
  41. return result