Skip to content

Commit 1426356

Browse files
committed
Addressed review remarks
1 parent 0320106 commit 1426356

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

clients/pkg/promtail/scrapeconfig/scrapeconfig.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,15 @@ type JournalTargetConfig struct {
174174
Matches string `yaml:"matches"`
175175
}
176176

177+
type SyslogFormat string
178+
179+
const (
180+
// A modern Syslog RFC
181+
SyslogFormatRFC5424 = "rfc5424"
182+
// A legacy Syslog RFC also known as BSD-syslog
183+
SyslogFormatRFC3164 = "rfc3164"
184+
)
185+
177186
// SyslogTargetConfig describes a scrape config that listens for log lines over syslog.
178187
type SyslogTargetConfig struct {
179188
// ListenAddress is the address to listen on for syslog messages.
@@ -202,15 +211,19 @@ type SyslogTargetConfig struct {
202211
// message should be pushed to Loki
203212
UseRFC5424Message bool `yaml:"use_rfc5424_message"`
204213

205-
// IsRFC3164Message defines wether the log is formated as RFC3164
206-
IsRFC3164Message bool `yaml:"is_rfc3164_message"`
214+
// Used Sylog format at the target.
215+
SyslogFormat SyslogFormat `yaml:"syslog_format"`
207216

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

211220
TLSConfig promconfig.TLSConfig `yaml:"tls_config,omitempty"`
212221
}
213222

223+
func (config SyslogTargetConfig) IsRFC3164Message() bool {
224+
return config.SyslogFormat == SyslogFormatRFC3164
225+
}
226+
214227
// WindowsEventsTargetConfig describes a scrape config that listen for windows event logs.
215228
type WindowsEventsTargetConfig struct {
216229

clients/pkg/promtail/targets/syslog/syslogtarget.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func (t *SyslogTarget) handleMessageRFC3164(connLabels labels.Labels, msg syslog
225225
}
226226

227227
func (t *SyslogTarget) handleMessage(connLabels labels.Labels, msg syslog.Message) {
228-
if t.config.IsRFC3164Message {
228+
if t.config.IsRFC3164Message() {
229229
t.handleMessageRFC3164(connLabels, msg)
230230
} else {
231231
t.handleMessageRFC5424(connLabels, msg)

clients/pkg/promtail/targets/syslog/transport.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ func (t *TCPTransport) handleConnection(cn net.Conn) {
272272

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

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

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

400-
err = syslogparser.ParseStream(t.config.IsRFC3164Message, r, func(result *syslog.Result) {
400+
err = syslogparser.ParseStream(t.config.IsRFC3164Message(), r, func(result *syslog.Result) {
401401
if err := result.Error; err != nil {
402402
t.handleMessageError(err)
403403
} else {

docs/sources/send-data/promtail/configuration.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -865,9 +865,10 @@ Priority label is available as both value and keyword. For example, if `priority
865865
### syslog
866866

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

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

923931
#### Available Labels

0 commit comments

Comments
 (0)