func (spd SecurityProfileDeletedEvent) GetLogEntry() *logrus.Entry {
	return logrus.WithFields(logrus.Fields{
		"name":      spd.Profile.Name,
		"namespace": spd.Profile.Namespace,
		"cluster":   spd.Profile.ClusterName,
		"kind":      spd.Profile.Kind,
	})
}
GetLogEntry - Returns the event logrus fields
package model
import (
	"fmt"
	"sync"
	"time"
	"docker.io/go-docker/api/types"
	"docker.io/go-docker/api/types/container"
	"docker.io/go-docker/api/types/strslice"
	"github.com/docker/go-connections/nat"
	"github.com/sirupsen/logrus"
	v1 "github.com/Gui774ume/network-security-probe/pkg/k8s/apis/securityprobe.datadoghq.com/v1"
	"github.com/Gui774ume/network-security-probe/pkg/model/kernel"
)
type EventType string
var (
	UnknownEventType EventType = "Unknown"
	AnyEventType EventType = "Any"
	ContainerCreatedEventType EventType = "ContainerCreated"
	ContainerRunningEventType EventType = "ContainerRunning"
	ContainerExitedEventType EventType = "ContainerExit"
	ContainerDestroyedEventType EventType = "ContainerDestroyed"
	ContainerExecEventType EventType = "ContainerExec"
	ContainerAttachEventType EventType = "ContainerAttach"
	ContainerConnectEventType EventType = "ContainerConnect"
	ContainerDisconnectEventType EventType = "ContainerDisconnect"
	FlowType EventType = "Flow"
	NewNetDeviceType EventType = "NewNetDevice"
	DeviceNetnsUpdateType EventType = "DeviceNetnsUpdate"
	SecurityProfileCreatedType EventType = "SecurityProfileCreated"
	SecurityProfileUpdatedType EventType = "SecurityProfileUpdated"
	SecurityProfileDeletedType EventType = "SecurityProfileDeleted"
	NetworkAlertType EventType = "NetworkAlert"
	DNSQueryType EventType = "DNSQuery"
	DNSResponseType EventType = "DNSResponse"
	ForkEventType EventType = "Fork"
	ExecEventType EventType = "Exec"
	ExitEventType EventType = "Exit"
)
type ProbeEvent interface {
	GetPid() uint32
	GetNetns() uint64
	GetLogEntry() *logrus.Entry
	GetMessage() string
	GetTimestamp() time.Time
	GetEventType() EventType
	GetEventMonitorName() MonitorName
	SetProcessCacheData(entry *ProcessCacheEntry)
	GetProcessCacheData() *ProcessCacheEntry
	SetNamespaceCacheData(entry *NamespaceCacheEntry)
	GetNamespaceCacheData() *NamespaceCacheEntry
}
const (
	DeviceRegistration = iota
	DeviceUnregistration
	DeviceFree
)
type EventBase struct {
	ProcessData      *ProcessCacheEntry   `json:"process_data,omitempty"`
	NamespaceData    *NamespaceCacheEntry `json:"namespace_data,omitempty"`
	EventType        EventType            `json:"event_type"`
	EventMonitorName MonitorName          `json:"event_monitor_name"`
	Timestamp        time.Time            `json:"timestamp"`
	TTYName          string               `json:"tty_name"`
}
func (eb *EventBase) GetTimestamp() time.Time {
	return eb.Timestamp
}
func (eb *EventBase) GetEventType() EventType {
	return eb.EventType
}
func (eb *EventBase) GetEventMonitorName() MonitorName {
	return eb.EventMonitorName
}
func (eb *EventBase) SetProcessCacheData(pce *ProcessCacheEntry) {
	eb.ProcessData = pce
}
func (eb *EventBase) GetProcessCacheData() *ProcessCacheEntry {
	return eb.ProcessData
}
func (eb *EventBase) SetNamespaceCacheData(nce *NamespaceCacheEntry) {
	eb.NamespaceData = nce
}
func (eb *EventBase) GetNamespaceCacheData() *NamespaceCacheEntry {
	return eb.NamespaceData
}
type ProcessCacheEntry struct {
	sync.RWMutex
	BinaryPath           string             `json:"binary_path"`
	Ppid                 uint32             `json:"ppid,omitempty"`
	Parent               *ProcessCacheEntry `json:"parent,omitempty"`
	Pid                  uint32             `json:"pid,omitempty"`
	TTYName              string             `json:"tty_name,omitempty"`
	ExecveTime           *time.Time         `json:"execve_time,omitempty"`
	ForkTime             *time.Time         `json:"fork_time,omitempty"`
	ForkThresholdReached bool               `json:"-"`
	ExitTime             *time.Time         `json:"exit_time,omitempty"`
}
var MultiprocessingThreshold = 100 * time.Millisecond
func (pce *ProcessCacheEntry) IsExecveResolved(timestamp time.Time, updateState bool) bool {
	if updateState {
		pce.Lock()
		defer pce.Unlock()
	} else {
		pce.RLock()
		defer pce.RUnlock()
	}
	if pce.ForkTime == nil || pce.ForkThresholdReached {
		return true
	}
	if pce.ExecveTime != nil && pce.ForkTime.Before(*pce.ExecveTime) {
		if updateState {
			pce.ForkThresholdReached = true
		}
		return true
	}
	if pce.ForkTime.Add(MultiprocessingThreshold).Before(timestamp) {
		if updateState {
			pce.ForkThresholdReached = true
		}
		return true
	}
	return false
}
func (pce *ProcessCacheEntry) HasQuickExitTime() bool {
	if pce.ExitTime == nil || pce.ForkTime == nil {
		return false
	}
	return pce.ForkTime.Add(MultiprocessingThreshold).After(*pce.ExitTime)
}
func (pce *ProcessCacheEntry) IsInCache() bool {
	pce.RLock()
	defer pce.RUnlock()
	inCache := pce.ExecveTime != nil || pce.ForkTime != nil
	return inCache
}
type NamespaceCacheEntry struct {
	sync.RWMutex
	Name      string     `json:"name"`
	ID        string     `json:"id"`
	Base      string     `json:"base"`
	Digest    string     `json:"digest"`
	Pod       string     `json:"pod"`
	Namespace string     `json:"namespace"`
	StartTime *time.Time `json:"start_time"`
	ExitTime  *time.Time `json:"-"`
}
func (nce *NamespaceCacheEntry) IsInCache() bool {
	nce.RLock()
	inCache := len(nce.Name) > 0
	nce.RUnlock()
	return inCache
}
type Metadata struct {
	Pidns        uint64   `json:"pidns"`
	Netns        uint64   `json:"netns"`
	TimestampRaw uint64   `json:"-"`
	TTYNameRaw   [64]byte `json:"-"`
	PID          uint32   `json:"pid"`
	TID          uint32   `json:"tid"`
}
func (m Metadata) getEntry() *logrus.Entry {
	return logrus.WithFields(logrus.Fields{
		"pidns": m.Pidns,
		"netns": m.Netns,
		"pid":   m.PID,
		"tid":   m.TID,
	})
}
func (m Metadata) String() string {
	return fmt.Sprintf("pidns:%v timestampRaw:%v ttyNameRaw:%v pid:%v tid:%v", m.Pidns, m.TimestampRaw, m.TTYNameRaw, m.PID, m.TID)
}
type Device struct {
	DeviceFlag  int32    `json:"device_flag"`
	Ifindex     int32    `json:"ifindex"`
	Group       int32    `json:"group"`
	PeerIfindex int32    `json:"peer_ifindex"`
	Netns       uint64   `json:"netns"`
	NameRaw     [16]byte `json:"-"`
}
type DeviceEventRaw struct {
	EventFlag uint64   `json:"event_flag"`
	Metadata  Metadata `json:"metadata"`
	Device    Device   `json:"device"`
	Peer      Device   `json:"peer"`
}
type DeviceEvent struct {
	EventBase
	*DeviceEventRaw
	DeviceName string `json:"device_name"`
	PeerName   string `json:"peer_name"`
}
func (nde *DeviceEvent) GetPid() uint32 {
	return nde.DeviceEventRaw.Metadata.PID
}
func (nde *DeviceEvent) GetNetns() uint64 {
	return nde.DeviceEventRaw.Metadata.Netns
}
func (nde *DeviceEvent) GetLogEntry() *logrus.Entry {
	entry := nde.Metadata.getEntry()
	entry.WithFields(logrus.Fields{
		"tty": nde.TTYName,
	})
	if nde.Device.PeerIfindex == 0 {
		return entry.WithFields(logrus.Fields{
			"name":    nde.DeviceName,
			"netns":   nde.Device.Netns,
			"ifindex": nde.Device.Ifindex,
		})
	}
	return entry.WithFields(logrus.Fields{
		"device_name":    nde.DeviceName,
		"device_netns":   nde.Device.Netns,
		"device_ifindex": nde.Device.Ifindex,
		"peer_name":      nde.PeerName,
		"peer_netns":     nde.Peer.Netns,
		"peer_ifindex":   nde.Peer.Ifindex,
	})
}
func (nde *DeviceEvent) GetMessage() string {
	switch nde.EventFlag {
	case DeviceRegistration:
		if nde.Device.PeerIfindex == 0 {
			return "New network device registered"
		}
		return "New veth pair registered"
	case DeviceUnregistration:
		return "Device unregistered"
	case DeviceFree:
		return "Device structure freed"
	default:
		return fmt.Sprintf("Unknown event %v", nde.EventFlag)
	}
}
type DeviceNetnsUpdateRaw struct {
	Metadata Metadata `json:"metadata"`
	Device   Device   `json:"device"`
	NewNetns uint64   `json:"new_netns"`
}
type DeviceNetnsUpdate struct {
	EventBase
	*DeviceNetnsUpdateRaw
	DeviceName string `json:"device_name"`
}
func (dnu *DeviceNetnsUpdate) GetPid() uint32 {
	return dnu.DeviceNetnsUpdateRaw.Metadata.PID
}
func (dnu *DeviceNetnsUpdate) GetNetns() uint64 {
	return dnu.DeviceNetnsUpdateRaw.Metadata.Netns
}
func (dnu *DeviceNetnsUpdate) GetLogEntry() *logrus.Entry {
	entry := dnu.Metadata.getEntry()
	entry.WithFields(logrus.Fields{
		"tty": dnu.TTYName,
	})
	return entry.WithFields(logrus.Fields{
		"name":      dnu.DeviceName,
		"old_netns": dnu.Device.Netns,
		"new_netns": dnu.NewNetns,
		"ifindex":   dnu.Device.Ifindex,
	})
}
func (dnu *DeviceNetnsUpdate) GetMessage() string {
	return "Network device netns update"
}
type FlowRaw struct {
	Metadata Metadata  `json:"metadata"`
	AddrRaw  [2]uint64 `json:"-"`
	Port     uint16    `json:"port"`
	Family   uint16    `json:"family"`
}
type Flow struct {
	EventBase
	*FlowRaw
	Addr string `json:"addr"`
}
func (f *Flow) GetPid() uint32 {
	return f.FlowRaw.Metadata.PID
}
func (f *Flow) GetNetns() uint64 {
	return f.FlowRaw.Metadata.Netns
}
func (f *Flow) GetLogEntry() *logrus.Entry {
	entry := f.Metadata.getEntry()
	entry.WithFields(logrus.Fields{
		"tty": f.TTYName,
	})
	return entry.WithFields(logrus.Fields{
		"addr":   f.Addr,
		"port":   f.Port,
		"family": f.Family,
	})
}
func (f *Flow) GetMessage() string {
	return "Network flow registered"
}
type ContainerEvent struct {
	EventBase
	InitPid             uint32                 `json:"init_pid"`
	Pidns               uint64                 `json:"pidns"`
	Cgroup              uint64                 `json:"cgroup"`
	Mntns               uint64                 `json:"mntns"`
	Netns               uint64                 `json:"netns"`
	Userns              uint64                 `json:"userns"`
	Image               string                 `json:"image"`
	K8sLabelImage       string                 `json:"k8s_label_image"`
	Tag                 string                 `json:"tag"`
	ContainerName       string                 `json:"container_name"`
	ContainerID         string                 `json:"container_id"`
	Digest              string                 `json:"digest"`
	Privileged          bool                   `json:"privileged"`
	CapAdd              strslice.StrSlice      `json:"cap_add"`
	AppArmorProfile     string                 `json:"apparmor_profile"`
	StartedAt           time.Time              `json:"started_at"`
	FinishedAt          time.Time              `json:"finished_at"`
	PortBindings        nat.PortMap            `json:"port_bindings"`
	SecurityOpt         []string               `json:"security_opt"`
	CommandPath         string                 `json:"command_path"`
	CommandArgs         []string               `json:"command_args"`
	OverlayFsMergedPath string                 `json:"overlayfs_merged_path"`
	Resources           container.Resources    `json:"resources"`
	NetworkSettings     *types.NetworkSettings `json:"network_settings"`
	MountPoints         []types.MountPoint     `json:"mount_points"`
	Labels              map[string]string      `json:"labels"`
}
func (ce ContainerEvent) GetPid() uint32 {
	return ce.InitPid
}
func (ce ContainerEvent) GetNetns() uint64 {
	return ce.Netns
}
func (ce ContainerEvent) GetLogEntry() *logrus.Entry {
	fields := logrus.Fields{}
	for label, value := range ce.Labels {
		fields[label] = value
	}
	return logrus.WithFields(logrus.Fields{
		"image":     ce.Image,
		"digest":    ce.Digest,
		"container": ce.ContainerName,
		"init_pid":  ce.InitPid,
	}).WithFields(fields)
}
func (ce ContainerEvent) GetMessage() string {
	return string(ce.EventType)
}
func (ce ContainerEvent) String() string {
	networksCount := 0
	if ce.NetworkSettings != nil {
		networksCount = len(ce.NetworkSettings.Networks)
	}
	return fmt.Sprintf(
		"%v Image:%v Name:%v ContainerID:%v InitPid:%v Digest:%v Privileged:%v CapAdd:%v CommandPath:%v CommandArgs:%v NetworksCount:%v Pidns:%v Cgroup:%v Mntns:%v Netns:%v Userns:%v AppArmorProfile:%v SecurityOpt:%v",
		ce.EventType,
		ce.Image,
		ce.ContainerName,
		ce.ContainerID,
		ce.InitPid,
		ce.Digest,
		ce.Privileged,
		ce.CapAdd,
		ce.CommandPath,
		ce.CommandArgs,
		networksCount,
		ce.Pidns,
		ce.Cgroup,
		ce.Mntns,
		ce.Netns,
		ce.Userns,
		ce.AppArmorProfile,
		ce.SecurityOpt,
	)
}
type SecurityProfileCreatedEvent struct {
	EventBase
	Profile *v1.SecurityProfile
}
func (spc *SecurityProfileCreatedEvent) GetPid() uint32 {
	return 0
}
func (spc *SecurityProfileCreatedEvent) GetNetns() uint64 {
	return 0
}
func (spc SecurityProfileCreatedEvent) GetLogEntry() *logrus.Entry {
	return logrus.WithFields(logrus.Fields{
		"name":      spc.Profile.Name,
		"namespace": spc.Profile.Namespace,
		"cluster":   spc.Profile.ClusterName,
		"kind":      spc.Profile.Kind,
	})
}
func (spc SecurityProfileCreatedEvent) GetMessage() string {
	return "New SecurityProfile detected"
}
type SecurityProfileUpdatedEvent struct {
	EventBase
	Old *v1.SecurityProfile
	New *v1.SecurityProfile
}
func (spu *SecurityProfileUpdatedEvent) GetPid() uint32 {
	return 0
}
func (spu *SecurityProfileUpdatedEvent) GetNetns() uint64 {
	return 0
}
func (spu SecurityProfileUpdatedEvent) GetLogEntry() *logrus.Entry {
	return logrus.WithFields(logrus.Fields{
		"name":      spu.Old.Name,
		"namespace": spu.Old.Namespace,
		"cluster":   spu.Old.ClusterName,
		"kind":      spu.Old.Kind,
	})
}
func (spu SecurityProfileUpdatedEvent) GetMessage() string {
	return "SecurityProfile updated"
}
type SecurityProfileDeletedEvent struct {
	EventBase
	Profile *v1.SecurityProfile
}
func (spd *SecurityProfileDeletedEvent) GetPid() uint32 {
	return 0
}
func (spd *SecurityProfileDeletedEvent) GetNetns() uint64 {
	return 0
}