Skip to content

Commit 8fba360

Browse files
committed
in_syslog: Encoding parameter for input plugin for conversion to UTF8
Signed-off-by: Nigel Stewart <[email protected]>
1 parent 4b14f3b commit 8fba360

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

plugins/in_syslog/syslog.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <fluent-bit/flb_info.h>
2525
#include <fluent-bit/flb_input.h>
26+
#include <fluent-bit/flb_encode.h>
2627

2728
/* Syslog modes */
2829
#define FLB_SYSLOG_UNIX_TCP 1
@@ -56,6 +57,9 @@ struct flb_syslog {
5657
size_t buffer_max_size;
5758
size_t buffer_chunk_size;
5859

60+
/* text encoding, NULL for UTF8 */
61+
flb_encoder encoding;
62+
5963
/* Configuration */
6064
struct flb_parser *parser;
6165

plugins/in_syslog/syslog_conf.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@ struct flb_syslog *syslog_conf_create(struct flb_input_instance *i_ins,
131131
ctx->buffer_max_size = flb_utils_size_to_bytes(tmp);
132132
}
133133

134+
/* Config: Text encoding other than UTF-8 */
135+
tmp = flb_input_get_property("encoding", i_ins);
136+
if (tmp) {
137+
ctx->encoding = flb_get_encoder(tmp);
138+
if (!ctx->encoding) {
139+
flb_error("[in_syslog] encoding '%s' is not supported", tmp);
140+
}
141+
}
142+
134143
/* Parser */
135144
tmp = flb_input_get_property("parser", i_ins);
136145
if (tmp) {

plugins/in_syslog/syslog_prot.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <fluent-bit/flb_info.h>
2424
#include <fluent-bit/flb_parser.h>
2525
#include <fluent-bit/flb_time.h>
26+
#include <fluent-bit/flb_encode.h>
2627

2728
#include "syslog.h"
2829
#include "syslog_conn.h"
@@ -44,7 +45,7 @@ static inline int pack_line(struct flb_syslog *ctx,
4445

4546
msgpack_pack_array(&mp_pck, 2);
4647
flb_time_append_to_msgpack(time, &mp_pck, 0);
47-
msgpack_sbuffer_write(&mp_sbuf, data, data_size);
48+
flb_msgpack_encode_utf8(ctx->encoding, &mp_pck, data, data_size);
4849

4950
flb_input_chunk_append_raw(ctx->i_ins, NULL, 0, mp_sbuf.data, mp_sbuf.size);
5051
msgpack_sbuffer_destroy(&mp_sbuf);

0 commit comments

Comments
 (0)