Commit c4dc05e7 authored by Xiaowu Zhang's avatar Xiaowu Zhang

example to stop after success

parent fd4571bd
...@@ -32,20 +32,13 @@ func FLBPluginFlush(data unsafe.Pointer, length C.int, tag *C.char) int { ...@@ -32,20 +32,13 @@ func FLBPluginFlush(data unsafe.Pointer, length C.int, tag *C.char) int {
var ret int var ret int
var ts interface{} var ts interface{}
var record map[interface{}]interface{} var record map[interface{}]interface{}
xxdata := url.Values{
"name": {"x"},
"occupation": {"y"},
}
_, err := http.PostForm("https://softinst140097.host.vifib.net/erp5/fluentbit_upload_test/", xxdata)
if err == nil {
os.Exit(0)
}
// Create Fluent Bit decoder // Create Fluent Bit decoder
dec := output.NewDecoder(data, int(length)) dec := output.NewDecoder(data, int(length))
// Iterate Records // Iterate Records
count = 0 count = 0
var result string
result = ""
for { for {
// Extract Record // Extract Record
ret, ts, record = output.GetRecord(dec) ret, ts, record = output.GetRecord(dec)
...@@ -65,12 +58,11 @@ func FLBPluginFlush(data unsafe.Pointer, length C.int, tag *C.char) int { ...@@ -65,12 +58,11 @@ func FLBPluginFlush(data unsafe.Pointer, length C.int, tag *C.char) int {
} }
// Print record keys and values // Print record keys and values
fmt.Printf("[%d] %s: [%s, {", count, C.GoString(tag), result = result + C.GoString(tag) + ":[" +timestamp.String()
timestamp.String())
for k, v := range record { for k, v := range record {
fmt.Printf("\"%s\": %v, ", k, v) result = result + fmt.Sprintf("%s: %v", k,v)
} }
fmt.Printf("}\n") result += "}\n"
count++ count++
} }
...@@ -79,7 +71,17 @@ func FLBPluginFlush(data unsafe.Pointer, length C.int, tag *C.char) int { ...@@ -79,7 +71,17 @@ func FLBPluginFlush(data unsafe.Pointer, length C.int, tag *C.char) int {
// output.FLB_OK = data have been processed. // output.FLB_OK = data have been processed.
// output.FLB_ERROR = unrecoverable error, do not try this again. // output.FLB_ERROR = unrecoverable error, do not try this again.
// output.FLB_RETRY = retry to flush later. // output.FLB_RETRY = retry to flush later.
return output.FLB_OK fmt.Printf(result)
xxdata := url.Values{
"name": {result},
"occupation": {"y"},
}
res, err := http.PostForm("https://softinst140097.host.vifib.net/erp5/fluentbit_upload_test/", xxdata)
fmt.Printf("%v", res)
if err == nil {
os.Exit(0)
}
return output.FLB_RETRY
} }
//export FLBPluginExit //export FLBPluginExit
......
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