fluent-bit: Align syslog output with syslog-ng

- added support to prepend message length in syslog output
This commit is contained in:
Husaam Mehdi 2025-05-30 03:57:19 +00:00 committed by IOPSYS Dev
parent 7227cbd8da
commit 09cccc39cc
No known key found for this signature in database

View file

@ -0,0 +1,47 @@
diff --git a/plugins/out_syslog/syslog.c b/plugins/out_syslog/syslog.c
index 4ecc7c4ac..cfe568245 100644
--- a/plugins/out_syslog/syslog.c
+++ b/plugins/out_syslog/syslog.c
@@ -776,12 +776,42 @@ static flb_sds_t syslog_format(struct flb_syslog *ctx, msgpack_object *o,
}
if (ctx->parsed_mode != FLB_SYSLOG_UDP) {
+ unsigned int msg_len = 0;
+
+ /* Create new SDS for length prefix */
+ flb_sds_t prefix = flb_sds_create_size(ctx->maxsize + 32);
+ if (!prefix) {
+ ret_sds = NULL;
+ goto clean;
+ }
+
+ /* Add newline also to make behaviour similar to syslog-ng */
tmp = flb_sds_cat(*s, "\n", 1);
if (!tmp) {
+ flb_sds_destroy(prefix);
ret_sds = NULL;
goto clean;
}
*s = tmp;
+
+ msg_len = flb_sds_len(*s);
+ tmp = flb_sds_printf(&prefix, "%u ", msg_len);
+ if (!tmp) {
+ flb_sds_destroy(prefix);
+ ret_sds = NULL;
+ goto clean;
+ }
+ prefix = tmp;
+
+ tmp = flb_sds_cat(prefix, *s, msg_len);
+ if (!tmp) {
+ flb_sds_destroy(prefix);
+ ret_sds = NULL;
+ goto clean;
+ }
+
+ flb_sds_destroy(*s);
+ *s = tmp;
}
}
else {