parent
547874dafd
commit
d38a21983c
1 changed files with 31 additions and 34 deletions
|
@ -15,7 +15,6 @@ Parameters:
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
import threading
|
|
||||||
|
|
||||||
import core.module
|
import core.module
|
||||||
import core.widget
|
import core.widget
|
||||||
|
@ -25,7 +24,41 @@ import core.decorators
|
||||||
import util.cli
|
import util.cli
|
||||||
|
|
||||||
|
|
||||||
def get_rtt(module, widget):
|
|
||||||
|
|
||||||
|
class Module(core.module.Module):
|
||||||
|
@core.decorators.every(seconds=60)
|
||||||
|
def __init__(self, config, theme):
|
||||||
|
super().__init__(config, theme, core.widget.Widget(self.rtt))
|
||||||
|
|
||||||
|
self.background = True
|
||||||
|
|
||||||
|
widget = self.widget()
|
||||||
|
|
||||||
|
widget.set("address", self.parameter("address", "8.8.8.8"))
|
||||||
|
widget.set("rtt-probes", self.parameter("probes", 5))
|
||||||
|
widget.set("rtt-timeout", self.parameter("timeout", 5.0))
|
||||||
|
widget.set("rtt-avg", 0.0)
|
||||||
|
widget.set("rtt-unit", "")
|
||||||
|
widget.set("packet-loss", 0)
|
||||||
|
|
||||||
|
def rtt(self, widget):
|
||||||
|
if widget.get("rtt-unreachable"):
|
||||||
|
return "{}: unreachable".format(widget.get("address"))
|
||||||
|
return "{}: {:.1f}{} ({}%)".format(
|
||||||
|
widget.get("address"),
|
||||||
|
widget.get("rtt-avg"),
|
||||||
|
widget.get("rtt-unit"),
|
||||||
|
widget.get("packet-loss"),
|
||||||
|
)
|
||||||
|
|
||||||
|
def state(self, widget):
|
||||||
|
if widget.get("rtt-unreachable"):
|
||||||
|
return ["critical"]
|
||||||
|
return self.threshold_state(widget.get("rtt-avg"), 1000.0, 2000.0)
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
widget = self.widget()
|
||||||
try:
|
try:
|
||||||
widget.set("rtt-unreachable", False)
|
widget.set("rtt-unreachable", False)
|
||||||
res = util.cli.execute(
|
res = util.cli.execute(
|
||||||
|
@ -55,41 +88,5 @@ def get_rtt(module, widget):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
widget.set("rtt-unreachable", True)
|
widget.set("rtt-unreachable", True)
|
||||||
|
|
||||||
core.event.trigger("update", [module.id], redraw_only=True)
|
|
||||||
|
|
||||||
|
|
||||||
class Module(core.module.Module):
|
|
||||||
@core.decorators.every(seconds=60)
|
|
||||||
def __init__(self, config, theme):
|
|
||||||
super().__init__(config, theme, core.widget.Widget(self.rtt))
|
|
||||||
|
|
||||||
widget = self.widget()
|
|
||||||
|
|
||||||
widget.set("address", self.parameter("address", "8.8.8.8"))
|
|
||||||
widget.set("rtt-probes", self.parameter("probes", 5))
|
|
||||||
widget.set("rtt-timeout", self.parameter("timeout", 5.0))
|
|
||||||
widget.set("rtt-avg", 0.0)
|
|
||||||
widget.set("rtt-unit", "")
|
|
||||||
widget.set("packet-loss", 0)
|
|
||||||
|
|
||||||
def rtt(self, widget):
|
|
||||||
if widget.get("rtt-unreachable"):
|
|
||||||
return "{}: unreachable".format(widget.get("address"))
|
|
||||||
return "{}: {:.1f}{} ({}%)".format(
|
|
||||||
widget.get("address"),
|
|
||||||
widget.get("rtt-avg"),
|
|
||||||
widget.get("rtt-unit"),
|
|
||||||
widget.get("packet-loss"),
|
|
||||||
)
|
|
||||||
|
|
||||||
def state(self, widget):
|
|
||||||
if widget.get("rtt-unreachable"):
|
|
||||||
return ["critical"]
|
|
||||||
return self.threshold_state(widget.get("rtt-avg"), 1000.0, 2000.0)
|
|
||||||
|
|
||||||
def update(self):
|
|
||||||
thread = threading.Thread(target=get_rtt, args=(self, self.widget(),))
|
|
||||||
thread.start()
|
|
||||||
|
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue