From 65639403fb9a51f302383f074b1aac5e9ef6dc64 Mon Sep 17 00:00:00 2001 From: g41797 Date: Mon, 30 Oct 2023 11:21:06 +0200 Subject: [PATCH] Adjust e2e tests --- README.md | 8 ++++---- e2e/client.go | 8 ++++---- syslogconf.go | 10 +++++++++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1cb722a..39d6ce6 100644 --- a/README.md +++ b/README.md @@ -232,11 +232,11 @@ Examples of producer: - [producer for NATS](https://github.com/g41797/syslog2nats/blob/main/msgproducer.go) - [producer for Memphis](https://github.com/g41797/memphis-protocol-adapter/blob/master/pkg/syslog/msgproducer.go) - ## Advanced configuration + ### Advanced configuration and helper functions for producer [syslog.conf](https://linux.die.net/man/5/syslog.conf) file contains logging rules for syslogd. -syslogsidecar support similar functionality via *syslogconf.json* file within configurations folder. +syslogsidecar support similar functionality via *syslogconf.json* file within configurations folder and 2 helper functions for producer. *syslogconf.json* file should be provided by developer of the syslogsidecar for specific broker. @@ -274,7 +274,7 @@ Example of syslogconf.json used by syslogsidecar in e2e test: *Selector* contains rule based on facilities and or severities of the message in question. -*Target* contains where message should be published to. It may be topic, station, subject, folder, etc - it depends on functionality of specific broker. +*Target* contains where message should be published to. It may be topic, station, subject, folder, combination of configuration parameters, etc - it depends on functionality of specific broker. One requirement - not empty valid for JSON format string. E.g. for the configuration above: @@ -312,7 +312,7 @@ All badly formatted messages should be published to "badmessages-topic" } ``` -List of targets for the message producer can get from *syslogsidecar.Targets* function: +Producer can get list of targets for the message from *syslogsidecar.Targets* function: ```go // Returns list of non-repeating "targets" for the message according to facility and severity // of the message and content of syslogconf.json file. diff --git a/e2e/client.go b/e2e/client.go index de4aa4b..22cde21 100644 --- a/e2e/client.go +++ b/e2e/client.go @@ -274,13 +274,13 @@ func (cl *client) report() { } func (cl *client) openLoggers() error { - lgr, err := newLogWriter(cl.conf, srslog.RFC3164Formatter) + lgr, err := newLogWriter(cl.conf, srslog.RFC3164Formatter, srslog.LOG_LOCAL0+srslog.LOG_EMERG) if err != nil { return err } cl.loggers[0] = lgr - lgr, err = newLogWriter(cl.conf, srslog.RFC5424Formatter) + lgr, err = newLogWriter(cl.conf, srslog.RFC5424Formatter, srslog.LOG_WARNING) if err != nil { cl.loggers[0].Close() cl.loggers[0] = nil @@ -298,8 +298,8 @@ func (cl *client) closeLoggers() { } } -func newLogWriter(cnf syslogsidecar.SyslogConfiguration, rfcForm srslog.Formatter) (*srslog.Writer, error) { - w, err := srslog.Dial("tcp", cnf.ADDRTCP, srslog.LOG_ALERT, "re2e") +func newLogWriter(cnf syslogsidecar.SyslogConfiguration, rfcForm srslog.Formatter, pri srslog.Priority) (*srslog.Writer, error) { + w, err := srslog.Dial("tcp", cnf.ADDRTCP, pri, "re2e") if err != nil { return nil, err } diff --git a/syslogconf.go b/syslogconf.go index 6ed4a17..16bfd4e 100644 --- a/syslogconf.go +++ b/syslogconf.go @@ -228,6 +228,9 @@ func (se *slfEntry) toFinder() (*targetFinder, error) { severities := strings.Split(after, ",") for _, sev := range severities { + if len(sev) == 0 { + continue + } if !isSeverity(sev) { return nil, fmt.Errorf("wrong severity %s", sev) } @@ -237,7 +240,12 @@ func (se *slfEntry) toFinder() (*targetFinder, error) { } } - tf.gettarget = tf.severitiesOfFacitity + if len(tf.severities) == 0 { + tf.gettarget = tf.listoffacilities + } else { + tf.gettarget = tf.severitiesOfFacitity + } + return tf, nil } // s1,s2,....sN or f1,f2,...fN ?