summaryrefslogtreecommitdiff
path: root/cmd/podman/shared/events.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2019-03-27 13:50:54 -0500
committerbaude <bbaude@redhat.com>2019-04-24 16:00:04 -0500
commit7bf7c177ab3f67d5de1689842204c258fca083e4 (patch)
tree960fd1365913209fec61e3226b96a6f8bb1fd051 /cmd/podman/shared/events.go
parentd75543fcd2ce87a9b87b8883400f355979004e91 (diff)
downloadpodman-7bf7c177ab3f67d5de1689842204c258fca083e4.tar.gz
podman-7bf7c177ab3f67d5de1689842204c258fca083e4.tar.bz2
podman-7bf7c177ab3f67d5de1689842204c258fca083e4.zip
journald event logging
add the ability for podman to read and write events to journald instead of just a logfile. This can be controlled in libpod.conf with the `events_logger` attribute of `journald` or `file`. The default will be set to `journald`. Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/podman/shared/events.go')
-rw-r--r--cmd/podman/shared/events.go115
1 files changed, 0 insertions, 115 deletions
diff --git a/cmd/podman/shared/events.go b/cmd/podman/shared/events.go
deleted file mode 100644
index c62044271..000000000
--- a/cmd/podman/shared/events.go
+++ /dev/null
@@ -1,115 +0,0 @@
-package shared
-
-import (
- "fmt"
- "strings"
- "time"
-
- "github.com/containers/libpod/libpod/events"
- "github.com/containers/libpod/pkg/util"
- "github.com/pkg/errors"
-)
-
-func generateEventFilter(filter, filterValue string) (func(e *events.Event) bool, error) {
- switch strings.ToUpper(filter) {
- case "CONTAINER":
- return func(e *events.Event) bool {
- if e.Type != events.Container {
- return false
- }
- if e.Name == filterValue {
- return true
- }
- return strings.HasPrefix(e.ID, filterValue)
- }, nil
- case "EVENT", "STATUS":
- return func(e *events.Event) bool {
- return fmt.Sprintf("%s", e.Status) == filterValue
- }, nil
- case "IMAGE":
- return func(e *events.Event) bool {
- if e.Type != events.Image {
- return false
- }
- if e.Name == filterValue {
- return true
- }
- return strings.HasPrefix(e.ID, filterValue)
- }, nil
- case "POD":
- return func(e *events.Event) bool {
- if e.Type != events.Pod {
- return false
- }
- if e.Name == filterValue {
- return true
- }
- return strings.HasPrefix(e.ID, filterValue)
- }, nil
- case "VOLUME":
- return func(e *events.Event) bool {
- if e.Type != events.Volume {
- return false
- }
- return strings.HasPrefix(e.ID, filterValue)
- }, nil
- case "TYPE":
- return func(e *events.Event) bool {
- return fmt.Sprintf("%s", e.Type) == filterValue
- }, nil
- }
- return nil, errors.Errorf("%s is an invalid filter", filter)
-}
-
-func generateEventSinceOption(timeSince time.Time) func(e *events.Event) bool {
- return func(e *events.Event) bool {
- return e.Time.After(timeSince)
- }
-}
-
-func generateEventUntilOption(timeUntil time.Time) func(e *events.Event) bool {
- return func(e *events.Event) bool {
- return e.Time.Before(timeUntil)
-
- }
-}
-
-func parseFilter(filter string) (string, string, error) {
- filterSplit := strings.Split(filter, "=")
- if len(filterSplit) != 2 {
- return "", "", errors.Errorf("%s is an invalid filter", filter)
- }
- return filterSplit[0], filterSplit[1], nil
-}
-
-func GenerateEventOptions(filters []string, since, until string) ([]events.EventFilter, error) {
- var options []events.EventFilter
- for _, filter := range filters {
- key, val, err := parseFilter(filter)
- if err != nil {
- return nil, err
- }
- funcFilter, err := generateEventFilter(key, val)
- if err != nil {
- return nil, err
- }
- options = append(options, funcFilter)
- }
-
- if len(since) > 0 {
- timeSince, err := util.ParseInputTime(since)
- if err != nil {
- return nil, errors.Wrapf(err, "unable to convert since time of %s", since)
- }
- options = append(options, generateEventSinceOption(timeSince))
- }
-
- if len(until) > 0 {
- timeUntil, err := util.ParseInputTime(until)
- if err != nil {
- return nil, errors.Wrapf(err, "unable to convert until time of %s", until)
- }
- options = append(options, generateEventUntilOption(timeUntil))
- }
- return options, nil
-}