Ejemplo n.º 1
0
    def state(self, widget):
        state = []
        capacity = widget.get("capacity", -1)
        if capacity < 0:
            return ["critical", "unknown"]

        if capacity < int(self.parameter("critical", 10)):
            state.append("critical")
        elif capacity < int(self.parameter("warning", 20)):
            state.append("warning")

        if widget.get("ac"):
            state.append("AC")
        else:
            charge = "Unknown"
            try:
                charge = self.power.get_state(self.device)
            except Exception as e:
                logging.exception("unable to get charge value: {}".format(
                    str(e)))
            if charge == "Discharging":
                state.append("discharging-{}".format(
                    min([10, 25, 50, 80, 100],
                        key=lambda i: abs(i - capacity))))
            elif charge == "Unknown":
                state.append("unknown-{}".format(
                    min([10, 25, 50, 80, 100],
                        key=lambda i: abs(i - capacity))))
            else:
                if capacity > 95:
                    state.append("charged")
                else:
                    state.append("charging")
        return state
Ejemplo n.º 2
0
    def update(self):
        widget = self.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"),
            ))

            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
                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))
        except Exception as e:
            widget.set("rtt-unreachable", True)
Ejemplo n.º 3
0
 def state(self, widget):
     cnt = 0
     for t in ["security", "bugfixes", "enhancements", "other"]:
         cnt += widget.get(t, 0)
     if cnt == 0:
         return "good"
     if cnt > 50 or widget.get("security", 0) > 0:
         return "critical"
Ejemplo n.º 4
0
 def state(self, widget):
     widget_type = widget.get("type", "")
     try:
         data = self.__data[widget.get("adapter")][widget.get("package")][
             widget.get("field")]
         if "crit" in data and float(data["input"]) > float(data["crit"]):
             return ["critical", widget_type]
         if "max" in data and float(data["input"]) > float(data["max"]):
             return ["warning", widget_type]
     except:
         pass
     return [widget_type]
Ejemplo n.º 5
0
    def state(self, widget):
        cnt = 0
        ret = "good"
        for t in ["to_upgrade", "to_remove"]:
            cnt += widget.get(t, 0)
        if cnt > 50:
            ret = "critical"
        elif cnt > 0:
            ret = "warning"
        if widget.get("error"):
            ret = "critical"

        return ret
Ejemplo n.º 6
0
    def state(self, widget):
        weightedCount = sum(
            map(lambda x: (len(repos) - x[0]) * widget.get(x[1], 0), enumerate(repos))
        )

        if weightedCount < 10:
            return "good"

        return self.threshold_state(weightedCount, 100, 150)
Ejemplo n.º 7
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"),
     )
Ejemplo n.º 8
0
 def __update_widget(self, widget):
     if widget.get("field", "") == "":
         return  # nothing to do
     data = self.__data[widget.get("adapter")][widget.get("package")][
         widget.get("field")]
     if "temp" in widget.get("field"):
         widget.full_text("{:0.01f}°C".format(data["input"]))
     elif "fan" in widget.get("field"):
         widget.full_text("{:0.0f}RPM".format(data["input"]))
     else:
         widget.full_text("{:0.0f}".format(data["input"]))
Ejemplo n.º 9
0
    def get_progress_text(self, widget):
        if self.update_progress_info(widget):
            width = util.format.asint(self.parameter("barwidth", 8))
            count = round((width * widget.get("per")) / 100)
            filledchar = self.parameter("barfilledchar", "#")
            emptychar = self.parameter("baremptychar", "-")

            bar = "[{}{}]".format(filledchar * count,
                                  emptychar * (width - count))

            str_format = self.parameter("format", "{bar} {cmd} {arg}")
            return str_format.format(
                bar=bar,
                pid=widget.get("pid"),
                cmd=widget.get("cmd"),
                arg=widget.get("arg"),
                percentage=widget.get("per"),
                quantity=widget.get("qty"),
                speed=widget.get("spd"),
                time=widget.get("tim"),
            )
        else:
            return self.parameter("placeholder", "n/a")
Ejemplo n.º 10
0
 def text(self, widget):
     val = widget.get("temp", "n/a")
     return val
Ejemplo n.º 11
0
 def updates(self, widget):
     if widget.get("error"):
         return widget.get("error")
     return "{} to upgrade, {} to remove".format(
         widget.get("to_upgrade", 0), widget.get("to_remove", 0))
Ejemplo n.º 12
0
 def updates(self, widget):
     result = []
     for t in ["security", "bugfixes", "enhancements", "other"]:
         result.append(str(widget.get(t, 0)))
     return "/".join(result)
Ejemplo n.º 13
0
 def text(self, widget):
     val = widget.get("temp", "n/a")
     transition = widget.get("transition", "")
     if transition and self.show_transition:
         val = "{} {}".format(val, transition)
     return val
Ejemplo n.º 14
0
 def utilization(self, widget):
     return self._format.format(widget.get("utilization", 0.0))
Ejemplo n.º 15
0
 def updates(self, widget):
     if util.format.asbool(self.parameter("sum")):
         return str(sum(map(lambda x: widget.get(x, 0), repos)))
     return "/".join(map(lambda x: str(widget.get(x, 0)), repos))
Ejemplo n.º 16
0
 def state(self, widget):
     return self.threshold_state(widget.get("utilization", 0.0), 70, 80)
Ejemplo n.º 17
0
 def state(self, widget):
     return widget.get("state", None)
Ejemplo n.º 18
0
 def state(self, widget):
     if widget.get("rtt-unreachable"):
         return ["critical"]
     return self.threshold_state(widget.get("rtt-avg"), 1000.0, 2000.0)