Skip to content

Commit

Permalink
Adjust e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
g41797 committed Oct 30, 2023
1 parent adf0a20 commit 6563940
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions e2e/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
10 changes: 9 additions & 1 deletion syslogconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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 ?
Expand Down

0 comments on commit 6563940

Please sign in to comment.