/
task.go
43 lines (38 loc) · 1.05 KB
/
task.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package client
import (
"encoding/json"
"fmt"
"github.com/bytedance/Elkeid/server/agent_center/common"
"github.com/bytedance/Elkeid/server/agent_center/common/ylog"
"github.com/levigross/grequests"
"time"
)
const TaskUrl = `http://%s/api/v1/agent/updateSubTask`
type ResTaskConf struct {
Code int `json:"code"`
Message string `json:"msg"`
}
func PostTask(postList []map[string]string) {
resp, err := grequests.Post(fmt.Sprintf(TaskUrl, common.GetRandomManageAddr()), &grequests.RequestOptions{
JSON: postList,
RequestTimeout: 2 * time.Second,
})
if err != nil {
ylog.Errorf("PostTask", "error: %s, %#v", err.Error(), postList)
return
}
if !resp.Ok {
ylog.Errorf("PostTask", "response code is %d, %#v", resp.StatusCode, postList)
return
}
var response ResTaskConf
err = json.Unmarshal(resp.Bytes(), &response)
if err != nil {
ylog.Errorf("PostTask", "error: %s, %s", err.Error(), resp.String())
return
}
if response.Code != 0 {
ylog.Errorf("GetConfigFromRemote", "response code is not 0, %s", resp.String())
return
}
}