github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/libpod/events/config.go (about)

     1  package events
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/pkg/errors"
     7  )
     8  
     9  // EventerType ...
    10  type EventerType int
    11  
    12  const (
    13  	// LogFile indicates the event logger will be a logfile
    14  	LogFile EventerType = iota
    15  	// Journald indicates journald should be used to log events
    16  	Journald EventerType = iota
    17  	// Null is a no-op events logger. It does not read or write events.
    18  	Null EventerType = iota
    19  )
    20  
    21  // Event describes the attributes of a libpod event
    22  type Event struct {
    23  	// ContainerExitCode is for storing the exit code of a container which can
    24  	// be used for "internal" event notification
    25  	ContainerExitCode int `json:",omitempty"`
    26  	// ID can be for the container, image, volume, etc
    27  	ID string `json:",omitempty"`
    28  	// Image used where applicable
    29  	Image string `json:",omitempty"`
    30  	// Name where applicable
    31  	Name string `json:",omitempty"`
    32  	// Status describes the event that occurred
    33  	Status Status
    34  	// Time the event occurred
    35  	Time time.Time
    36  	// Type of event that occurred
    37  	Type Type
    38  }
    39  
    40  // EventerOptions describe options that need to be passed to create
    41  // an eventer
    42  type EventerOptions struct {
    43  	// EventerType describes whether to use journald or a file
    44  	EventerType string
    45  	// LogFilePath is the path to where the log file should reside if using
    46  	// the file logger
    47  	LogFilePath string
    48  }
    49  
    50  // Eventer is the interface for journald or file event logging
    51  type Eventer interface {
    52  	// Write an event to a backend
    53  	Write(event Event) error
    54  	// Read an event from the backend
    55  	Read(options ReadOptions) error
    56  	// String returns the type of event logger
    57  	String() string
    58  }
    59  
    60  // ReadOptions describe the attributes needed to read event logs
    61  type ReadOptions struct {
    62  	// EventChannel is the comm path back to user
    63  	EventChannel chan *Event
    64  	// Filters are key/value pairs that describe to limit output
    65  	Filters []string
    66  	// FromStart means you start reading from the start of the logs
    67  	FromStart bool
    68  	// Since reads "since" the given time
    69  	Since string
    70  	// Stream is follow
    71  	Stream bool
    72  	// Until reads "until" the given time
    73  	Until string
    74  }
    75  
    76  // Type of event that occurred (container, volume, image, pod, etc)
    77  type Type string
    78  
    79  // Status describes the actual event action (stop, start, create, kill)
    80  type Status string
    81  
    82  const (
    83  	// If you add or subtract any values to the following lists, make sure you also update
    84  	// the switch statements below and the enums for EventType or EventStatus in the
    85  	// varlink description file.
    86  
    87  	// Container - event is related to containers
    88  	Container Type = "container"
    89  	// Image - event is related to images
    90  	Image Type = "image"
    91  	// Pod - event is related to pods
    92  	Pod Type = "pod"
    93  	// System - event is related to Podman whole and not to any specific
    94  	// container/pod/image/volume
    95  	System Type = "system"
    96  	// Volume - event is related to volumes
    97  	Volume Type = "volume"
    98  
    99  	// Attach ...
   100  	Attach Status = "attach"
   101  	// AutoUpdate ...
   102  	AutoUpdate Status = "auto-update"
   103  	// Checkpoint ...
   104  	Checkpoint Status = "checkpoint"
   105  	// Cleanup ...
   106  	Cleanup Status = "cleanup"
   107  	// Commit ...
   108  	Commit Status = "commit"
   109  	// Create ...
   110  	Create Status = "create"
   111  	// Exec ...
   112  	Exec Status = "exec"
   113  	// Exited indicates that a container's process died
   114  	Exited Status = "died"
   115  	// Export ...
   116  	Export Status = "export"
   117  	// History ...
   118  	History Status = "history"
   119  	// Import ...
   120  	Import Status = "import"
   121  	// Init ...
   122  	Init Status = "init"
   123  	// Kill ...
   124  	Kill Status = "kill"
   125  	// LoadFromArchive ...
   126  	LoadFromArchive Status = "loadfromarchive"
   127  	// Mount ...
   128  	Mount Status = "mount"
   129  	// Pause ...
   130  	Pause Status = "pause"
   131  	// Prune ...
   132  	Prune Status = "prune"
   133  	// Pull ...
   134  	Pull Status = "pull"
   135  	// Push ...
   136  	Push Status = "push"
   137  	// Refresh indicates that the system refreshed the state after a
   138  	// reboot.
   139  	Refresh Status = "refresh"
   140  	// Remove ...
   141  	Remove Status = "remove"
   142  	// Renumber indicates that lock numbers were reallocated at user
   143  	// request.
   144  	Renumber Status = "renumber"
   145  	// Restart indicates the target was restarted via an API call.
   146  	Restart Status = "restart"
   147  	// Restore ...
   148  	Restore Status = "restore"
   149  	// Save ...
   150  	Save Status = "save"
   151  	// Start ...
   152  	Start Status = "start"
   153  	// Stop ...
   154  	Stop Status = "stop"
   155  	// Sync ...
   156  	Sync Status = "sync"
   157  	// Tag ...
   158  	Tag Status = "tag"
   159  	// Unmount ...
   160  	Unmount Status = "unmount"
   161  	// Unpause ...
   162  	Unpause Status = "unpause"
   163  	// Untag ...
   164  	Untag Status = "untag"
   165  )
   166  
   167  // EventFilter for filtering events
   168  type EventFilter func(*Event) bool
   169  
   170  var (
   171  	// ErrEventTypeBlank indicates the event log found something done by podman
   172  	// but it isn't likely an event
   173  	ErrEventTypeBlank = errors.New("event type blank")
   174  
   175  	// ErrEventNotFound indicates that the event was not found in the event log
   176  	ErrEventNotFound = errors.New("unable to find event")
   177  )