github.com/aporeto-inc/trireme-lib@v10.358.0+incompatible/common/events.go (about) 1 package common 2 3 import ( 4 "context" 5 ) 6 7 // TriremeSocket is the standard API server Trireme socket path 8 // it is set via ConfigureTriremeSocketPath() and canonicalized with 9 // utils.GetPathOnHostViaProcRoot() at point of use 10 var TriremeSocket = "/var/run/trireme.sock" 11 12 // ConfigureTriremeSocketPath updates the TriremeSocket path 13 func ConfigureTriremeSocketPath(path string) { 14 TriremeSocket = path 15 } 16 17 // PUType defines the PU type 18 type PUType int 19 20 const ( 21 // ContainerPU indicates that this PU is a container 22 ContainerPU PUType = iota 23 // LinuxProcessPU indicates that this is Linux process 24 LinuxProcessPU 25 // WindowsProcessPU indicates that this is Windows process 26 WindowsProcessPU 27 // HostPU is a host wrapping PU 28 HostPU 29 // HostNetworkPU is a PU for a network service in a host 30 HostNetworkPU 31 // KubernetesPU indicates that this is KubernetesPod 32 KubernetesPU 33 // TransientPU PU -- placeholder to run processing. This should not 34 // be inserted in any cache. This is valid only for processing a packet 35 TransientPU 36 ) 37 38 const ( 39 // TriremeCgroupPath is the standard Trireme cgroup path 40 TriremeCgroupPath = "/trireme/" 41 42 // TriremeDockerHostNetwork is the path for Docker HostNetwork container based activations 43 TriremeDockerHostNetwork = "/trireme_docker_hostnet/" 44 ) 45 46 // EventInfo is a generic structure that defines all the information related to a PU event. 47 // EventInfo should be used as a normalized struct container that 48 type EventInfo struct { 49 50 // EventType refers to one of the standard events that Trireme handles. 51 EventType Event `json:"eventtype,omitempty"` 52 53 // PUType is the the type of the PU 54 PUType PUType `json:"putype,omitempty"` 55 56 // The PUID is a unique value for the Processing Unit. Ideally this should be the UUID. 57 PUID string `json:"puid,omitempty"` 58 59 // The Name is a user-friendly name for the Processing Unit. 60 Name string `json:"name,omitempty"` 61 62 // The Executable is the executable name for the Processing Unit. 63 Executable string `json:"executable,omitempty"` 64 65 // Tags represents the set of MetadataTags associated with this PUID. 66 Tags []string `json:"tags,omitempty"` 67 68 // The path for the Network Namespace. 69 NS string `json:"namespace,omitempty"` 70 71 // Cgroup is the path to the cgroup - used for deletes 72 Cgroup string `json:"cgroup,omitempty"` 73 74 // IPs is a map of all the IPs that fully belong to this processing Unit. 75 IPs map[string]string `json:"ipaddressesutype,omitempty"` 76 77 // Services is a list of services of interest - for host control 78 Services []Service `json:"services,omitempty"` 79 80 // The PID is the PID on the system where this Processing Unit is running. 81 PID int32 `json:"pid,omitempty"` 82 83 // HostService indicates that the request is for the root namespace 84 HostService bool `json:"hostservice,omitempty"` 85 86 // AutoPort indicates that the PU will have auto port feature enabled 87 AutoPort bool `json:"autoport,omitempty"` 88 89 // NetworkOnlyTraffic indicates that traffic towards the applications must be controlled. 90 NetworkOnlyTraffic bool `json:"networktrafficonly,omitempty"` 91 92 // Root indicates that this request is coming from a roor user. Its overwritten by the enforcer 93 Root bool `json:"root,omitempty"` 94 } 95 96 // Event represents the event picked up by the monitor. 97 type Event string 98 99 // Values of the events 100 const ( 101 EventStart Event = "start" 102 EventStop Event = "stop" 103 EventUpdate Event = "update" 104 EventCreate Event = "create" 105 EventDestroy Event = "destroy" 106 EventPause Event = "pause" 107 EventUnpause Event = "unpause" 108 EventResync Event = "resync" 109 ) 110 111 var ( 112 // EventMap used for validations 113 EventMap = map[Event]*struct{}{ 114 "start": nil, 115 "stop": nil, 116 "update": nil, 117 "create": nil, 118 "destroy": nil, 119 "pause": nil, 120 "unpause": nil, 121 "resync": nil, 122 } 123 ) 124 125 // EventResponse encapsulate the error response if any. 126 type EventResponse struct { 127 Error string 128 } 129 130 // A EventHandler is type of event handler functions. 131 type EventHandler func(ctx context.Context, event *EventInfo) error 132 133 // A State describes the state of the PU. 134 type State int 135 136 const ( 137 // StateStarted is the state of a started PU. 138 StateStarted State = iota + 1 139 140 // StateStopped is the state of stopped PU. 141 StateStopped 142 143 // StatePaused is the state of a paused PU. 144 StatePaused 145 146 // StateDestroyed is the state of destroyed PU. 147 StateDestroyed 148 149 // StateUnknwown is the state of PU in an unknown state. 150 StateUnknwown 151 )