Commit efc517f7 authored by Eteri's avatar Eteri

fluentbit: add confing file. Fix errors

parent 2ff1f2ca
[INPUT]
Name dummy
Tag dummy
[OUTPUT]
Name wendelin_out
Match *
User <your_wendelin_user>
Password <your_wendelin_password>
Uri <Wendelin_URL>/erp5/portal_ingestion_policies/<YOUR_INGESTION_POLICY_ID>
Reference <input_stream_reference>
...@@ -6,7 +6,10 @@ import ( ...@@ -6,7 +6,10 @@ import (
"unsafe" "unsafe"
"C" "C"
"net/http" "net/http"
"strconv"
"bytes" "bytes"
"regexp"
) )
// configuration parameters // configuration parameters
...@@ -20,19 +23,18 @@ func FLBPluginRegister(ctx unsafe.Pointer) int { ...@@ -20,19 +23,18 @@ func FLBPluginRegister(ctx unsafe.Pointer) int {
return output.FLBPluginRegister(ctx, "wendelin_out", "Wendelin Out GO!") return output.FLBPluginRegister(ctx, "wendelin_out", "Wendelin Out GO!")
} }
/* //export FLBPluginInit
* export FLBPluginInit // (fluentbit will call this)
* fluentbit will call this // ctx (context) pointer to fluentbit context (state/ c code)
* ctx (context) pointer to fluentbit context (state/ c code)
*/
func FLBPluginInit(ctx unsafe.Pointer) int { func FLBPluginInit(ctx unsafe.Pointer) int {
// Retrieve the configuration parameters // Example to retrieve an optional configuration parameter
// param := output.FLBPluginConfigKey(ctx, "param")
user = output.FLBPluginConfigKey(ctx, "User") user = output.FLBPluginConfigKey(ctx, "User")
password = output.FLBPluginConfigKey(ctx, "Password") password = output.FLBPluginConfigKey(ctx, "Password")
uri = output.FLBPluginConfigKey(ctx, "Uri") uri = output.FLBPluginConfigKey(ctx, "Uri")
reference = output.FLBPluginConfigKey(ctx, "Reference") reference = output.FLBPluginConfigKey(ctx, "Reference")
//fmt.Printf("[flb-go] plugin parameter = '%s'\n", param)
fmt.Printf("[flb-go user] plugin parameter = '%s'\n", user) fmt.Printf("[flb-go user] plugin parameter = '%s'\n", user)
fmt.Printf("[flb-go password] plugin parameter = '%s'\n", password) fmt.Printf("[flb-go password] plugin parameter = '%s'\n", password)
fmt.Printf("[flb-go uri] plugin parameter = '%s'\n", uri) fmt.Printf("[flb-go uri] plugin parameter = '%s'\n", uri)
...@@ -44,18 +46,18 @@ func FLBPluginInit(ctx unsafe.Pointer) int { ...@@ -44,18 +46,18 @@ func FLBPluginInit(ctx unsafe.Pointer) int {
//export FLBPluginFlush //export FLBPluginFlush
func FLBPluginFlush(data unsafe.Pointer, length C.int, tag *C.char) int { func FLBPluginFlush(data unsafe.Pointer, length C.int, tag *C.char) int {
request_string := uri + "/ingest?reference=" + reference request_string := uri + "/ingest?reference=" + reference
var b []byte
var byte_data []byte b = C.GoBytes(data, C.int(length))
byte_data = C.GoBytes(data, C.int(length))
hc := http.Client{} hc := http.Client{}
req, err := http.NewRequest("POST", request_string, bytes.NewBuffer(byte_data)) req, err := http.NewRequest("POST", request_string, bytes.NewBuffer(b))
if err != nil { if err != nil {
return output.FLB_ERROR return output.FLB_ERROR
} }
req.Header.Set("Content-Type", "application/octet-stream") req.Header.Set("Content-Type", "application/octet-stream")
req.SetBasicAuth(user, password) req.SetBasicAuth(user, password)
...@@ -75,12 +77,21 @@ func FLBPluginFlush(data unsafe.Pointer, length C.int, tag *C.char) int { ...@@ -75,12 +77,21 @@ func FLBPluginFlush(data unsafe.Pointer, length C.int, tag *C.char) int {
* - 204: No Content * - 204: No Content
* - 205: Reset content * - 205: Reset content
*/ */
if resp.Status < 200 && resp.Status > 205 { re := regexp.MustCompile("[0-9]+") // get only the status code
status_code := re.FindAllString(resp.Status, -1)
resp_status, err := strconv.Atoi(status_code[0])
if err != nil {
fmt.Println(err)
return output.FLB_RETRY return output.FLB_RETRY
} }
fmt.Println(resp.Status) fmt.Println(resp.Status)
fmt.Println(err) fmt.Println(err)
if resp_status < 200 && resp_status > 205 {
return output.FLB_RETRY
}
defer resp.Body.Close() defer resp.Body.Close()
/* /*
......
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