Syslog Driver: RFC 5425 Framing should be used only when protocol is TCP+TLS
Signed-off-by: Ferran Rodenas <frodenas@gmail.com>
This commit is contained in:
parent
e904f58e19
commit
4039bfc917
|
@ -105,7 +105,7 @@ func New(ctx logger.Context) (logger.Logger, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
syslogFormatter, syslogFramer, err := parseLogFormat(ctx.Config["syslog-format"])
|
||||
syslogFormatter, syslogFramer, err := parseLogFormat(ctx.Config["syslog-format"], proto)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -205,7 +205,7 @@ func ValidateLogOpt(cfg map[string]string) error {
|
|||
if _, err := parseFacility(cfg["syslog-facility"]); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, _, err := parseLogFormat(cfg["syslog-format"]); err != nil {
|
||||
if _, _, err := parseLogFormat(cfg["syslog-format"], ""); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -241,16 +241,22 @@ func parseTLSConfig(cfg map[string]string) (*tls.Config, error) {
|
|||
return tlsconfig.Client(opts)
|
||||
}
|
||||
|
||||
func parseLogFormat(logFormat string) (syslog.Formatter, syslog.Framer, error) {
|
||||
func parseLogFormat(logFormat, proto string) (syslog.Formatter, syslog.Framer, error) {
|
||||
switch logFormat {
|
||||
case "":
|
||||
return syslog.UnixFormatter, syslog.DefaultFramer, nil
|
||||
case "rfc3164":
|
||||
return syslog.RFC3164Formatter, syslog.DefaultFramer, nil
|
||||
case "rfc5424":
|
||||
return rfc5424formatterWithAppNameAsTag, syslog.RFC5425MessageLengthFramer, nil
|
||||
if proto == secureProto {
|
||||
return rfc5424formatterWithAppNameAsTag, syslog.RFC5425MessageLengthFramer, nil
|
||||
}
|
||||
return rfc5424formatterWithAppNameAsTag, syslog.DefaultFramer, nil
|
||||
case "rfc5424micro":
|
||||
return rfc5424microformatterWithAppNameAsTag, syslog.RFC5425MessageLengthFramer, nil
|
||||
if proto == secureProto {
|
||||
return rfc5424microformatterWithAppNameAsTag, syslog.RFC5425MessageLengthFramer, nil
|
||||
}
|
||||
return rfc5424microformatterWithAppNameAsTag, syslog.DefaultFramer, nil
|
||||
default:
|
||||
return nil, nil, errors.New("Invalid syslog format")
|
||||
}
|
||||
|
|
|
@ -13,31 +13,43 @@ func functionMatches(expectedFun interface{}, actualFun interface{}) bool {
|
|||
}
|
||||
|
||||
func TestParseLogFormat(t *testing.T) {
|
||||
formatter, framer, err := parseLogFormat("rfc5424")
|
||||
formatter, framer, err := parseLogFormat("rfc5424", "udp")
|
||||
if err != nil || !functionMatches(rfc5424formatterWithAppNameAsTag, formatter) ||
|
||||
!functionMatches(syslog.DefaultFramer, framer) {
|
||||
t.Fatal("Failed to parse rfc5424 format", err, formatter, framer)
|
||||
}
|
||||
|
||||
formatter, framer, err = parseLogFormat("rfc5424", "tcp+tls")
|
||||
if err != nil || !functionMatches(rfc5424formatterWithAppNameAsTag, formatter) ||
|
||||
!functionMatches(syslog.RFC5425MessageLengthFramer, framer) {
|
||||
t.Fatal("Failed to parse rfc5424 format", err, formatter, framer)
|
||||
}
|
||||
|
||||
formatter, framer, err = parseLogFormat("rfc5424micro")
|
||||
formatter, framer, err = parseLogFormat("rfc5424micro", "udp")
|
||||
if err != nil || !functionMatches(rfc5424microformatterWithAppNameAsTag, formatter) ||
|
||||
!functionMatches(syslog.DefaultFramer, framer) {
|
||||
t.Fatal("Failed to parse rfc5424 (microsecond) format", err, formatter, framer)
|
||||
}
|
||||
|
||||
formatter, framer, err = parseLogFormat("rfc5424micro", "tcp+tls")
|
||||
if err != nil || !functionMatches(rfc5424microformatterWithAppNameAsTag, formatter) ||
|
||||
!functionMatches(syslog.RFC5425MessageLengthFramer, framer) {
|
||||
t.Fatal("Failed to parse rfc5424 (microsecond) format", err, formatter, framer)
|
||||
}
|
||||
|
||||
formatter, framer, err = parseLogFormat("rfc3164")
|
||||
formatter, framer, err = parseLogFormat("rfc3164", "")
|
||||
if err != nil || !functionMatches(syslog.RFC3164Formatter, formatter) ||
|
||||
!functionMatches(syslog.DefaultFramer, framer) {
|
||||
t.Fatal("Failed to parse rfc3164 format", err, formatter, framer)
|
||||
}
|
||||
|
||||
formatter, framer, err = parseLogFormat("")
|
||||
formatter, framer, err = parseLogFormat("", "")
|
||||
if err != nil || !functionMatches(syslog.UnixFormatter, formatter) ||
|
||||
!functionMatches(syslog.DefaultFramer, framer) {
|
||||
t.Fatal("Failed to parse empty format", err, formatter, framer)
|
||||
}
|
||||
|
||||
formatter, framer, err = parseLogFormat("invalid")
|
||||
formatter, framer, err = parseLogFormat("invalid", "")
|
||||
if err == nil {
|
||||
t.Fatal("Failed to parse invalid format", err, formatter, framer)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue