Skip to content

Commit 51745a0

Browse files
[filebeat] convert netflow input to API v2 (#37901)
* feat: migrate netflow input to v2.Plugin * fix: replace deprecated ioutil usage * fix: remove unnecessary type conversions * doc: update CHANGELOG.next.asciidoc * ci: install missing libpcap-dev for linux lint step * fix: utilise require.Eventually to wait for conditions to become true in netflow_test.go * fix: proper log verbosity for errors during stopping netflow input * fix: remove redundant config creation * fix: utilise a std context in statsLoop * fix: add server in udp regarding log messages * fix: remove redundant empty line in CHANGELOG.next.asciidoc * fix: enrich more the messages of eventual condition in netflow tests
1 parent 7461af0 commit 51745a0

File tree

10 files changed

+351
-170
lines changed

10 files changed

+351
-170
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ jobs:
3232
with:
3333
go-version-file: .go-version
3434

35+
- name: Install Apt Package
36+
run: sudo apt-get update && sudo apt-get install -y libpcap-dev
37+
3538
- name: golangci-lint
3639
env:
3740
GOOS: ${{ matrix.GOOS }}

CHANGELOG.next.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ fields added to events containing the Beats version. {pull}37553[37553]
2424

2525
*Filebeat*
2626

27+
- Convert netflow input to API v2 and disable event normalisation {pull}37901[37901]
28+
2729

2830
*Heartbeat*
2931

x-pack/dockerlogbeat/pipelinemock/pipelines.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,11 @@ func (pc *MockPipelineConnector) ConnectWith(beat.ClientConfig) (beat.Client, er
8585

8686
return c, nil
8787
}
88+
89+
// HasConnectedClients returns true if there are clients connected.
90+
func (pc *MockPipelineConnector) HasConnectedClients() bool {
91+
pc.mtx.Lock()
92+
defer pc.mtx.Unlock()
93+
94+
return len(pc.clients) > 0
95+
}

x-pack/dockerlogbeat/pipelinemock/reader.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"bytes"
99
"encoding/binary"
1010
"io"
11-
"io/ioutil"
1211
"testing"
1312

1413
"github.com/docker/docker/api/types/plugins/logdriver"
@@ -33,7 +32,7 @@ func CreateTestInputFromLine(t *testing.T, line string) io.ReadCloser {
3332
writer := new(bytes.Buffer)
3433

3534
encodeLog(t, writer, exampleStruct)
36-
return ioutil.NopCloser(writer)
35+
return io.NopCloser(writer)
3736
}
3837

3938
func encodeLog(t *testing.T, out io.Writer, entry *logdriver.LogEntry) {

x-pack/filebeat/input/default-inputs/inputs_other.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/elastic/beats/v7/x-pack/filebeat/input/http_endpoint"
2121
"github.com/elastic/beats/v7/x-pack/filebeat/input/httpjson"
2222
"github.com/elastic/beats/v7/x-pack/filebeat/input/lumberjack"
23+
"github.com/elastic/beats/v7/x-pack/filebeat/input/netflow"
2324
"github.com/elastic/beats/v7/x-pack/filebeat/input/o365audit"
2425
"github.com/elastic/beats/v7/x-pack/filebeat/input/shipper"
2526
"github.com/elastic/beats/v7/x-pack/filebeat/input/websocket"
@@ -41,5 +42,6 @@ func xpackInputs(info beat.Info, log *logp.Logger, store beater.StateStore) []v2
4142
lumberjack.Plugin(),
4243
shipper.Plugin(log, store),
4344
websocket.Plugin(log, store),
45+
netflow.Plugin(log),
4446
}
4547
}

x-pack/filebeat/input/netflow/case.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ func CamelCaseToSnakeCase(in string) string {
6060
}
6161

6262
out := make([]rune, 0, len(in)+4)
63-
runes := []rune(in)
6463
upperCount := 1
65-
for _, r := range runes {
64+
for _, r := range in {
6665
lr := unicode.ToLower(r)
6766
isUpper := lr != r
6867
if isUpper {

x-pack/filebeat/input/netflow/definitions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package netflow
77
import (
88
"errors"
99
"fmt"
10-
"io/ioutil"
10+
"io"
1111
"math"
1212
"os"
1313
"strconv"
@@ -95,7 +95,7 @@ func LoadFieldDefinitionsFromFile(path string) (defs fields.FieldDict, err error
9595
return nil, err
9696
}
9797
defer file.Close()
98-
contents, err := ioutil.ReadAll(file)
98+
contents, err := io.ReadAll(file)
9999
if err != nil {
100100
return nil, err
101101
}
@@ -169,7 +169,7 @@ func loadFields(def map[interface{}]interface{}, pem uint32, dest fields.FieldDi
169169
return fmt.Errorf("bad field ID %d: should have two items (type, name) or one (:skip) (Got %+v)", fieldID, list)
170170
}
171171
key := fields.Key{
172-
EnterpriseID: uint32(pem),
172+
EnterpriseID: pem,
173173
FieldID: uint16(fieldID),
174174
}
175175
if _, exists := dest[key]; exists {

0 commit comments

Comments
 (0)