Skip to content

Commit

Permalink
fix regression test
Browse files Browse the repository at this point in the history
set rfc5424 as default format
  • Loading branch information
dmachard committed Oct 30, 2023
1 parent 3c4f864 commit 70f1591
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
2 changes: 1 addition & 1 deletion dnsutils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ func (c *Config) SetDefault() {
c.Loggers.Syslog.ChannelBufferSize = 65535
c.Loggers.Syslog.Tag = ""
c.Loggers.Syslog.Framer = ""
c.Loggers.Syslog.Formatter = "rfc3164"
c.Loggers.Syslog.Formatter = "rfc5424"
c.Loggers.Syslog.Hostname = ""
c.Loggers.Syslog.AppName = ""

Expand Down
2 changes: 1 addition & 1 deletion docs/loggers/logger_syslog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Options:
* `text-format`: (string) output text format, please refer to the default text format to see all available [directives](../configuration.md#custom-text-format), use this parameter if you want a specific format
* `tls-insecure`: (boolean) insecure mode, skip certificate verify
* `tls-min-version`: (string) min tls version, default to 1.2
* `formattter`: (string) Set syslog formatter between `unix`, `rfc3164` (default) or `rfc5424`
* `formattter`: (string) Set syslog formatter between `unix`, `rfc3164` or `rfc5424` (default)
* `framer`: (string) Set syslog framer: `none` or `rfc5425`
* `hostname`: (string) Set syslog hostname
* `app-name`: (string) Set syslog program name
Expand Down
5 changes: 2 additions & 3 deletions loggers/syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ func (o *Syslog) ConnectToRemote() {
switch strings.ToLower(o.config.Loggers.Syslog.Formatter) {
case "unix":
o.syslogWriter.SetFormatter(syslog.UnixFormatter)
case "rfc3164", "":
case "rfc3164":
o.syslogWriter.SetFormatter(syslog.RFC3164Formatter)
case "rfc5424":
case "rfc5424", "":
o.syslogWriter.SetFormatter(syslog.RFC5424Formatter)
}

Expand All @@ -232,7 +232,6 @@ func (o *Syslog) ConnectToRemote() {
// notify process that the transport is ready
// block the loop until a reconnect is needed
o.transportReady <- true

o.transportReconnect <- true
}
}
Expand Down
50 changes: 30 additions & 20 deletions loggers/syslog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,44 @@ func Test_SyslogRunUdp(t *testing.T) {
name string
transport string
mode string
format string
formatter string
framer string
pattern string
listenAddr string
}{
{
name: "unix_format",
transport: dnsutils.SOCKET_UDP,
mode: dnsutils.MODE_TEXT,
format: "unix",
pattern: `<30> \d+-\d+-\d+.*`,
formatter: "unix",
framer: "",
pattern: `<30>\D+ \d+ \d+:\d+:\d+.*`,
listenAddr: ":4000",
},
{
name: "rfc3164_format",
transport: dnsutils.SOCKET_UDP,
mode: dnsutils.MODE_TEXT,
format: "rfc3164",
pattern: "<30>.*",
formatter: "rfc3164",
framer: "",
pattern: `<30>\D+ \d+ \d+:\d+:\d+.*`,
listenAddr: ":4000",
},
{
name: "rfc5424_format",
transport: dnsutils.SOCKET_UDP,
mode: dnsutils.MODE_TEXT,
format: "rfc5424",
formatter: "rfc5424",
framer: "",
pattern: `<30>1 \d+-\d+-\d+.*`,
listenAddr: ":4000",
},
{
name: "rfc5425_format",
name: "rfc5424_format_rfc5425_framer",
transport: dnsutils.SOCKET_UDP,
mode: dnsutils.MODE_TEXT,
format: "rfc5425",
formatter: "rfc5424",
framer: "rfc5425",
pattern: `\d+ \<30\>1 \d+-\d+-\d+.*`,
listenAddr: ":4000",
},
Expand All @@ -61,7 +66,8 @@ func Test_SyslogRunUdp(t *testing.T) {
config.Loggers.Syslog.Transport = tc.transport
config.Loggers.Syslog.RemoteAddress = tc.listenAddr
config.Loggers.Syslog.Mode = tc.mode
config.Loggers.Syslog.Formatter = tc.format
config.Loggers.Syslog.Formatter = tc.formatter
config.Loggers.Syslog.Framer = tc.framer

g := NewSyslog(config, logger.New(false), "test")

Expand Down Expand Up @@ -91,8 +97,6 @@ func Test_SyslogRunUdp(t *testing.T) {
t.Errorf("no data received")
}

print(string(buf))

re := regexp.MustCompile(tc.pattern)
if !re.MatchString(string(buf)) {
t.Errorf("syslog error want %s, got: %s", tc.pattern, string(buf))
Expand All @@ -106,39 +110,44 @@ func Test_SyslogRunTcp(t *testing.T) {
name string
transport string
mode string
format string
formatter string
framer string
pattern string
listenAddr string
}{
{
name: "unix_format",
transport: dnsutils.SOCKET_TCP,
mode: dnsutils.MODE_TEXT,
format: "unix",
pattern: `<30> \d+-\d+-\d+.*`,
formatter: "unix",
framer: "",
pattern: `<30>\D+ \d+ \d+:\d+:\d+.*`,
listenAddr: ":4000",
},
{
name: "rfc3164_format",
transport: dnsutils.SOCKET_TCP,
mode: dnsutils.MODE_TEXT,
format: "rfc3164",
pattern: "<30>.*",
formatter: "rfc3164",
framer: "",
pattern: `<30>\D+ \d+ \d+:\d+:\d+.*`,
listenAddr: ":4000",
},
{
name: "rfc5424_format",
transport: dnsutils.SOCKET_TCP,
mode: dnsutils.MODE_TEXT,
format: "rfc5424",
formatter: "rfc5424",
framer: "",
pattern: `<30>1 \d+-\d+-\d+.*`,
listenAddr: ":4000",
},
{
name: "rfc5425_format",
name: "rfc5425_format_rfc5425_framer",
transport: dnsutils.SOCKET_TCP,
mode: dnsutils.MODE_TEXT,
format: "rfc5425",
formatter: "rfc5424",
framer: "rfc5425",
pattern: `\d+ \<30\>1 \d+-\d+-\d+.*`,
listenAddr: ":4000",
},
Expand All @@ -151,7 +160,8 @@ func Test_SyslogRunTcp(t *testing.T) {
config.Loggers.Syslog.Transport = tc.transport
config.Loggers.Syslog.RemoteAddress = tc.listenAddr
config.Loggers.Syslog.Mode = tc.mode
config.Loggers.Syslog.Formatter = tc.format
config.Loggers.Syslog.Formatter = tc.formatter
config.Loggers.Syslog.Framer = tc.framer

g := NewSyslog(config, logger.New(false), "test")

Expand Down

0 comments on commit 70f1591

Please sign in to comment.