Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

out_syslog: when using a message key, avoid prefixing raw messages #6896

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions plugins/out_syslog/syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,21 @@ static char rfc5424_sp_name[256] = {
static flb_sds_t syslog_rfc5424(flb_sds_t *s, struct flb_time *tms,
struct syslog_msg *msg)
{
int len;
struct tm tm;
flb_sds_t tmp;
uint8_t prival;

if (msg->message && msg->message[0] == '<') {
len = flb_sds_len(msg->message);
tmp = flb_sds_cat(*s, msg->message, len);
if (!tmp) {
return NULL;
}
*s = tmp;
return *s;
}

prival = (msg->facility << 3) + msg->severity;

if (gmtime_r(&(tms->tm.tv_sec), &tm) == NULL) {
Expand All @@ -163,7 +174,7 @@ static flb_sds_t syslog_rfc5424(flb_sds_t *s, struct flb_time *tms,
*s = tmp;

if (msg->hostname) {
int len = flb_sds_len(msg->hostname);
len = flb_sds_len(msg->hostname);
tmp = flb_sds_cat(*s, msg->hostname, len > 255 ? 255 : len);
if (!tmp) {
return NULL;
Expand All @@ -185,7 +196,7 @@ static flb_sds_t syslog_rfc5424(flb_sds_t *s, struct flb_time *tms,
*s = tmp;

if (msg->appname) {
int len = flb_sds_len(msg->appname);
len = flb_sds_len(msg->appname);
tmp = flb_sds_cat(*s, msg->appname, len > 48 ? 48 : len);
if (!tmp) {
return NULL;
Expand All @@ -207,7 +218,7 @@ static flb_sds_t syslog_rfc5424(flb_sds_t *s, struct flb_time *tms,
*s = tmp;

if (msg->procid) {
int len = flb_sds_len(msg->procid);
len = flb_sds_len(msg->procid);
tmp = flb_sds_cat(*s, msg->procid, len > 128 ? 128 : len);
if (!tmp) {
return NULL;
Expand All @@ -229,7 +240,7 @@ static flb_sds_t syslog_rfc5424(flb_sds_t *s, struct flb_time *tms,
*s = tmp;

if (msg->msgid) {
int len = flb_sds_len(msg->msgid);
len = flb_sds_len(msg->msgid);
tmp = flb_sds_cat(*s, msg->msgid, len > 32 ? 32 : len);
if (!tmp) {
return NULL;
Expand Down Expand Up @@ -266,7 +277,7 @@ static flb_sds_t syslog_rfc5424(flb_sds_t *s, struct flb_time *tms,
}

if (msg->message) {
int len = flb_sds_len(msg->message);
len = flb_sds_len(msg->message);
tmp = flb_sds_cat(*s, " \xef\xbb\xbf", 4);
if (!tmp) {
return NULL;
Expand All @@ -285,10 +296,21 @@ static flb_sds_t syslog_rfc5424(flb_sds_t *s, struct flb_time *tms,
static flb_sds_t syslog_rfc3164 (flb_sds_t *s, struct flb_time *tms,
struct syslog_msg *msg)
{
int len;
struct tm tm;
flb_sds_t tmp;
uint8_t prival;

if (msg->message && msg->message[0] == '<') {
len = flb_sds_len(msg->message);
tmp = flb_sds_cat(*s, msg->message, len);
if (!tmp) {
return NULL;
}
*s = tmp;
return *s;
}

prival = (msg->facility << 3) + msg->severity;

if (gmtime_r(&(tms->tm.tv_sec), &tm) == NULL) {
Expand Down Expand Up @@ -777,6 +799,7 @@ static void cb_syslog_flush(struct flb_event_chunk *event_chunk,

if (ctx->parsed_mode != FLB_SYSLOG_UDP) {
u_conn = flb_upstream_conn_get(ctx->u);

if (!u_conn) {
flb_plg_error(ctx->ins, "no upstream connections available");
FLB_OUTPUT_RETURN(FLB_RETRY);
Expand Down
Loading