github.com/containers/podman/v4@v4.9.4/libpod/events/config.go (about)

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