engine.docker_events: Add filter

This commit is contained in:
Ronald van Zantvoort 2018-02-27 20:10:22 +01:00
parent 7f326c0c17
commit 7ba79eaadc
No known key found for this signature in database
GPG Key ID: D3DE53B7EFF75061

View File

@ -41,7 +41,8 @@ def __virtual__():
def start(docker_url='unix://var/run/docker.sock',
timeout=CLIENT_TIMEOUT,
tag='salt/engines/docker_events'):
tag='salt/engines/docker_events',
filters=None):
'''
Scan for Docker events and fire events
@ -52,10 +53,18 @@ def start(docker_url='unix://var/run/docker.sock',
engines:
- docker_events:
docker_url: unix://var/run/docker.sock
filters:
containers:
- start
- stop
- die
- oom
The config above sets up engines to listen
for events from the Docker daemon and publish
them to the Salt event bus.
For filter reference, see https://docs.docker.com/engine/reference/commandline/events/
'''
if __opts__.get('__role') == 'master':
@ -81,7 +90,7 @@ def start(docker_url='unix://var/run/docker.sock',
client = docker.Client(base_url=docker_url, timeout=timeout)
try:
events = client.events()
events = client.events(filters=filters)
for event in events:
data = salt.utils.json.loads(event.decode(__salt_system_encoding__, errors='replace'))
# https://github.com/docker/cli/blob/master/cli/command/system/events.go#L109