From 1e2f1243f06bc9cb381103ab2a60257d7fb2da09 Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 17 Mar 2020 23:06:43 +0100 Subject: [PATCH] [module] improvement of docker_ps by adding states Added state to the module to indicate when no containers are running, vs daemon off, container running --- bumblebee/modules/docker_ps.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/bumblebee/modules/docker_ps.py b/bumblebee/modules/docker_ps.py index c36c0e7..073c140 100644 --- a/bumblebee/modules/docker_ps.py +++ b/bumblebee/modules/docker_ps.py @@ -21,14 +21,25 @@ import bumblebee.engine class Module(bumblebee.engine.Module): def __init__(self, engine, config): - widget = bumblebee.output.Widget(full_text=self.status) - super(Module, self).__init__(engine, config, widget) + widgets = bumblebee.output.Widget(full_text=self.status) + super(Module, self).__init__(engine, config, widgets) self._status = self.status + self._state = self.state def update(self, widgets): self._status = self.status + self._state = self.state - def status(self, _): + def state(self, widget): + state = [] + status = self.status(widget) + if status == "OK - 0": + state.append("warning") + elif status in ["n/a", "Daemon off"]: + state.append("critical") + return state + + def status(self, widget): try: cli = docker.DockerClient(base_url='unix://var/run/docker.sock') cli.ping()