Skip to content

Commit d59715e

Browse files
committed
out_syslog: when using a message key, avoid prefixing raw messages
Signed-off-by: Eduardo Silva <[email protected]>
1 parent 92e0435 commit d59715e

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

plugins/out_syslog/syslog.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,21 @@ static char rfc5424_sp_name[256] = {
144144
static flb_sds_t syslog_rfc5424(flb_sds_t *s, struct flb_time *tms,
145145
struct syslog_msg *msg)
146146
{
147+
int len;
147148
struct tm tm;
148149
flb_sds_t tmp;
149150
uint8_t prival;
150151

152+
if (msg->message && msg->message[0] == '<') {
153+
len = flb_sds_len(msg->message);
154+
tmp = flb_sds_cat(*s, msg->message, len);
155+
if (!tmp) {
156+
return NULL;
157+
}
158+
*s = tmp;
159+
return *s;
160+
}
161+
151162
prival = (msg->facility << 3) + msg->severity;
152163

153164
if (gmtime_r(&(tms->tm.tv_sec), &tm) == NULL) {
@@ -164,7 +175,7 @@ static flb_sds_t syslog_rfc5424(flb_sds_t *s, struct flb_time *tms,
164175
*s = tmp;
165176

166177
if (msg->hostname) {
167-
int len = flb_sds_len(msg->hostname);
178+
len = flb_sds_len(msg->hostname);
168179
tmp = flb_sds_cat(*s, msg->hostname, len > 255 ? 255 : len);
169180
if (!tmp) {
170181
return NULL;
@@ -186,7 +197,7 @@ static flb_sds_t syslog_rfc5424(flb_sds_t *s, struct flb_time *tms,
186197
*s = tmp;
187198

188199
if (msg->appname) {
189-
int len = flb_sds_len(msg->appname);
200+
len = flb_sds_len(msg->appname);
190201
tmp = flb_sds_cat(*s, msg->appname, len > 48 ? 48 : len);
191202
if (!tmp) {
192203
return NULL;
@@ -208,7 +219,7 @@ static flb_sds_t syslog_rfc5424(flb_sds_t *s, struct flb_time *tms,
208219
*s = tmp;
209220

210221
if (msg->procid) {
211-
int len = flb_sds_len(msg->procid);
222+
len = flb_sds_len(msg->procid);
212223
tmp = flb_sds_cat(*s, msg->procid, len > 128 ? 128 : len);
213224
if (!tmp) {
214225
return NULL;
@@ -230,7 +241,7 @@ static flb_sds_t syslog_rfc5424(flb_sds_t *s, struct flb_time *tms,
230241
*s = tmp;
231242

232243
if (msg->msgid) {
233-
int len = flb_sds_len(msg->msgid);
244+
len = flb_sds_len(msg->msgid);
234245
tmp = flb_sds_cat(*s, msg->msgid, len > 32 ? 32 : len);
235246
if (!tmp) {
236247
return NULL;
@@ -267,7 +278,7 @@ static flb_sds_t syslog_rfc5424(flb_sds_t *s, struct flb_time *tms,
267278
}
268279

269280
if (msg->message) {
270-
int len = flb_sds_len(msg->message);
281+
len = flb_sds_len(msg->message);
271282
tmp = flb_sds_cat(*s, " \xef\xbb\xbf", 4);
272283
if (!tmp) {
273284
return NULL;
@@ -286,10 +297,21 @@ static flb_sds_t syslog_rfc5424(flb_sds_t *s, struct flb_time *tms,
286297
static flb_sds_t syslog_rfc3164 (flb_sds_t *s, struct flb_time *tms,
287298
struct syslog_msg *msg)
288299
{
300+
int len;
289301
struct tm tm;
290302
flb_sds_t tmp;
291303
uint8_t prival;
292304

305+
if (msg->message && msg->message[0] == '<') {
306+
len = flb_sds_len(msg->message);
307+
tmp = flb_sds_cat(*s, msg->message, len);
308+
if (!tmp) {
309+
return NULL;
310+
}
311+
*s = tmp;
312+
return *s;
313+
}
314+
293315
prival = (msg->facility << 3) + msg->severity;
294316

295317
if (gmtime_r(&(tms->tm.tv_sec), &tm) == NULL) {
@@ -797,6 +819,7 @@ static void cb_syslog_flush(struct flb_event_chunk *event_chunk,
797819

798820
if (ctx->parsed_mode != FLB_SYSLOG_UDP) {
799821
u_conn = flb_upstream_conn_get(ctx->u);
822+
800823
if (!u_conn) {
801824
flb_plg_error(ctx->ins, "no upstream connections available");
802825
FLB_OUTPUT_RETURN(FLB_RETRY);

0 commit comments

Comments
 (0)