Commit edfcd6d0 authored by Xiaowu Zhang's avatar Xiaowu Zhang

http post

parent 81da849f
......@@ -7,7 +7,7 @@
[output]
name wendelin_fluentbit
match *
streamtool_uri https://softinst143538.host.vifib.net
streamtool_uri https://softinst140097.host.vifib.net/erp5
user xx
password xx
buffer_type memory
......
package main
import (
"bytes"
"C"
"fmt"
"time"
"os"
"unsafe"
"net/http"
"net/url"
"github.com/fluent/fluent-bit-go/output"
)
......@@ -84,17 +84,26 @@ func FLBPluginFlushCtx(ctx, data unsafe.Pointer, length C.int, tag *C.char) int
// output.FLB_OK = data have been processed.
// output.FLB_ERROR = unrecoverable error, do not try this again.
// output.FLB_RETRY = retry to flush later.
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)
//body result
// content type "application/octet-stream"
//
var b = []byte(result)
uri := fmt.Sprintf("%s/ingest?reference=#%s", dict["streamtool_uri"], C.GoString(tag))
client := &http.Client{}
req, err := http.NewRequest("POST", uri, bytes.NewReader(b))
if err != nil {
fmt.Printf("Got error %s", err.Error())
return output.FLB_RETRY
}
req.SetBasicAuth(dict["user"], dict["password"])
req.Header.Set("Content-Type", "application/octet-stream")
rsp, _ := client.Do(req)
if rsp.StatusCode != http.StatusOK {
fmt.Printf("status code %d", rsp.StatusCode)
return output.FLB_RETRY
}
os.Exit(0)
return output.FLB_OK
}
//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