Skip to content

Commit

Permalink
Addressed review remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
catap committed May 22, 2024
1 parent 0320106 commit 1426356
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
17 changes: 15 additions & 2 deletions clients/pkg/promtail/scrapeconfig/scrapeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ type JournalTargetConfig struct {
Matches string `yaml:"matches"`
}

type SyslogFormat string

const (
// A modern Syslog RFC
SyslogFormatRFC5424 = "rfc5424"
// A legacy Syslog RFC also known as BSD-syslog
SyslogFormatRFC3164 = "rfc3164"
)

// SyslogTargetConfig describes a scrape config that listens for log lines over syslog.
type SyslogTargetConfig struct {
// ListenAddress is the address to listen on for syslog messages.
Expand Down Expand Up @@ -202,15 +211,19 @@ type SyslogTargetConfig struct {
// message should be pushed to Loki
UseRFC5424Message bool `yaml:"use_rfc5424_message"`

// IsRFC3164Message defines wether the log is formated as RFC3164
IsRFC3164Message bool `yaml:"is_rfc3164_message"`
// Used Sylog format at the target.
SyslogFormat SyslogFormat `yaml:"syslog_format"`

// MaxMessageLength sets the maximum limit to the length of syslog messages
MaxMessageLength int `yaml:"max_message_length"`

TLSConfig promconfig.TLSConfig `yaml:"tls_config,omitempty"`
}

func (config SyslogTargetConfig) IsRFC3164Message() bool {
return config.SyslogFormat == SyslogFormatRFC3164
}

// WindowsEventsTargetConfig describes a scrape config that listen for windows event logs.
type WindowsEventsTargetConfig struct {

Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/promtail/targets/syslog/syslogtarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (t *SyslogTarget) handleMessageRFC3164(connLabels labels.Labels, msg syslog
}

func (t *SyslogTarget) handleMessage(connLabels labels.Labels, msg syslog.Message) {
if t.config.IsRFC3164Message {
if t.config.IsRFC3164Message() {
t.handleMessageRFC3164(connLabels, msg)
} else {
t.handleMessageRFC5424(connLabels, msg)
Expand Down
4 changes: 2 additions & 2 deletions clients/pkg/promtail/targets/syslog/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (t *TCPTransport) handleConnection(cn net.Conn) {

lbs := t.connectionLabels(ipFromConn(c).String())

err := syslogparser.ParseStream(t.config.IsRFC3164Message, c, func(result *syslog.Result) {
err := syslogparser.ParseStream(t.config.IsRFC3164Message(), c, func(result *syslog.Result) {
if err := result.Error; err != nil {
t.handleMessageError(err)
return
Expand Down Expand Up @@ -397,7 +397,7 @@ func (t *UDPTransport) handleRcv(c *ConnPipe) {

r := bytes.NewReader(datagram[:n])

err = syslogparser.ParseStream(t.config.IsRFC3164Message, r, func(result *syslog.Result) {
err = syslogparser.ParseStream(t.config.IsRFC3164Message(), r, func(result *syslog.Result) {
if err := result.Error; err != nil {
t.handleMessageError(err)
} else {
Expand Down
14 changes: 11 additions & 3 deletions docs/sources/send-data/promtail/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -865,9 +865,10 @@ Priority label is available as both value and keyword. For example, if `priority
### syslog

The `syslog` block configures a syslog listener allowing users to push
logs to Promtail with the syslog protocol.
Currently supported is [IETF Syslog (RFC5424)](https://tools.ietf.org/html/rfc5424)
with and without octet counting.
logs to Promtail with the syslog protocol. Currently supported both
[BSD syslog Protocol](https://datatracker.ietf.org/doc/html/rfc3164) and
[IETF Syslog (RFC5424)](https://tools.ietf.org/html/rfc5424) with and
without octet counting.

The recommended deployment is to have a dedicated syslog forwarder like **syslog-ng** or **rsyslog**
in front of Promtail. The forwarder can take care of the various specifications
Expand Down Expand Up @@ -918,6 +919,13 @@ use_incoming_timestamp: <bool>
# Sets the maximum limit to the length of syslog messages
max_message_length: <int>
# Defines used Sylog format at the target.
syslog_format:
[type: <string> | default = "rfc5424"]
# Defines whether the full RFC5424 formatted syslog message should be pushed to Loki
use_rfc5424_message: <bool>
```

#### Available Labels
Expand Down

0 comments on commit 1426356

Please sign in to comment.