Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions internal/generator/vector/output/syslog/syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ func (s Syslog) Template() string {
type = "remap"
inputs = {{.Inputs}}
source = '''
. = merge(., parse_json!(string!(.message))) ?? .
obj, err = parse_json(string!(.message))
if err != null {
log(err, level: "error")
} else {
if is_object(obj) {
.message = obj
}
}
'''

[sinks.{{.ComponentID}}]
Expand Down Expand Up @@ -157,7 +164,7 @@ func Facility(s *logging.Syslog) string {
return "user"
}
if IsKeyExpr(s.Facility) {
return fmt.Sprintf("$%s", s.Facility)
return fmt.Sprintf("$$.%s", s.Facility[2:])
}
return vectorhelpers.EscapeDollarSigns(s.Facility)
}
Expand All @@ -167,7 +174,7 @@ func Severity(s *logging.Syslog) string {
return "informational"
}
if IsKeyExpr(s.Severity) {
return fmt.Sprintf("$%s", s.Severity)
return fmt.Sprintf("$$.%s", s.Severity[2:])
}
return vectorhelpers.EscapeDollarSigns(s.Severity)
}
Expand All @@ -194,7 +201,7 @@ func AppName(s *logging.Syslog) Element {
return Nil
}
if IsKeyExpr(s.AppName) {
return KV(appname, fmt.Sprintf(`"$%s"`, s.AppName))
return KV(appname, fmt.Sprintf(`"$$.%s"`, s.AppName[2:]))
}
if s.AppName == "tag" {
return KV(appname, "${tag}")
Expand All @@ -208,7 +215,7 @@ func Tag(s *logging.Syslog) Element {
}
tag := "tag"
if IsKeyExpr(s.Tag) {
return KV(tag, fmt.Sprintf(`"$%s"`, s.Tag))
return KV(tag, fmt.Sprintf(`"$$.%s"`, s.Tag[2:]))
}
return KV(tag, fmt.Sprintf(`"%s"`, vectorhelpers.EscapeDollarSigns(s.Tag)))
}
Expand All @@ -219,7 +226,7 @@ func MsgID(s *logging.Syslog) Element {
}
msgid := "msg_id"
if IsKeyExpr(s.MsgID) {
return KV(msgid, fmt.Sprintf(`"$%s"`, s.MsgID))
return KV(msgid, fmt.Sprintf(`"$$.%s"`, s.MsgID[2:]))
}
return KV(msgid, fmt.Sprintf(`"%s"`, vectorhelpers.EscapeDollarSigns(s.MsgID)))
}
Expand All @@ -230,7 +237,7 @@ func ProcID(s *logging.Syslog) Element {
}
procid := "proc_id"
if IsKeyExpr(s.ProcID) {
return KV(procid, fmt.Sprintf(`"$%s"`, s.ProcID))
return KV(procid, fmt.Sprintf(`"$$.%s"`, s.ProcID[2:]))
}
return KV(procid, fmt.Sprintf(`"%s"`, vectorhelpers.EscapeDollarSigns(s.ProcID)))
}
Expand Down
45 changes: 40 additions & 5 deletions internal/generator/vector/output/syslog/syslog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ source = '''
type = "remap"
inputs = ["example_dedot"]
source = '''
. = merge(., parse_json!(string!(.message))) ?? .
obj, err = parse_json(string!(.message))
if err != null {
log(err, level: "error")
} else {
if is_object(obj) {
.message = obj
}
}
'''

[sinks.example]
Expand Down Expand Up @@ -89,7 +96,14 @@ source = '''
type = "remap"
inputs = ["example_dedot"]
source = '''
. = merge(., parse_json!(string!(.message))) ?? .
obj, err = parse_json(string!(.message))
if err != null {
log(err, level: "error")
} else {
if is_object(obj) {
.message = obj
}
}
'''

[sinks.example]
Expand Down Expand Up @@ -134,7 +148,14 @@ source = '''
type = "remap"
inputs = ["example_dedot"]
source = '''
. = merge(., parse_json!(string!(.message))) ?? .
obj, err = parse_json(string!(.message))
if err != null {
log(err, level: "error")
} else {
if is_object(obj) {
.message = obj
}
}
'''

[sinks.example]
Expand Down Expand Up @@ -184,7 +205,14 @@ source = '''
type = "remap"
inputs = ["example_dedot"]
source = '''
. = merge(., parse_json!(string!(.message))) ?? .
obj, err = parse_json(string!(.message))
if err != null {
log(err, level: "error")
} else {
if is_object(obj) {
.message = obj
}
}
'''

[sinks.example]
Expand Down Expand Up @@ -235,7 +263,14 @@ source = '''
type = "remap"
inputs = ["example_dedot"]
source = '''
. = merge(., parse_json!(string!(.message))) ?? .
obj, err = parse_json(string!(.message))
if err != null {
log(err, level: "error")
} else {
if is_object(obj) {
.message = obj
}
}
'''

[sinks.example]
Expand Down
4 changes: 3 additions & 1 deletion test/functional/outputs/syslog/rfc3164_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ var _ = Describe("[Functional][Outputs][Syslog] RFC3164 tests", func() {
Expect(outputlogs).To(HaveLen(1), "Expected the receiver to receive the message")
expMatch := fmt.Sprintf(`( %s )`, expTag)
Expect(outputlogs[0]).To(MatchRegexp(expMatch), "Exp to find tag in received message")
Expect(outputlogs[0]).To(MatchRegexp(`{"index":.*1,.*"timestamp":.*1,.*"tag_key":.*"rec_tag"}`), "Exp to find the original message in received message")
Expect(outputlogs[0]).To(MatchRegexp(`"index":.*1`), "Exp to find the original message in received message")
Expect(outputlogs[0]).To(MatchRegexp(`"timestamp":.*1`), "Exp to find the original message in received message")
Expect(outputlogs[0]).To(MatchRegexp(`"tag_key":.*"rec_tag"`), "Exp to find the original message in received message")
},

Entry("should use the value from the record and include the message", "$.message.tag_key", "rec_tag", false),
Expand Down
5 changes: 4 additions & 1 deletion test/functional/outputs/syslog/rfc5424_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ var _ = Describe("[Functional][Outputs][Syslog] RFC5424 tests", func() {
Expect(outputlogs).To(HaveLen(1), "Expected the receiver to receive the message")
expMatch := fmt.Sprintf(`( %s )`, expInfo)
Expect(outputlogs[0]).To(MatchRegexp(expMatch), "Exp to match the appname/procid/msgid in received message")
Expect(outputlogs[0]).To(MatchRegexp(record), "Exp to find the original message in received message")
Expect(outputlogs[0]).To(MatchRegexp(`"index":.*1`), "Exp to find the original message in received message")
Expect(outputlogs[0]).To(MatchRegexp(`"appname_key":.*"rec_appname"`), "Exp to find the original message in received message")
Expect(outputlogs[0]).To(MatchRegexp(`"msgid_key":.*"rec_msgid"`), "Exp to find the original message in received message")
Expect(outputlogs[0]).To(MatchRegexp(`"procid_key":.*"rec_procid"`), "Exp to find the original message in received message")
},

Entry("should use the value from the record and include the message", "$.message.appname_key", "$.message.msgid_key", "$.message.procid_key", "rec_appname rec_procid rec_msgid", false),
Expand Down