Skip to content

Commit

Permalink
Feature #2: filter events by image name
Browse files Browse the repository at this point in the history
  • Loading branch information
int128 committed Dec 14, 2015
1 parent b1da6f5 commit 4398de0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ curl -O https://raw.githubusercontent.com/int128/slack-docker/master/docker-comp
docker-compose up -d
```

### Filter events by image name

By default all events are sent to Slack, but events can be filtered by the environment variable `image_regexp` as follows:

```sh
docker run -d -e image_regexp='node:.*' -e webhook=URL -v /var/run/docker.sock:/var/run/docker.sock int128/slack-docker
```


## Contribution

Expand Down
9 changes: 7 additions & 2 deletions app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ Slack =
fields: fields
.fail (e) -> console.error e

EventFilter =
_imageRegExp: new RegExp(process.env.image_regexp)
satisfy: (event) ->
@_imageRegExp.test event.from

EventProcessor =
_containers: {}
_start: (event) ->
Expand Down Expand Up @@ -55,8 +60,8 @@ Docker.getVersion().then (version) ->
console.info version
Docker.events().then (stream) ->
stream.pipe EventStream.map (event) ->
console.info "#{event.time}: #{event.status}: #{event.id} from #{event.from}"
EventProcessor.handle event
if EventFilter.satisfy event
EventProcessor.handle event
.fail (e) ->
console.error e

0 comments on commit 4398de0

Please sign in to comment.