From 39f2e6bfea885ff68e4eb132f4554fa66636e002 Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Sun, 19 Apr 2020 14:42:40 +0200 Subject: [PATCH] [modules/http_status] Update to latest API --- modules/contrib/http_status.py | 62 ++++++++++++++++------------------ 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/modules/contrib/http_status.py b/modules/contrib/http_status.py index 9853753..7230987 100644 --- a/modules/contrib/http_status.py +++ b/modules/contrib/http_status.py @@ -3,66 +3,64 @@ """Display HTTP status code Parameters: - * http_status.label: Prefix label (optional) - * http_status.target: Target to retrieve the HTTP status from - * http_status.expect: Expected HTTP status + * http__status.label: Prefix label (optional) + * http__status.target: Target to retrieve the HTTP status from + * http__status.expect: Expected HTTP status """ from requests import head import psutil -import bumblebee.input -import bumblebee.output -import bumblebee.engine -class Module(bumblebee.engine.Module): +import core.module +import core.widget +import core.decorators + +class Module(core.module.Module): UNK = 'UNK' - def __init__(self, engine, config): - widget = bumblebee.output.Widget(full_text=self.output) - super(Module, self).__init__(engine, config, widget) + @core.decorators.every(seconds=30) + def __init__(self, config): + super().__init__(config, core.widget.Widget(self.output)) - self._label = self.parameter('label') - self._target = self.parameter('target') - self._expect = self.parameter('expect', '200') - self._status = self.getStatus() - self._output = self.getOutput() + self.__label = self.parameter('label') + self.__target = self.parameter('target') + self.__expect = self.parameter('expect', '200') def labelize(self, s): - if self._label is None: + if self.__label is None: return s - return '{}: {}'.format(self._label, s) + return '{}: {}'.format(self.__label, s) def getStatus(self): try: - res = head(self._target) - except Exception: + res = head(self.__target) + except Exception as e: + print(e) return self.UNK else: status = str(res.status_code) - self._status = status return status def getOutput(self): - if self._status == self._expect: - return self.labelize(self._status) + if self.__status == self.__expect: + return self.labelize(self.__status) else: - reason = ' != {}'.format(self._expect) - return self.labelize('{}{}'.format(self._status, reason)) + reason = ' != {}'.format(self.__expect) + return self.labelize('{}{}'.format(self.__status, reason)) def output(self, widget): - return self._output + return self.__output - def update(self, widgets): - self.getStatus() - self._output = self.getOutput() + def update(self): + self.__status = self.getStatus() + self.__output = self.getOutput() def state(self, widget): - if self._status == self.UNK: + if self.__status == self.UNK: return 'warning' - if self._status != self._expect: + if self.__status != self.__expect: return 'critical' - return self._output - + return self.__output # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4