From bcf0264f993a1e63eed7026e4201dcea60cdf158 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Mon, 31 Oct 2016 15:17:51 +0100 Subject: [PATCH] [modules] Add DNF supervision module Add a module that periodically (by default, once every 30min) calls "dnf updateinfo" and evaluates the results to report the number of bugfixes, enhancements, etc. If there's either too many pending updates, or at least one security update, the module goes critical. --- bumblebee/modules/dnf.py | 80 +++++++++++++++++++++++ bumblebee/themes/solarized-powerline.json | 9 +++ 2 files changed, 89 insertions(+) create mode 100644 bumblebee/modules/dnf.py diff --git a/bumblebee/modules/dnf.py b/bumblebee/modules/dnf.py new file mode 100644 index 0000000..58aea4c --- /dev/null +++ b/bumblebee/modules/dnf.py @@ -0,0 +1,80 @@ +import time +import shlex +import threading +import subprocess + +import bumblebee.module +import bumblebee.util + +def get_dnf_info(obj): + while True: + try: + res = subprocess.check_output(shlex.split("dnf updateinfo")) + except Exception as e: + break + + security = 0 + bugfixes = 0 + enhancements = 0 + other = 0 + for line in res.split("\n"): + if "expiration" in line: continue + elif "ecurity" in line: + for s in str.split(line): + if s.isdigit(): security += int(s) + elif "ugfix" in line: + for s in str.split(line): + if s.isdigit(): bugfixes += int(s) + elif "hancement" in line: + for s in str.split(line): + if s.isdigit(): enhancements += int(s) + else: + for s in str.split(line): + if s.isdigit(): other += int(s) + + obj.set("security", security) + obj.set("bugfixes", bugfixes) + obj.set("enhancements", enhancements) + obj.set("other", other) + + time.sleep(obj.interval()) + + +class Module(bumblebee.module.Module): + def __init__(self, args): + super(Module, self).__init__(args) + self._interval = args[0] if args else 30*60 + self._counter = {} + self._thread = threading.Thread(target=get_dnf_info, args=(self,)) + self._thread.start() + + def interval(self): + return self._interval + + def set(self, what, value): + self._counter[what] = value + + def get(self, what): + return self._counter.get(what, 0) + + def data(self): + result = [] + for t in [ "security", "bugfix", "enhancement", "other" ]: + result.append(str(self.get(t))) + + return "/".join(result) + + def state(self): + total = sum(self._counter.values()) + if total == 0: return "good" + return "default" + + def warning(self): + total = sum(self._counter.values()) + return total > 0 + + def critical(self): + total = sum(self._counter.values()) + return total > 50 or self._counter.get("security", 0) > 0 + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/bumblebee/themes/solarized-powerline.json b/bumblebee/themes/solarized-powerline.json index 0a2ffbe..17c8e85 100644 --- a/bumblebee/themes/solarized-powerline.json +++ b/bumblebee/themes/solarized-powerline.json @@ -35,6 +35,15 @@ "disk": { "prefix": "  " }, + "dnf": { + "prefix": "  ", + "states": { + "good": { + "fg": "#002b36", + "bg": "#859900" + } + } + }, "pasink": { "states": { "muted": {