1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #25800 from vdemeester/25798-fix-event-actions

Fix 25798 : Allow "partial/prefix" filter for health_status, exec_create and exec_start events
This commit is contained in:
Vincent Demeester 2016-10-28 05:20:49 +02:00 committed by GitHub
commit 10d77b878c
2 changed files with 50 additions and 1 deletions

View file

@ -18,7 +18,7 @@ func NewFilter(filter filters.Args) *Filter {
// Include returns true when the event ev is included by the filters
func (ef *Filter) Include(ev events.Message) bool {
return ef.filter.ExactMatch("event", ev.Action) &&
return ef.matchEvent(ev) &&
ef.filter.ExactMatch("type", ev.Type) &&
ef.matchDaemon(ev) &&
ef.matchContainer(ev) &&
@ -29,6 +29,24 @@ func (ef *Filter) Include(ev events.Message) bool {
ef.matchLabels(ev.Actor.Attributes)
}
func (ef *Filter) matchEvent(ev events.Message) bool {
// #25798 if an event filter contains either health_status, exec_create or exec_start without a colon
// Let's to a FuzzyMatch instead of an ExactMatch.
if ef.filterContains("event", map[string]struct{}{"health_status": {}, "exec_create": {}, "exec_start": {}}) {
return ef.filter.FuzzyMatch("event", ev.Action)
}
return ef.filter.ExactMatch("event", ev.Action)
}
func (ef *Filter) filterContains(field string, values map[string]struct{}) bool {
for _, v := range ef.filter.Get(field) {
if _, ok := values[v]; ok {
return true
}
}
return false
}
func (ef *Filter) matchLabels(attributes map[string]string) bool {
if !ef.filter.Include("label") {
return true

View file

@ -641,6 +641,37 @@ func (s *DockerSuite) TestEventsFilterType(c *check.C) {
c.Assert(len(events), checker.GreaterOrEqualThan, 1, check.Commentf("Events == %s", events))
}
// #25798
func (s *DockerSuite) TestEventsSpecialFiltersWithExecCreate(c *check.C) {
since := daemonUnixTime(c)
runSleepingContainer(c, "--name", "test-container", "-d")
waitRun("test-container")
dockerCmd(c, "exec", "test-container", "echo", "hello-world")
out, _ := dockerCmd(
c,
"events",
"--since", since,
"--until", daemonUnixTime(c),
"--filter",
"event='exec_create: echo hello-world'",
)
events := strings.Split(strings.TrimSpace(out), "\n")
c.Assert(len(events), checker.Equals, 1, check.Commentf(out))
out, _ = dockerCmd(
c,
"events",
"--since", since,
"--until", daemonUnixTime(c),
"--filter",
"event=exec_create",
)
c.Assert(len(events), checker.Equals, 1, check.Commentf(out))
}
func (s *DockerSuite) TestEventsFilterImageInContainerAction(c *check.C) {
since := daemonUnixTime(c)
dockerCmd(c, "run", "--name", "test-container", "-d", "busybox", "true")