write

package
v1.8.0-crc0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2025 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const IPv6Type uint16 = 0x86DD

IPv6Type value as defined in IEEE 802: https://www.iana.org/assignments/ieee-802-numbers/ieee-802-numbers.xhtml

Variables

View Source
var (
	IANAFields = []string{
		"ethernetType",
		"flowDirection",
		"sourceMacAddress",
		"destinationMacAddress",
		"protocolIdentifier",
		"sourceTransportPort",
		"destinationTransportPort",
		"octetDeltaCount",
		"flowStartMilliseconds",
		"flowEndMilliseconds",
		"packetDeltaCount",
		"interfaceName",
	}
	IPv4IANAFields = append([]string{
		"sourceIPv4Address",
		"destinationIPv4Address",
	}, IANAFields...)
	IPv6IANAFields = append([]string{
		"sourceIPv6Address",
		"destinationIPv6Address",
		"nextHeaderIPv6",
	}, IANAFields...)
	KubeFields = []string{
		"sourcePodNamespace",
		"sourcePodName",
		"destinationPodNamespace",
		"destinationPodName",
		"sourceNodeName",
		"destinationNodeName",
	}
	CustomNetworkFields = []string{
		"timeFlowRttNs",
		"interfaces",
		"directions",
	}

	MapIPFIXKeys = map[string]FieldMap{
		"sourceIPv4Address": {
			Key:    "SrcAddr",
			Getter: func(elt entities.InfoElementWithValue) any { return elt.GetIPAddressValue().String() },
			Setter: func(elt entities.InfoElementWithValue, rec any) { elt.SetIPAddressValue(net.ParseIP(rec.(string))) },
		},
		"destinationIPv4Address": {
			Key:    "DstAddr",
			Getter: func(elt entities.InfoElementWithValue) any { return elt.GetIPAddressValue().String() },
			Setter: func(elt entities.InfoElementWithValue, rec any) { elt.SetIPAddressValue(net.ParseIP(rec.(string))) },
		},
		"sourceIPv6Address": {
			Key:    "SrcAddr",
			Getter: func(elt entities.InfoElementWithValue) any { return elt.GetIPAddressValue().String() },
			Setter: func(elt entities.InfoElementWithValue, rec any) { elt.SetIPAddressValue(net.ParseIP(rec.(string))) },
		},
		"destinationIPv6Address": {
			Key:    "DstAddr",
			Getter: func(elt entities.InfoElementWithValue) any { return elt.GetIPAddressValue().String() },
			Setter: func(elt entities.InfoElementWithValue, rec any) { elt.SetIPAddressValue(net.ParseIP(rec.(string))) },
		},
		"nextHeaderIPv6": {
			Key:    "Proto",
			Getter: func(elt entities.InfoElementWithValue) any { return elt.GetUnsigned8Value() },
			Setter: func(elt entities.InfoElementWithValue, rec any) { elt.SetUnsigned8Value(rec.(uint8)) },
		},
		"sourceMacAddress": {
			Key: "SrcMac",
			Setter: func(elt entities.InfoElementWithValue, rec any) {
				elt.SetMacAddressValue(net.HardwareAddr(rec.(string)))
			},
			Matcher: func(_ entities.InfoElementWithValue, _ any) bool {

				return true
			},
		},
		"destinationMacAddress": {
			Key: "DstMac",
			Setter: func(elt entities.InfoElementWithValue, rec any) {
				elt.SetMacAddressValue(net.HardwareAddr(rec.(string)))
			},
			Matcher: func(_ entities.InfoElementWithValue, _ any) bool {

				return true
			},
		},
		"ethernetType": {
			Key:    "Etype",
			Getter: func(elt entities.InfoElementWithValue) any { return elt.GetUnsigned16Value() },
			Setter: func(elt entities.InfoElementWithValue, rec any) { elt.SetUnsigned16Value(rec.(uint16)) },
		},
		"flowDirection": {
			Key: "IfDirections",
			Setter: func(elt entities.InfoElementWithValue, rec any) {
				if dirs, ok := rec.([]int); ok && len(dirs) > 0 {
					elt.SetUnsigned8Value(uint8(dirs[0]))
				}
			},
			Matcher: func(elt entities.InfoElementWithValue, expected any) bool {
				ifdirs := expected.([]int)
				return int(elt.GetUnsigned8Value()) == ifdirs[0]
			},
		},
		"directions": {
			Key: "IfDirections",
			Getter: func(elt entities.InfoElementWithValue) any {
				var dirs []int
				for _, dir := range strings.Split(elt.GetStringValue(), ",") {
					d, _ := strconv.Atoi(dir)
					dirs = append(dirs, d)
				}
				return dirs
			},
			Setter: func(elt entities.InfoElementWithValue, rec any) {
				if dirs, ok := rec.([]int); ok && len(dirs) > 0 {
					var asStr []string
					for _, dir := range dirs {
						asStr = append(asStr, strconv.Itoa(dir))
					}
					elt.SetStringValue(strings.Join(asStr, ","))
				}
			},
		},
		"protocolIdentifier": {
			Key:    "Proto",
			Getter: func(elt entities.InfoElementWithValue) any { return elt.GetUnsigned8Value() },
			Setter: func(elt entities.InfoElementWithValue, rec any) { elt.SetUnsigned8Value(rec.(uint8)) },
		},
		"sourceTransportPort": {
			Key:    "SrcPort",
			Getter: func(elt entities.InfoElementWithValue) any { return elt.GetUnsigned16Value() },
			Setter: func(elt entities.InfoElementWithValue, rec any) { elt.SetUnsigned16Value(rec.(uint16)) },
		},
		"destinationTransportPort": {
			Key:    "DstPort",
			Getter: func(elt entities.InfoElementWithValue) any { return elt.GetUnsigned16Value() },
			Setter: func(elt entities.InfoElementWithValue, rec any) { elt.SetUnsigned16Value(rec.(uint16)) },
		},
		"octetDeltaCount": {
			Key:    "Bytes",
			Getter: func(elt entities.InfoElementWithValue) any { return elt.GetUnsigned64Value() },
			Setter: func(elt entities.InfoElementWithValue, rec any) { elt.SetUnsigned64Value(rec.(uint64)) },
		},
		"flowStartMilliseconds": {
			Key:    "TimeFlowStartMs",
			Getter: func(elt entities.InfoElementWithValue) any { return int64(elt.GetUnsigned64Value()) },
			Setter: func(elt entities.InfoElementWithValue, rec any) { elt.SetUnsigned64Value(uint64(rec.(int64))) },
		},
		"flowEndMilliseconds": {
			Key:    "TimeFlowEndMs",
			Getter: func(elt entities.InfoElementWithValue) any { return int64(elt.GetUnsigned64Value()) },
			Setter: func(elt entities.InfoElementWithValue, rec any) { elt.SetUnsigned64Value(uint64(rec.(int64))) },
		},
		"packetDeltaCount": {
			Key:    "Packets",
			Getter: func(elt entities.InfoElementWithValue) any { return uint32(elt.GetUnsigned64Value()) },
			Setter: func(elt entities.InfoElementWithValue, rec any) { elt.SetUnsigned64Value(uint64(rec.(uint32))) },
		},
		"interfaceName": {
			Key: "Interfaces",
			Setter: func(elt entities.InfoElementWithValue, rec any) {
				if ifs, ok := rec.([]string); ok && len(ifs) > 0 {
					elt.SetStringValue(ifs[0])
				}
			},
			Matcher: func(elt entities.InfoElementWithValue, expected any) bool {
				ifs := expected.([]string)
				return elt.GetStringValue() == ifs[0]
			},
		},
		"interfaces": {
			Key:    "Interfaces",
			Getter: func(elt entities.InfoElementWithValue) any { return strings.Split(elt.GetStringValue(), ",") },
			Setter: func(elt entities.InfoElementWithValue, rec any) {
				if ifs, ok := rec.([]string); ok {
					elt.SetStringValue(strings.Join(ifs, ","))
				}
			},
		},
		"sourcePodNamespace": {
			Key:      "SrcK8S_Namespace",
			Getter:   func(elt entities.InfoElementWithValue) any { return elt.GetStringValue() },
			Setter:   func(elt entities.InfoElementWithValue, rec any) { elt.SetStringValue(rec.(string)) },
			Optional: true,
		},
		"sourcePodName": {
			Key:      "SrcK8S_Name",
			Getter:   func(elt entities.InfoElementWithValue) any { return elt.GetStringValue() },
			Setter:   func(elt entities.InfoElementWithValue, rec any) { elt.SetStringValue(rec.(string)) },
			Optional: true,
		},
		"destinationPodNamespace": {
			Key:      "DstK8S_Namespace",
			Getter:   func(elt entities.InfoElementWithValue) any { return elt.GetStringValue() },
			Setter:   func(elt entities.InfoElementWithValue, rec any) { elt.SetStringValue(rec.(string)) },
			Optional: true,
		},
		"destinationPodName": {
			Key:      "DstK8S_Name",
			Getter:   func(elt entities.InfoElementWithValue) any { return elt.GetStringValue() },
			Setter:   func(elt entities.InfoElementWithValue, rec any) { elt.SetStringValue(rec.(string)) },
			Optional: true,
		},
		"sourceNodeName": {
			Key:      "SrcK8S_HostName",
			Getter:   func(elt entities.InfoElementWithValue) any { return elt.GetStringValue() },
			Setter:   func(elt entities.InfoElementWithValue, rec any) { elt.SetStringValue(rec.(string)) },
			Optional: true,
		},
		"destinationNodeName": {
			Key:      "DstK8S_HostName",
			Getter:   func(elt entities.InfoElementWithValue) any { return elt.GetStringValue() },
			Setter:   func(elt entities.InfoElementWithValue, rec any) { elt.SetStringValue(rec.(string)) },
			Optional: true,
		},
		"timeFlowRttNs": {
			Key:      "TimeFlowRttNs",
			Getter:   func(elt entities.InfoElementWithValue) any { return int64(elt.GetUnsigned64Value()) },
			Setter:   func(elt entities.InfoElementWithValue, rec any) { elt.SetUnsigned64Value(uint64(rec.(int64))) },
			Optional: true,
		},
	}
)

