|
| 1 | +/* |
| 2 | + * Copyright (C) 2022 IBM, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + */ |
| 17 | + |
| 18 | +package api |
| 19 | + |
| 20 | +import ( |
| 21 | + "fmt" |
| 22 | + |
| 23 | + "github.com/netsampler/goflow2/producer" |
| 24 | +) |
| 25 | + |
| 26 | +type IngestIpfix struct { |
| 27 | + HostName string `yaml:"hostName,omitempty" json:"hostName,omitempty" doc:"the hostname to listen on; defaults to 0.0.0.0"` |
| 28 | + Port uint `yaml:"port,omitempty" json:"port,omitempty" doc:"the port number to listen on, for IPFIX/NetFlow v9. Omit or set to 0 to disable IPFIX/NetFlow v9 ingestion. If both port and portLegacy are omitted, defaults to 2055"` |
| 29 | + PortLegacy uint `yaml:"portLegacy,omitempty" json:"portLegacy,omitempty" doc:"the port number to listen on, for legacy NetFlow v5. Omit or set to 0 to disable NetFlow v5 ingestion"` |
| 30 | + Workers uint `yaml:"workers,omitempty" json:"workers,omitempty" doc:"the number of netflow/ipfix decoding workers"` |
| 31 | + Sockets uint `yaml:"sockets,omitempty" json:"sockets,omitempty" doc:"the number of listening sockets"` |
| 32 | + Mapping []producer.NetFlowMapField `yaml:"mapping,omitempty" json:"mapping,omitempty" doc:"custom field mapping"` |
| 33 | +} |
| 34 | + |
| 35 | +func (i *IngestIpfix) SetDefaults() { |
| 36 | + if i.HostName == "" { |
| 37 | + i.HostName = "0.0.0.0" |
| 38 | + } |
| 39 | + if i.Port == 0 && i.PortLegacy == 0 { |
| 40 | + i.Port = 2055 |
| 41 | + } |
| 42 | + if i.Workers == 0 { |
| 43 | + i.Workers = 1 |
| 44 | + } |
| 45 | + if i.Sockets == 0 { |
| 46 | + i.Sockets = 1 |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +func (i *IngestIpfix) String() string { |
| 51 | + hasMapping := "no" |
| 52 | + if len(i.Mapping) > 0 { |
| 53 | + hasMapping = "yes" |
| 54 | + } |
| 55 | + return fmt.Sprintf( |
| 56 | + "hostname=%s, port=%d, portLegacy=%d, workers=%d, sockets=%d, mapping=%s", |
| 57 | + i.HostName, |
| 58 | + i.Port, |
| 59 | + i.PortLegacy, |
| 60 | + i.Workers, |
| 61 | + i.Sockets, |
| 62 | + hasMapping, |
| 63 | + ) |
| 64 | +} |
0 commit comments