[modules/docker_ps] Update to latest API
This commit is contained in:
parent
e270ec55ef
commit
d2a35f7d02
1 changed files with 18 additions and 25 deletions
|
@ -7,44 +7,37 @@ Requires the following python packages:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
|
||||||
import docker
|
import docker
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
from requests.exceptions import ConnectionError
|
from requests.exceptions import ConnectionError
|
||||||
|
|
||||||
import bumblebee.input
|
import core.module
|
||||||
import bumblebee.output
|
import core.widget
|
||||||
import bumblebee.engine
|
import core.decorators
|
||||||
|
|
||||||
|
class Module(core.module.Module):
|
||||||
class Module(bumblebee.engine.Module):
|
@core.decorators.every(seconds=5)
|
||||||
def __init__(self, engine, config):
|
def __init__(self, config):
|
||||||
widgets = bumblebee.output.Widget(full_text=self.status)
|
super().__init__(config, core.widget.Widget(self.docker_info))
|
||||||
super(Module, self).__init__(engine, config, widgets)
|
self.__info = ''
|
||||||
self._status = self.status
|
|
||||||
self._state = self.state
|
|
||||||
|
|
||||||
def update(self, widgets):
|
|
||||||
self._status = self.status
|
|
||||||
self._state = self.state
|
|
||||||
|
|
||||||
def state(self, widget):
|
def state(self, widget):
|
||||||
state = []
|
state = []
|
||||||
status = self.status(widget)
|
if self.__info == 'OK - 0':
|
||||||
if status == 'OK - 0':
|
|
||||||
state.append('warning')
|
state.append('warning')
|
||||||
elif status in ['n/a', 'Daemon off']:
|
elif self.__info in ['n/a', 'daemon off']:
|
||||||
state.append('critical')
|
state.append('critical')
|
||||||
return state
|
return state
|
||||||
|
|
||||||
def status(self, widget):
|
def docker_info(self, widget):
|
||||||
try:
|
try:
|
||||||
cli = docker.DockerClient(base_url='unix://var/run/docker.sock')
|
cli = docker.DockerClient(base_url='unix://var/run/docker.sock')
|
||||||
cli.ping()
|
cli.ping()
|
||||||
except ConnectionError:
|
except ConnectionError:
|
||||||
return 'Daemon off'
|
self.__info = 'daemon off'
|
||||||
except Exception:
|
except Exception:
|
||||||
return 'n/a'
|
self.__info = 'n/a'
|
||||||
return 'OK - {}'.format(len(cli.containers.list(filters={'status': 'running'})))
|
self.__info = 'OK - {}'.format(len(cli.containers.list(filters={'status': 'running'})))
|
||||||
|
return self.__info
|
||||||
|
|
||||||
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue