[modules] critical/warning threshold refactoring

Quite a lot of modules use the "if higher X -> critical, if higher Y ->
warning" idiom now, so extracted that into a common function for reuse.

see #23
This commit is contained in:
Tobi-wan Kenobi 2016-12-11 08:25:54 +01:00
parent edfccd2d31
commit 23d7d53fca
5 changed files with 14 additions and 22 deletions

View file

@ -51,6 +51,13 @@ class Module(object):
name = "{}.{}".format(self.name, name)
return self._config["config"].get(name, default)
def threshold_state(self, value, warn, crit):
if value > float(self.parameter("critical", crit)):
return "critical"
if value > float(self.parameter("warning", warn)):
return "warning"
return None
class Engine(object):
"""Engine for driving the application