out_syslog: add formatter callback
@@ -919,6 +919,69 @@ static int cb_syslog_exit(void *data, struct flb_config *config)
return 0;
}
+
+/* for testing */
+static int cb_syslog_format_test(struct flb_config *config,
+ struct flb_input_instance *ins,
+ void *plugin_context,
+ void *flush_ctx,
+ const char *tag, int tag_len,
+ const void *data, size_t bytes,
+ void **out_data, size_t *out_size)
+{
+ struct flb_syslog *ctx = plugin_context;
+ flb_sds_t tmp;
+ flb_sds_t s;
+ size_t off = 0;
+ msgpack_unpacked result;
+ msgpack_object root;
+ msgpack_object map;
+ msgpack_object *obj;
+ struct flb_time tm;
+
+ s = flb_sds_create_size(ctx->maxsize);
+ if (s == NULL) {
+ flb_error("flb_sds_create_size failed");
+ return -1;
+ }
+
+ msgpack_unpacked_init(&result);
+
+ if ( msgpack_unpack_next(&result, data, bytes, &off) != MSGPACK_UNPACK_SUCCESS) {
+ msgpack_unpacked_destroy(&result);
+ flb_error("msgpack_unpack_next failed");
+ return -1;
+ }
+ if (result.data.type != MSGPACK_OBJECT_ARRAY) {
+ msgpack_object_print(stdout, result.data);
+ msgpack_unpacked_destroy(&result);
+ flb_error("data is not array");
+ return -1;
+ }
+
+ root = result.data;
+ if (root.via.array.size != 2) {
+ msgpack_unpacked_destroy(&result);
+ flb_error("array size is not 2. size=%d", root.via.array.size);
+ return -1;
+ }
+ flb_time_pop_from_msgpack(&tm, &result, &obj);
+ map = root.via.array.ptr[1];
+ flb_sds_len_set(s, 0);
+ tmp = syslog_format(ctx, &map, &s, &tm);
+
+ msgpack_unpacked_destroy(&result);
+ if (tmp == NULL) {
+ flb_error("syslog_fromat returns NULL");
+ return -1;
+ }
+
+ *out_data = tmp;
+ *out_size = flb_sds_len(tmp);
+
+ return 0;
+}
+
/* Configuration properties map */
static struct flb_config_map config_map[] = {
{
@@ -1017,6 +1080,9 @@ struct flb_output_plugin out_syslog_plugin = {
/* Configuration */
.config_map = config_map,
+ /* for testing */
+ .test_formatter.callback = cb_syslog_format_test,
+
/* Plugin flags */
.flags = FLB_OUTPUT_NET | FLB_IO_OPT_TLS,
};
