Commit 81da849f authored by Xiaowu Zhang's avatar Xiaowu Zhang

example to get parameters

parent c4dc05e7
[SERVICE] [SERVICE]
Flush 5 flush 5
Daemon off
[INPUT] [INPUT]
Name cpu name cpu
[output] [output]
Name http name wendelin_fluentbit
Match * match *
Host softinst143538.host.vifib.net streamtool_uri https://softinst143538.host.vifib.net
URI /erp5/fluentbit_upload_test user xx
password xx
buffer_type memory
flush_interval 60s
disable_retry_limit true
...@@ -13,28 +13,41 @@ import ( ...@@ -13,28 +13,41 @@ import (
//export FLBPluginRegister //export FLBPluginRegister
func FLBPluginRegister(def unsafe.Pointer) int { func FLBPluginRegister(def unsafe.Pointer) int {
return output.FLBPluginRegister(def, "gstdout", "Stdout GO!") return output.FLBPluginRegister(def, "wendelin_fluentbit", "Wendelin Fluentbit")
} }
//export FLBPluginInit //export FLBPluginInit
// (fluentbit will call this) // (fluentbit will call this)
// plugin (context) pointer to fluentbit context (state/ c code) // plugin (context) pointer to fluentbit context (state/ c code)
func FLBPluginInit(plugin unsafe.Pointer) int { func FLBPluginInit(plugin unsafe.Pointer) int {
// Example to retrieve an optional configuration parameter streamtool_uri := output.FLBPluginConfigKey(plugin, "streamtool_uri")
param := output.FLBPluginConfigKey(plugin, "param") user := output.FLBPluginConfigKey(plugin, "user")
fmt.Printf("[flb-go] plugin parameter = '%s'\n", param) password := output.FLBPluginConfigKey(plugin, "password")
buffer_type := output.FLBPluginConfigKey(plugin, "buffer_type")
flush_interval := output.FLBPluginConfigKey(plugin, "flush_interval")
disable_retry_limit := output.FLBPluginConfigKey(plugin, "disable_retry_limit")
dict := map[string]string{
"streamtool_uri": streamtool_uri,
"user": user,
"password": password,
"buffer_type": buffer_type,
"flush_interval": flush_interval,
"disable_retry_limit": disable_retry_limit,
}
output.FLBPluginSetContext(plugin, dict)
return output.FLB_OK return output.FLB_OK
} }
//export FLBPluginFlush //export FLBPluginFlushCtx
func FLBPluginFlush(data unsafe.Pointer, length C.int, tag *C.char) int { func FLBPluginFlushCtx(ctx, data unsafe.Pointer, length C.int, tag *C.char) int {
var count int var count int
var ret int var ret int
var ts interface{} var ts interface{}
var record map[interface{}]interface{} var record map[interface{}]interface{}
// Create Fluent Bit decoder // Create Fluent Bit decoder
dec := output.NewDecoder(data, int(length)) dec := output.NewDecoder(data, int(length))
dict := output.FLBPluginGetContext(ctx).(map[string]string)
fmt.Printf("streamtool_uri %s \n", dict["streamtool_uri"])
// Iterate Records // Iterate Records
count = 0 count = 0
var result string var result string
......
...@@ -73,7 +73,7 @@ extern GoInt FLBPluginRegister(void* def); ...@@ -73,7 +73,7 @@ extern GoInt FLBPluginRegister(void* def);
// (fluentbit will call this) // (fluentbit will call this)
// plugin (context) pointer to fluentbit context (state/ c code) // plugin (context) pointer to fluentbit context (state/ c code)
extern GoInt FLBPluginInit(void* plugin); extern GoInt FLBPluginInit(void* plugin);
extern GoInt FLBPluginFlush(void* data, int length, char* tag); extern GoInt FLBPluginFlushCtx(void* ctx, void* data, int length, char* tag);
extern GoInt FLBPluginExit(); extern GoInt FLBPluginExit();
#ifdef __cplusplus #ifdef __cplusplus
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment