From b9b1e65176a1151447e5738d31c8667df1c516bd Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Sun, 12 Apr 2020 14:21:59 +0200 Subject: [PATCH] [modules/ping] quotes --- modules/core/ping.py | 52 ++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/modules/core/ping.py b/modules/core/ping.py index 0a1419b..a721e61 100644 --- a/modules/core/ping.py +++ b/modules/core/ping.py @@ -24,61 +24,61 @@ import bumblebee.engine def get_rtt(module, widget): try: - widget.set("rtt-unreachable", False) - res = bumblebee.util.execute("ping -n -q -c {} -W {} {}".format( - widget.get("rtt-probes"), widget.get("rtt-timeout"), widget.get("address") + widget.set('rtt-unreachable', False) + res = bumblebee.util.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"))): + 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)) - if not line.startswith("rtt"): continue + 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) class Module(bumblebee.engine.Module): def __init__(self, engine, config): widget = bumblebee.output.Widget(full_text=self.rtt) super(Module, self).__init__(engine, config, widget) - widget.set("address", self.parameter("address", "8.8.8.8")) - widget.set("interval", self.parameter("interval", 60)) - 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('address', self.parameter('address', '8.8.8.8')) + widget.set('interval', self.parameter('interval', 60)) + 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) self._next_check = 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"), + 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, widgets): if int(time.time()) < self._next_check: return thread = threading.Thread(target=get_rtt, args=(self, widgets[0],)) thread.start() - self._next_check = int(time.time()) + int(widgets[0].get("interval")) + self._next_check = int(time.time()) + int(widgets[0].get('interval')) # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4