Skip to content

Commit 063a775

Browse files
nokute78edsiper
authored andcommitted
out_syslog: add formatter callback
Signed-off-by: Takahiro Yamashita <[email protected]>
1 parent 17378fc commit 063a775

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

plugins/out_syslog/syslog.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,69 @@ static int cb_syslog_exit(void *data, struct flb_config *config)
919919
return 0;
920920
}
921921

922+
923+
/* for testing */
924+
static int cb_syslog_format_test(struct flb_config *config,
925+
struct flb_input_instance *ins,
926+
void *plugin_context,
927+
void *flush_ctx,
928+
const char *tag, int tag_len,
929+
const void *data, size_t bytes,
930+
void **out_data, size_t *out_size)
931+
{
932+
struct flb_syslog *ctx = plugin_context;
933+
flb_sds_t tmp;
934+
flb_sds_t s;
935+
size_t off = 0;
936+
msgpack_unpacked result;
937+
msgpack_object root;
938+
msgpack_object map;
939+
msgpack_object *obj;
940+
struct flb_time tm;
941+
942+
s = flb_sds_create_size(ctx->maxsize);
943+
if (s == NULL) {
944+
flb_error("flb_sds_create_size failed");
945+
return -1;
946+
}
947+
948+
msgpack_unpacked_init(&result);
949+
950+
if ( msgpack_unpack_next(&result, data, bytes, &off) != MSGPACK_UNPACK_SUCCESS) {
951+
msgpack_unpacked_destroy(&result);
952+
flb_error("msgpack_unpack_next failed");
953+
return -1;
954+
}
955+
if (result.data.type != MSGPACK_OBJECT_ARRAY) {
956+
msgpack_object_print(stdout, result.data);
957+
msgpack_unpacked_destroy(&result);
958+
flb_error("data is not array");
959+
return -1;
960+
}
961+
962+
root = result.data;
963+
if (root.via.array.size != 2) {
964+
msgpack_unpacked_destroy(&result);
965+
flb_error("array size is not 2. size=%d", root.via.array.size);
966+
return -1;
967+
}
968+
flb_time_pop_from_msgpack(&tm, &result, &obj);
969+
map = root.via.array.ptr[1];
970+
flb_sds_len_set(s, 0);
971+
tmp = syslog_format(ctx, &map, &s, &tm);
972+
973+
msgpack_unpacked_destroy(&result);
974+
if (tmp == NULL) {
975+
flb_error("syslog_fromat returns NULL");
976+
return -1;
977+
}
978+
979+
*out_data = tmp;
980+
*out_size = flb_sds_len(tmp);
981+
982+
return 0;
983+
}
984+
922985
/* Configuration properties map */
923986
static struct flb_config_map config_map[] = {
924987
{
@@ -1017,6 +1080,9 @@ struct flb_output_plugin out_syslog_plugin = {
10171080
/* Configuration */
10181081
.config_map = config_map,
10191082

1083+
/* for testing */
1084+
.test_formatter.callback = cb_syslog_format_test,
1085+
10201086
/* Plugin flags */
10211087
.flags = FLB_OUTPUT_NET | FLB_IO_OPT_TLS,
10221088
};

0 commit comments

Comments
 (0)