From 722369f56874028b81e97189ee554b754eb02680 Mon Sep 17 00:00:00 2001 From: timn Date: Mon, 10 Jul 2023 13:58:52 -0400 Subject: [PATCH 1/3] init octetmultiline --- .chloggen/pkg-stanza-input-syslog.yaml | 20 ++++++++++++++++++++ pkg/stanza/operator/input/syslog/syslog.go | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 .chloggen/pkg-stanza-input-syslog.yaml diff --git a/.chloggen/pkg-stanza-input-syslog.yaml b/.chloggen/pkg-stanza-input-syslog.yaml new file mode 100644 index 000000000000..d4518461fd29 --- /dev/null +++ b/.chloggen/pkg-stanza-input-syslog.yaml @@ -0,0 +1,20 @@ +# Use this changelog template to create an entry for release notes. +# If your change doesn't affect end users, such as a test fix or a tooling change, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: pkg/stanza/input/syslog + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: ensure octetmultiplinebuilder is initialized + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [24073] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/pkg/stanza/operator/input/syslog/syslog.go b/pkg/stanza/operator/input/syslog/syslog.go index 6c43ce0bec67..1d21bb6b0709 100644 --- a/pkg/stanza/operator/input/syslog/syslog.go +++ b/pkg/stanza/operator/input/syslog/syslog.go @@ -61,11 +61,11 @@ func (c Config) Build(logger *zap.SugaredLogger) (operator.Operator, error) { if c.TCP != nil { tcpInputCfg := tcp.NewConfigWithID(inputBase.ID() + "_internal_tcp") + tcpInputCfg.BaseConfig = *c.TCP if syslogParserCfg.EnableOctetCounting { tcpInputCfg.MultiLineBuilder = OctetMultiLineBuilder } - tcpInputCfg.BaseConfig = *c.TCP tcpInput, err := tcpInputCfg.Build(logger) if err != nil { return nil, fmt.Errorf("failed to resolve tcp config: %w", err) From d11a61e2603f67d637cdb88174207b60bca5af44 Mon Sep 17 00:00:00 2001 From: timn Date: Mon, 10 Jul 2023 16:00:04 -0400 Subject: [PATCH 2/3] add slight validation --- .../operator/input/syslog/syslog_test.go | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/pkg/stanza/operator/input/syslog/syslog_test.go b/pkg/stanza/operator/input/syslog/syslog_test.go index 1315d3dc1f10..b6bd8f223cfd 100644 --- a/pkg/stanza/operator/input/syslog/syslog_test.go +++ b/pkg/stanza/operator/input/syslog/syslog_test.go @@ -11,6 +11,7 @@ import ( "github.com/stretchr/testify/require" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/entry" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/helper" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/input/tcp" @@ -21,14 +22,55 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/testutil" ) -func TestInput(t *testing.T) { - basicConfig := func() *syslog.Config { +var ( + basicConfig = func() *syslog.Config { cfg := syslog.NewConfigWithID("test_syslog_parser") return cfg } + OctetCase = syslog.Case{ + Name: "RFC6587 Octet Counting", + Config: func() *syslog.Config { + cfg := basicConfig() + cfg.Protocol = syslog.RFC5424 + cfg.EnableOctetCounting = true + return cfg + }(), + Input: &entry.Entry{ + Body: `215 <86>1 2015-08-05T21:58:59.693Z 192.168.2.132 SecureAuth0 23108 ID52020 [SecureAuth@27389 UserHostAddress="192.168.2.132" Realm="SecureAuth0" UserID="Tester2" PEN="27389"] Found the user for retrieving user's profile215 <86>1 2016-08-05T21:58:59.693Z 192.168.2.132 SecureAuth0 23108 ID52020 [SecureAuth@27389 UserHostAddress="192.168.2.132" Realm="SecureAuth0" UserID="Tester2" PEN="27389"] Found the user for retrieving user's profile215 <86>1 2017-08-05T21:58:59.693Z 192.168.2.132 SecureAuth0 23108 ID52020 [SecureAuth@27389 UserHostAddress="192.168.2.132" Realm="SecureAuth0" UserID="Tester2" PEN="27389"] Found the user for retrieving user's profile`, + }, + Expect: &entry.Entry{ + Timestamp: time.Date(2015, 8, 5, 21, 58, 59, 693000000, time.UTC), + Severity: entry.Info, + SeverityText: "info", + Attributes: map[string]interface{}{ + "appname": "SecureAuth0", + "facility": 10, + "hostname": "192.168.2.132", + "message": "Found the user for retrieving user's profile", + "msg_id": "ID52020", + "priority": 86, + "proc_id": "23108", + "structured_data": map[string]map[string]string{ + "SecureAuth@27389": { + "PEN": "27389", + "Realm": "SecureAuth0", + "UserHostAddress": "192.168.2.132", + "UserID": "Tester2", + }, + }, + "version": 1, + }, + Body: `215 <86>1 2015-08-05T21:58:59.693Z 192.168.2.132 SecureAuth0 23108 ID52020 [SecureAuth@27389 UserHostAddress="192.168.2.132" Realm="SecureAuth0" UserID="Tester2" PEN="27389"] Found the user for retrieving user's profile`, + }, + ValidForTCP: true, + } +) + +func TestInput(t *testing.T) { cases, err := syslog.CreateCases(basicConfig) require.NoError(t, err) + cases = append(cases, OctetCase) for _, tc := range cases { if tc.ValidForTCP { From 6f044dd9b719b88979c3dfad9348c11e2e81fffa Mon Sep 17 00:00:00 2001 From: Daniel Jaglowski Date: Tue, 11 Jul 2023 13:44:56 -0400 Subject: [PATCH 3/3] Changelog --- .chloggen/pkg-stanza-input-syslog.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.chloggen/pkg-stanza-input-syslog.yaml b/.chloggen/pkg-stanza-input-syslog.yaml index d4518461fd29..7ee156763825 100644 --- a/.chloggen/pkg-stanza-input-syslog.yaml +++ b/.chloggen/pkg-stanza-input-syslog.yaml @@ -6,10 +6,10 @@ change_type: bug_fix # The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) -component: pkg/stanza/input/syslog +component: pkg/stanza # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: ensure octetmultiplinebuilder is initialized +note: Fix issue where syslog input ignored enable_octet_counting setting # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. issues: [24073]