95 lines
1.8 KiB
Go
95 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"github.com/gin-gonic/gin"
|
|
"leafdev.top/ivampiresp/msgpack-fluentbit-log-collect/config"
|
|
"log"
|
|
"time"
|
|
)
|
|
|
|
var Router *gin.Engine
|
|
|
|
type LogStruct []struct {
|
|
Date float64 `json:"date"`
|
|
Time time.Time `json:"time"`
|
|
Stream string `json:"stream"`
|
|
P string `json:"_p"`
|
|
Log string `json:"log"`
|
|
Kubernetes struct {
|
|
PodName string `json:"pod_name"`
|
|
NamespaceName string `json:"namespace_name"`
|
|
PodID string `json:"pod_id"`
|
|
Labels map[string]interface{} `json:"labels"`
|
|
Annotations map[string]interface{} `json:"annotations"`
|
|
Host string `json:"host"`
|
|
ContainerName string `json:"container_name"`
|
|
DockerID string `json:"docker_id"`
|
|
ContainerImage string `json:"container_image"`
|
|
} `json:"kubernetes"`
|
|
}
|
|
|
|
func init() {
|
|
config.InitConfig()
|
|
InitGin()
|
|
Controller()
|
|
}
|
|
|
|
func main() {
|
|
err := Router.Run(fmt.Sprintf(":%s", config.Gin.Port))
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
return
|
|
}
|
|
}
|
|
|
|
func InitGin() {
|
|
Router = gin.Default()
|
|
}
|
|
|
|
func Controller() {
|
|
Router.POST("/", func(c *gin.Context) {
|
|
if !ValidatePassword(c.GetHeader("Authorization")) {
|
|
c.JSON(401, gin.H{
|
|
"code": 401,
|
|
"message": "Unauthorized",
|
|
})
|
|
return
|
|
}
|
|
|
|
var remoteLog []LogStruct
|
|
|
|
// bind LogStruct
|
|
err := c.BindJSON(&remoteLog)
|
|
if err != nil {
|
|
c.JSON(400, gin.H{
|
|
"code": 400,
|
|
})
|
|
return
|
|
}
|
|
|
|
fmt.Println(remoteLog[0])
|
|
|
|
})
|
|
}
|
|
|
|
func ValidatePassword(pass string) bool {
|
|
return pass == "Bearer "+config.Auth.Pass
|
|
}
|
|
|
|
func Process(body []byte) error {
|
|
// time
|
|
|
|
var r map[interface{}]interface{}
|
|
|
|
if err := json.Unmarshal(body, &r); err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Println(r["kubernetes"])
|
|
|
|
return nil
|
|
|
|
}
|