1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #24153 from frodenas/syslog-fix

Syslog Driver: RFC 5425 Message Framing should be used only when protocol is TCP+TLS
This commit is contained in:
Brian Goff 2016-08-25 12:15:06 -04:00 committed by GitHub
commit 15f3d060ac
2 changed files with 28 additions and 10 deletions

View file

@ -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")
}

View file

@ -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)
}