Functions

func SendTemplateRecordv4 added in v0.1.8

func SendTemplateRecordv4(exporter *ipfixExporter.ExportingProcess, enrichEnterpriseID uint32) (uint16, []entities.InfoElementWithValue, error)

func SendTemplateRecordv6 added in v0.1.8

func SendTemplateRecordv6(exporter *ipfixExporter.ExportingProcess, enrichEnterpriseID uint32) (uint16, []entities.InfoElementWithValue, error)

Types

type Fake

type Fake struct {
	// contains filtered or unexported fields
}

func (*Fake) AllRecords

func (w *Fake) AllRecords() []config.GenericMap

func (*Fake) Write

func (w *Fake) Write(in config.GenericMap)

Write stores in memory all records.

type FieldMap

type FieldMap struct {
	Key      string
	Getter   func(entities.InfoElementWithValue) any
	Setter   func(entities.InfoElementWithValue, any)
	Matcher  func(entities.InfoElementWithValue, any) bool
	Optional bool
}

type Loki

type Loki struct {
	// contains filtered or unexported fields
}

Loki record writer

func NewWriteLoki

func NewWriteLoki(opMetrics *operational.Metrics, params config.StageParam) (*Loki, error)

NewWriteLoki creates a Loki writer from configuration

func (*Loki) ProcessRecord

func (l *Loki) ProcessRecord(in config.GenericMap) error

func (*Loki) Write

func (l *Loki) Write(entry config.GenericMap)

Write writes a flow before being stored

type None

type None struct {
	// contains filtered or unexported fields
}

func (*None) PrevRecords

func (t *None) PrevRecords() []config.GenericMap

func (*None) Write

func (t *None) Write(in config.GenericMap)

Write writes entries

type Writer

type Writer interface {
	Write(in config.GenericMap)
}

func NewWriteFake added in v0.1.3

func NewWriteFake(_ config.StageParam) (Writer, error)

NewWriteFake creates a new write.

func NewWriteGRPC

func NewWriteGRPC(params config.StageParam) (Writer, error)

NewWriteGRPC create a new write

func NewWriteIpfix added in v0.1.8

func NewWriteIpfix(params config.StageParam) (Writer, error)

NewWriteIpfix creates a new write

func NewWriteNone

func NewWriteNone() (Writer, error)

NewWriteNone create a new write

func NewWriteStdout

func NewWriteStdout(params config.StageParam) (Writer, error)

NewWriteStdout create a new write

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL