Skip to content

Instantly share code, notes, and snippets.

@nokute78
Created February 2, 2017 13:12
Show Gist options
  • Save nokute78/67712ad25cbf829d12f4c1dece842ab7 to your computer and use it in GitHub Desktop.
Save nokute78/67712ad25cbf829d12f4c1dece842ab7 to your computer and use it in GitHub Desktop.
sample code for filter plugin
#include <unistd.h>
#include <fluent-bit.h>
#include <msgpack.h>
int my_stdout_json(void* data, size_t size)
{
printf("[%s]",__FUNCTION__);
printf("%s",(char*)data);
printf("\n");
/* User has to release the buffer. */
flb_free(data);
return 0;
}
int main()
{
flb_ctx_t *ctx;
int in_ffd;
int out_ffd;
int filter_ffd;
/* Initialize library */
ctx = flb_create();
if (!ctx) {
exit(EXIT_FAILURE);
}
in_ffd = flb_input(ctx, "cpu", NULL);
flb_input_set(ctx, in_ffd, "tag", "test", NULL);
out_ffd = flb_output(ctx, "lib", my_stdout_json);
flb_output_set(ctx, out_ffd, "match", "test", "format", "json", NULL);
filter_ffd = flb_filter(ctx, "stdout", NULL);
flb_filter_set(ctx, filter_ffd, "match", "*", NULL);
/* Start the background worker */
flb_start(ctx);
sleep(10);
flb_stop(ctx);
/* Release Resources */
flb_destroy(ctx);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment