Skip to content

Commit 9a163f1

Browse files
authored
Merge pull request #77 from yubiuser/development
v2.2.0
2 parents afe2f8f + e73eb7c commit 9a163f1

File tree

9 files changed

+177
-20
lines changed

9 files changed

+177
-20
lines changed

.devcontainer/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax=docker/dockerfile:1
12
ARG alpine_version=3.19
23
ARG golang_version=1.21
34

.github/pushover.png

79.6 KB
Loading

.github/workflows/ghcr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797
digest="${{ steps.build.outputs.digest }}"
9898
touch "/tmp/digests/${digest#sha256:}"
9999
- name: Upload digest
100-
uses: actions/[email protected].0
100+
uses: actions/[email protected].1
101101
with:
102102
name: digests-${{ env.PLATFORM_PAIR }}
103103
path: /tmp/digests/*
@@ -116,7 +116,7 @@ jobs:
116116
packages: write
117117
steps:
118118
- name: Download digests
119-
uses: actions/[email protected].1
119+
uses: actions/[email protected].2
120120
with:
121121
path: /tmp/digests
122122
pattern: digests-*

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax=docker/dockerfile:1
12
ARG alpine_version=3.19
23
ARG golang_version=1.21
34

Readme.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ services:
6060
MAIL_PASSWORD: 'PASSWORD'
6161
MAIL_PORT: 587
6262
MAIL_HOST: '[email protected]'
63-
FILTER: 'event=start,event=stop,type=container'
63+
FILTER: 'type=container'
64+
EXCLUDE: 'Action=exec_start,Action=exec_die,Action=exec_create'
6465
DELAY: '500ms'
6566
LOG_LEVEL: 'info'
6667
SERVER_TAG: ''
@@ -100,5 +101,20 @@ Configurations can use the CLI flags or environment variables. The table below o
100101
| `--mailport` | `MAIL_PORT` | `587` | |
101102
| `--mailhost` | `MAIL_HOST` | `""` | `[email protected]` |
102103
| `--filter` | `FILTER` | `""` | Filter events. Uses the same filters as `docker events` (see [here](https://docs.docker.com/engine/reference/commandline/events/#filter)) |
104+
| `--exclude` | `EXCLUDE` | `""` | Exclude events from being reported |
103105
| `--loglevel` | `LOG_LEVEL` | `"info"`| Use `debug` for more verbose logging |
104106
| `--servertag` | `SERVER_TAG` | `""` | Prefix to include in the title of notifications. Useful when running docker-event-monitors on multiple machines |
107+
108+
### Filter and exclude events
109+
110+
Docker Event Monitor offers two options that sound alike, but aren't: `Filter` and `Exclude`.
111+
By default, the docker system event stream will contain **all** events. The `filter` option is a docker built-in function that allows filtering certain events from the stream. It's a **positive** filter only, meaning it defines which events will pass the filter. The possible filters and syntax are described [here](https://docs.docker.com/engine/reference/commandline/events/#filter).
112+
113+
However, docker has no native support for **negative** filter (let all events pass, except those defined) - so I added it. To distingush it from postive filters, this option is named `exclude`.
114+
Based on how it is implemented, **exclusion happens after filtering**. Together you can create configurations like filtering events of type container, but exclude reporting for a specific container or certain actions.
115+
116+
The syntax for exclusion is also `key=value`. But as the exclusion happens on the data contained in the reported event, the `key`s are different from those used for `filtering`. E.g. instead of `event`, `Action` is used. To figure out which keys to use, it's best to enable debug logging and carefully inspect the event's data structure. A typical container event looks like
117+
118+
```
119+
{Status:"start", ID:"b4a2a54c4487ddc0bbae006e48ae970d4b2fa4b9fd2bef390d8875cb6158c888", From:"squidfunk/mkdocs-material", Type:"container", Action:"start", Actor:events.Actor{ID:"b4a2a54c4487ddc0bbae006e48ae970d4b2fa4b9fd2bef390d8875cb6158c888", Attributes:map[string]string{"com.docker.compose.config-hash":"cd464ac038ddc9ee7a53599aaa9db6a85a01683a9a08a749582d0c0b8c0a595d", "com.docker.compose.container-number":"1", "com.docker.compose.depends_on":"", "com.docker.compose.image":"sha256:feb8ba83cb7272046551c69a58ec03ecda2306410a07844d22c166e810034aa6", "com.docker.compose.oneoff":"False", "com.docker.compose.project":"mkdocs-material", "com.docker.compose.project.config_files":"/home/pi/docker/mkdocs-material/docker-compose.yml", "com.docker.compose.project.working_dir":"/home/pi/docker/mkdocs-material", "com.docker.compose.service":"mkdocs-material", "com.docker.compose.version":"2.24.5", "image":"squidfunk/mkdocs-material", "name":"mkdocs-material", "org.opencontainers.image.created":"2024-02-10T06:18:18.743Z", "org.opencontainers.image.description":"Documentation that simply works", "org.opencontainers.image.licenses":"MIT", "org.opencontainers.image.revision":"a6286ef3ac3407e8b6c985cf0571fc0e2caa6f5b", "org.opencontainers.image.source":"https://github.com/squidfunk/mkdocs-material", "org.opencontainers.image.title":"mkdocs-material", "org.opencontainers.image.url":"https://github.com/squidfunk/mkdocs-material", "org.opencontainers.image.version":"9.5.9"}}, Scope:"local", Time:1708201602, TimeNano:1708201602805856956}
120+
```

src/docker-event-monitor.go

Lines changed: 123 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"fmt"
56
"io"
67
"net/http"
78
"net/smtp"
@@ -18,6 +19,7 @@ import (
1819
"github.com/docker/docker/api/types/filters"
1920
"github.com/docker/docker/client"
2021
"github.com/gregdel/pushover"
22+
"github.com/oleiade/reflections"
2123

2224
"github.com/rs/zerolog"
2325

@@ -42,6 +44,8 @@ type args struct {
4244
Delay time.Duration `arg:"env:DELAY" default:"500ms" help:"Delay before next message is send"`
4345
FilterStrings []string `arg:"env:FILTER,--filter,separate" help:"Filter docker events using Docker syntax."`
4446
Filter map[string][]string `arg:"-"`
47+
ExcludeStrings []string `arg:"env:EXCLUDE,--exclude,separate" help:"Exclude docker events using Docker syntax."`
48+
Exclude map[string][]string `arg:"-"`
4549
LogLevel string `arg:"env:LOG_LEVEL" default:"info" help:"Set log level. Use debug for more logging."`
4650
ServerTag string `arg:"env:SERVER_TAG" help:"Prefix to include in the title of notifications. Useful when running docker-event-monitors on multiple machines."`
4751
Version bool `arg:"-v" help:"Print version information."`
@@ -57,8 +61,8 @@ var glb_arguments args
5761
var (
5862
version string = "n/a"
5963
commit string = "n/a"
60-
date string
61-
gitdate string
64+
date string = "0"
65+
gitdate string = "0"
6266
branch string = "n/a"
6367
)
6468

@@ -140,7 +144,8 @@ func main() {
140144
Str("Delay", glb_arguments.Delay.String()).
141145
Str("Loglevel", glb_arguments.LogLevel).
142146
Str("ServerTag", glb_arguments.ServerTag).
143-
Str("Filter", strings.Join(glb_arguments.FilterStrings, " ")),
147+
Str("Filter", strings.Join(glb_arguments.FilterStrings, " ")).
148+
Str("Exclude", strings.Join(glb_arguments.ExcludeStrings, " ")),
144149
).
145150
Dict("version", zerolog.Dict().
146151
Str("Version", version).
@@ -176,6 +181,16 @@ func main() {
176181
case err := <-errs:
177182
logger.Fatal().Err(err).Msg("")
178183
case event := <-event_chan:
184+
// if logging level is Debug, log the event
185+
logger.Debug().Msgf("%#v", event)
186+
187+
// Check if event should be exlcuded from reporting
188+
if len(glb_arguments.Exclude) > 0 {
189+
logger.Debug().Msg("Performing check for event exclusion")
190+
if excludeEvent(event) {
191+
break //breaks out of the select and waits for the next event to arrive
192+
}
193+
}
179194
processEvent(&event)
180195
}
181196
}
@@ -185,6 +200,7 @@ func buildStartupMessage(timestamp time.Time) string {
185200
var startup_message_builder strings.Builder
186201

187202
startup_message_builder.WriteString("Docker event monitor started at " + timestamp.Format(time.RFC1123Z) + "\n")
203+
startup_message_builder.WriteString("Docker event monitor version: " + version + "\n")
188204

189205
if glb_arguments.Pushover {
190206
startup_message_builder.WriteString("Notify via Pushover, using API Token " + glb_arguments.PushoverAPIToken + " and user key " + glb_arguments.PushoverUserKey)
@@ -217,6 +233,18 @@ func buildStartupMessage(timestamp time.Time) string {
217233
startup_message_builder.WriteString("\nServerTag: none")
218234
}
219235

236+
if len(glb_arguments.FilterStrings) > 0 {
237+
startup_message_builder.WriteString("\nFilterStrings: " + strings.Join(glb_arguments.FilterStrings, " "))
238+
} else {
239+
startup_message_builder.WriteString("\nFilterStrings: none")
240+
}
241+
242+
if len(glb_arguments.ExcludeStrings) > 0 {
243+
startup_message_builder.WriteString("\nExcludeStrings: " + strings.Join(glb_arguments.ExcludeStrings, " "))
244+
} else {
245+
startup_message_builder.WriteString("\nExcludeStrings: none")
246+
}
247+
220248
return startup_message_builder.String()
221249
}
222250

@@ -360,6 +388,77 @@ func sendPushover(message string, title string) {
360388

361389
}
362390

391+
func excludeEvent(event events.Message) bool {
392+
// Checks if any of the exclusion criteria matches the event
393+
394+
var ActorID string
395+
if len(event.Actor.ID) > 0 {
396+
if strings.HasPrefix(event.Actor.ID, "sha256:") {
397+
ActorID = strings.TrimPrefix(event.Actor.ID, "sha256:")[:8] //remove prefix + limit ActorID legth
398+
} else {
399+
ActorID = event.Actor.ID[:8] //limit ActorID legth
400+
}
401+
}
402+
403+
// getting the values of the events struct
404+
// first check if any exclusion key matches a key in the event message
405+
for key, values := range glb_arguments.Exclude {
406+
fieldExists, err := reflections.HasField(event, key)
407+
if err != nil {
408+
logger.Error().Err(err).
409+
Str("ActorID", ActorID).
410+
Str("Key", key).
411+
Msg("Error while checking existence of event field")
412+
}
413+
if fieldExists {
414+
// key matched, check if any value matches
415+
logger.Debug().
416+
Str("ActorID", ActorID).
417+
Msgf("Exclusion key \"%s\" matched, checking values", key)
418+
419+
eventValue, err := reflections.GetField(event, key)
420+
if err != nil {
421+
logger.Error().Err(err).
422+
Str("ActorID", ActorID).
423+
Str("Key", key).
424+
Msg("Error while getting event field's value")
425+
}
426+
427+
logger.Debug().
428+
Str("ActorID", ActorID).
429+
Msgf("Event's value for key \"%s\" is \"%s\"", key, eventValue)
430+
431+
//GetField returns an interface which needs to be converted to string
432+
strEventValue := fmt.Sprintf("%v", eventValue)
433+
434+
for _, value := range values {
435+
// comparing the prefix to be able to filter actions like "exec_XXX: YYYY" which use a
436+
// special, dynamic, syntax
437+
// see https://github.com/moby/moby/blob/bf053be997f87af233919a76e6ecbd7d17390e62/api/types/events/events.go#L74-L81
438+
439+
if strings.HasPrefix(strEventValue, value) {
440+
logger.Debug().
441+
Str("ActorID", ActorID).
442+
Msgf("Event excluded based on exclusion setting \"%s=%s\"", key, value)
443+
return true
444+
}
445+
}
446+
logger.Debug().
447+
Str("ActorID", ActorID).
448+
Msgf("Exclusion key \"%s\" matched, but values did not match", key)
449+
} else {
450+
logger.Debug().
451+
Str("ActorID", ActorID).
452+
Msgf("Exclusion key \"%s\" did not match", key)
453+
454+
}
455+
}
456+
logger.Debug().
457+
Str("ActorID", ActorID).
458+
Msg("Exclusion settings didn't match, not excluding event")
459+
return false
460+
}
461+
363462
func processEvent(event *events.Message) {
364463
// the Docker Events endpoint will return a struct events.Message
365464
// https://pkg.go.dev/github.com/docker/docker/api/types/events#Message
@@ -373,12 +472,12 @@ func processEvent(event *events.Message) {
373472
// Finishing this function not before a certain time before draining the next event from the event channel in main() solves the issue
374473
timer := time.NewTimer(glb_arguments.Delay)
375474

376-
// if logging level is Debug, log the event
377-
logger.Debug().Msgf("%#v", event)
378-
379-
//some events don't return Actor.ID, Actor.Attributes["image"] or Actor.Attributes["name"]
380-
if len(event.Actor.ID) > 0 && strings.HasPrefix(event.Actor.ID, "sha256:") {
381-
ActorID = strings.TrimPrefix(event.Actor.ID, "sha256:")[:8] //remove prefix + limit ActorID legth
475+
if len(event.Actor.ID) > 0 {
476+
if strings.HasPrefix(event.Actor.ID, "sha256:") {
477+
ActorID = strings.TrimPrefix(event.Actor.ID, "sha256:")[:8] //remove prefix + limit ActorID legth
478+
} else {
479+
ActorID = event.Actor.ID[:8] //limit ActorID legth
480+
}
382481
}
383482
if len(event.Actor.Attributes["image"]) > 0 {
384483
ActorImage = event.Actor.Attributes["image"]
@@ -461,6 +560,7 @@ func processEvent(event *events.Message) {
461560
func parseArgs() {
462561
parser := arg.MustParse(&glb_arguments)
463562

563+
// Parse (include) filters
464564
glb_arguments.Filter = make(map[string][]string)
465565

466566
for _, filter := range glb_arguments.FilterStrings {
@@ -473,6 +573,20 @@ func parseArgs() {
473573
glb_arguments.Filter[key] = append(glb_arguments.Filter[key], val)
474574
}
475575

576+
// Parse exclude filters
577+
glb_arguments.Exclude = make(map[string][]string)
578+
579+
for _, exclude := range glb_arguments.ExcludeStrings {
580+
pos := strings.Index(exclude, "=")
581+
if pos == -1 {
582+
parser.Fail("each filter should be of the form key=value")
583+
}
584+
//trim whitespaces and make first letter uppercase for key (to match events.Message key format)
585+
key := cases.Title(language.English, cases.Compact).String(strings.TrimSpace(exclude[:pos]))
586+
val := exclude[pos+1:]
587+
glb_arguments.Exclude[key] = append(glb_arguments.Exclude[key], val)
588+
}
589+
476590
}
477591

478592
func configureLogger(LogLevel string) {

src/go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ go 1.21
44

55
require (
66
github.com/alexflint/go-arg v1.4.3
7-
github.com/docker/docker v25.0.2+incompatible
7+
github.com/docker/docker v25.0.3+incompatible
88
github.com/gregdel/pushover v1.3.0
9-
github.com/rs/zerolog v1.31.0
9+
github.com/oleiade/reflections v1.0.1
10+
github.com/rs/zerolog v1.32.0
1011
golang.org/x/text v0.14.0
1112
)
1213

src/go.sum

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
1717
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1818
github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=
1919
github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
20-
github.com/docker/docker v25.0.2+incompatible h1:/OaKeauroa10K4Nqavw4zlhcDq/WBcPMc5DbjOGgozY=
21-
github.com/docker/docker v25.0.2+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
20+
github.com/docker/docker v25.0.3+incompatible h1:D5fy/lYmY7bvZa0XTZ5/UJPljor41F+vdyJG5luQLfQ=
21+
github.com/docker/docker v25.0.3+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
2222
github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=
2323
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
2424
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
@@ -53,6 +53,8 @@ github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
5353
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
5454
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
5555
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
56+
github.com/oleiade/reflections v1.0.1 h1:D1XO3LVEYroYskEsoSiGItp9RUxG6jWnCVvrqH0HHQM=
57+
github.com/oleiade/reflections v1.0.1/go.mod h1:rdFxbxq4QXVZWj0F+e9jqjDkc7dbp97vkRixKo2JR60=
5658
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
5759
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
5860
github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM=
@@ -62,12 +64,13 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
6264
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
6365
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
6466
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
65-
github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A=
66-
github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
67+
github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0=
68+
github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
6769
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
6870
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
6971
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
7072
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
73+
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
7174
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
7275
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
7376
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=

src/makefile

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
1-
BINARY_NAME := docker-event-monitor
1+
BINARY_NAME = docker-event-monitor
2+
3+
# using the ?= assignment operator: Assign only if variable is not set (e.g. via environment) yet
4+
# this allows overwriting via CI
25
GIT_COMMIT ?= $(shell git --no-pager describe --always --abbrev=8 --dirty)
36
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
47
GIT_VERSION ?= $(shell git --no-pager describe --tags --always --abbrev=8 --dirty)
58
GIT_DATE ?= $(shell git --no-pager show --date=short --format=%at --name-only | head -n 1)
9+
10+
# GIT_TAG is only set when a CI build is trigged via release tag
611
ifdef GIT_TAG
712
override GIT_VERSION = ${GIT_TAG}
813
endif
9-
DATE := $(shell date +%s)
14+
15+
# in case 'git' or the repo is not available, GIT_XXX is set empty via the assignment above
16+
# so we set them explicitly
17+
ifeq ($(GIT_DATE),)
18+
GIT_DATE = 0
19+
endif
20+
ifeq ($(GIT_COMMIT),)
21+
GIT_COMMIT = "n/a"
22+
endif
23+
ifeq ($(GIT_BRANCH),)
24+
GIT_BRANCH = "n/a"
25+
endif
26+
ifeq ($(GIT_VERSION),)
27+
GIT_VERSION = "n/a"
28+
endif
29+
30+
DATE = $(shell date +%s)
1031
build:
1132
CGO_ENABLED=0 go build -ldflags "-s -w -X 'main.version=${GIT_VERSION}' -X 'main.gitdate=${GIT_DATE}' -X 'main.date=${DATE}' -X 'main.commit=${GIT_COMMIT}' -X 'main.branch=${GIT_BRANCH}'" -o=${BINARY_NAME} docker-event-monitor.go

0 commit comments

Comments
 (0)