github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/libpod/events/config.go (about)

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