[formatting] reformat using "black -t py34"
getting rid of thinking about consistent formatting...
This commit is contained in:
parent
fa98bcbdd1
commit
30c1f712a6
119 changed files with 3961 additions and 3495 deletions
|
@ -24,30 +24,39 @@ import core.decorators
|
|||
|
||||
import util.cli
|
||||
|
||||
|
||||
def get_rtt(module, widget):
|
||||
try:
|
||||
widget.set('rtt-unreachable', False)
|
||||
res = util.cli.execute('ping -n -q -c {} -W {} {}'.format(
|
||||
widget.get('rtt-probes'), widget.get('rtt-timeout'), widget.get('address')
|
||||
))
|
||||
widget.set("rtt-unreachable", False)
|
||||
res = util.cli.execute(
|
||||
"ping -n -q -c {} -W {} {}".format(
|
||||
widget.get("rtt-probes"),
|
||||
widget.get("rtt-timeout"),
|
||||
widget.get("address"),
|
||||
)
|
||||
)
|
||||
|
||||
for line in res.split('\n'):
|
||||
if line.startswith('{} packets transmitted'.format(widget.get('rtt-probes'))):
|
||||
m = re.search(r'(\d+)% packet loss', line)
|
||||
for line in res.split("\n"):
|
||||
if line.startswith(
|
||||
"{} packets transmitted".format(widget.get("rtt-probes"))
|
||||
):
|
||||
m = re.search(r"(\d+)% packet loss", line)
|
||||
|
||||
widget.set('packet-loss', m.group(1))
|
||||
widget.set("packet-loss", m.group(1))
|
||||
|
||||
if not line.startswith('rtt'): continue
|
||||
m = re.search(r'([0-9\.]+)/([0-9\.]+)/([0-9\.]+)/([0-9\.]+)\s+(\S+)', line)
|
||||
if not line.startswith("rtt"):
|
||||
continue
|
||||
m = re.search(r"([0-9\.]+)/([0-9\.]+)/([0-9\.]+)/([0-9\.]+)\s+(\S+)", line)
|
||||
|
||||
widget.set('rtt-min', float(m.group(1)))
|
||||
widget.set('rtt-avg', float(m.group(2)))
|
||||
widget.set('rtt-max', float(m.group(3)))
|
||||
widget.set('rtt-unit', m.group(5))
|
||||
widget.set("rtt-min", float(m.group(1)))
|
||||
widget.set("rtt-avg", float(m.group(2)))
|
||||
widget.set("rtt-max", float(m.group(3)))
|
||||
widget.set("rtt-unit", m.group(5))
|
||||
except Exception as e:
|
||||
widget.set('rtt-unreachable', True)
|
||||
widget.set("rtt-unreachable", True)
|
||||
|
||||
core.event.trigger("update", [module.id], redraw_only=True)
|
||||
|
||||
core.event.trigger('update', [ module.id ], redraw_only=True)
|
||||
|
||||
class Module(core.module.Module):
|
||||
@core.decorators.every(seconds=60)
|
||||
|
@ -56,29 +65,31 @@ class Module(core.module.Module):
|
|||
|
||||
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)
|
||||
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')
|
||||
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)
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue