Skip to content

Commit 20a2569

Browse files
author
Joseph Sirianni
authored
Goflow input operator (#332)
* WIP, just playing around with netflow * wip * sflow * convert byte keys * pass context to Publish. Remove go func, not needed * fix error message * refactor Publish methods * replace map keys in Parse() instead of copying the map, benchmark results are faster * add tests * remove early return * remove duplicate from init. hardcode reuse to true * initial netflow docs * make tidy * remove reuse from test * re-combine all 3 goflow operators into goflow (previously netflow) package. add param * refactor WriteGoFlowMessage * promote timestamp * enhance parse testing * integration test for netflow v5 * refactor publish * use stanza's logging for goflow logging interface * Refactor startup handling, stop stanza if Goflow fails at anytime * Refactor goflow process handling. verify that the socket is available during Build(), implement automatic restart on goflow failure with a backoff * refactor test, ensure file_output content is correct * check sampler address, it is based on the source ip * we need docker for tests * setup int tests at a later time * Added Goflow operator for receiving Netflow (v5, v9, ipfix) and Sflow * cleanup commented fields * rename netflow v9 --> netflow ipfix. ipfix is the latest version and is backwards compatible with v9 * use const values that already exist * use netflow_ipfix as default mode * use ListenAddress instead of address + port. Set mode default before checking if valid
1 parent b5a6c13 commit 20a2569

File tree

14 files changed

+1143
-3
lines changed

14 files changed

+1143
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ local/*
77
artifacts/*
88
**/.vscode/*
99
gen/
10+
**/testdata/*.log

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## Unreleased
8+
9+
### Added
10+
- Added Goflow operator for receiving Netflow (v5, v9, ipfix) and Sflow [PR 332](https://github.com/observIQ/stanza/pull/332)
11+
712
## 1.0.1 - 2021-06-16
813

914
### Fixed

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ test: vet test-only
2323
test-only:
2424
$(MAKE) for-all CMD="go test -race -coverprofile coverage.txt -coverpkg ./... ./..."
2525

26+
.PHONY: test-integration
27+
test-integration:
28+
mkdir -p artifacts
29+
curl -fL https://github.com/observiq/stanza-plugins/releases/latest/download/stanza-plugins.tar.gz -o ./artifacts/stanza-plugins.tar.gz
30+
docker build . -t stanza-integration:latest
31+
$(MAKE) for-all CMD="go clean -testcache ./... ./..."
32+
$(MAKE) for-all CMD="go test -tags integration ./... ./..."
33+
2634
.PHONY: bench
2735
bench:
2836
$(MAKE) for-all CMD="go test -run=NONE -bench '.*' ./... -benchmem"

cmd/stanza/init_common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
_ "github.com/observiq/stanza/operator/builtin/input/file"
99
_ "github.com/observiq/stanza/operator/builtin/input/forward"
1010
_ "github.com/observiq/stanza/operator/builtin/input/generate"
11+
_ "github.com/observiq/stanza/operator/builtin/input/goflow"
1112
_ "github.com/observiq/stanza/operator/builtin/input/k8sevent"
1213
_ "github.com/observiq/stanza/operator/builtin/input/stanza"
1314
_ "github.com/observiq/stanza/operator/builtin/input/stdin"

docs/operators/goflow_input.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
## `goflow_input` operator
2+
3+
The `goflow_input` operator recieves Netflow v9 / IPFIX, Netflow v5, and Sflow messages from network devices. `goflow_input` implements [Goflow](https://github.com/cloudflare/goflow).
4+
5+
The `timereceived` field is promoted as the entries Timestamp.
6+
7+
### Configuration Fields
8+
9+
| Field | Default | Description |
10+
| --- | --- | --- |
11+
| `id` | `goflow_input` | A unique identifier for the operator |
12+
| `output` | Next in pipeline | The connected operator(s) that will receive all outbound entries |
13+
| `mode` | `netflow_ipfix` | The Goflow mode [`netflow_ipfix`, `netflow_v5`, `sflow`] |
14+
| `address` | `0.0.0.0` | The ip address to bind to |
15+
| `port` | required | The port to bind to |
16+
| `workers` | `1` | Number of worker processes spawned by the underlying [Goflow package](https://github.com/cloudflare/goflow) |
17+
18+
### Example Configuration
19+
20+
Configuration:
21+
```yaml
22+
pipeline:
23+
- type: goflow_input
24+
mode: netflow_v5
25+
port: 2000
26+
- type: stdout
27+
```
28+
29+
### Example Output
30+
31+
```json
32+
{
33+
"timestamp": "2021-06-15T11:59:26-04:00",
34+
"severity": 0,
35+
"record": {
36+
"bytes": 936,
37+
"dstaddr": "173.195.121.172",
38+
"dstas": 14164,
39+
"dstnet": 5,
40+
"dstport": 17210,
41+
"etype": 2048,
42+
"nexthop": "66.88.34.2",
43+
"packets": 100,
44+
"proto": 6,
45+
"sampleraddress": "172.17.0.2",
46+
"sequencenum": 7,
47+
"srcaddr": "241.104.80.243",
48+
"srcas": 43137,
49+
"srcnet": 11,
50+
"srcport": 37247,
51+
"timeflowend": 1623772766,
52+
"timeflowstart": 1623772766,
53+
"type": 2
54+
}
55+
}
56+
57+
```

go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ require (
99
github.com/aws/aws-sdk-go v1.38.31
1010
github.com/bmatcuk/doublestar/v2 v2.0.4
1111
github.com/cenkalti/backoff/v4 v4.1.1
12+
github.com/cloudflare/goflow/v3 v3.4.2
1213
github.com/elastic/go-elasticsearch/v7 v7.13.0
14+
github.com/fatih/structs v1.1.0
1315
github.com/golang/protobuf v1.5.2
1416
github.com/hashicorp/go-uuid v1.0.2
1517
github.com/jpillora/backoff v1.0.0
@@ -19,8 +21,10 @@ require (
1921
github.com/observiq/ctimefmt v1.0.0
2022
github.com/observiq/go-syslog/v3 v3.0.2
2123
github.com/observiq/nanojack v0.0.0-20201106172433-343928847ebc
24+
github.com/sirupsen/logrus v1.7.0
2225
github.com/spf13/cobra v1.1.3
2326
github.com/stretchr/testify v1.7.0
27+
github.com/testcontainers/testcontainers-go v0.11.0
2428
go.etcd.io/bbolt v1.3.5
2529
go.opentelemetry.io/collector v0.13.0
2630
go.uber.org/multierr v1.5.0

0 commit comments

Comments
 (0)