fix wrong agent status of host

This commit is contained in:
liugq 2023-05-23 16:35:44 +08:00
parent 4b9fddcf8d
commit 605c89222e
5 changed files with 2 additions and 41 deletions

View File

@ -82,17 +82,6 @@ func (h *APIHandler) enrollHost(w http.ResponseWriter, req *http.Request, ps htt
log.Error(err)
continue
}
if hi.Source == "agent" {
sm := common2.GetStateManager()
ag, _ := sm.GetAgent(hostInfo.AgentID)
err = sm.GetAgentClient().DiscoveredHost(nil, ag.GetEndpoint(), util.MapStr{
"host_id": hostInfo.ID,
})
if err != nil {
log.Error(err)
}
}
}
resBody := util.MapStr{
"success": true,

View File

@ -73,6 +73,7 @@ func (h *APIHandler) createInstance(w http.ResponseWriter, req *http.Request, ps
obj.IPS = res.IPS
}
obj.Status = common2.StatusOnline
err = orm.Create(nil, obj)
if err != nil {
h.WriteError(w, err.Error(), http.StatusInternalServerError)
@ -116,13 +117,6 @@ func bindAgentToHostByIP(ag *agent.Instance) error{
if err != nil {
return err
}
err = sm.GetAgentClient().DiscoveredHost(nil, ag.GetEndpoint(), util.MapStr{
"host_id": hostInfo.ID,
})
if err != nil {
return err
}
}
return nil
}

View File

@ -38,28 +38,6 @@ func (client *Client) GetHostInfo(ctx context.Context, agentBaseURL string) (*ho
return resBody.HostInfo, nil
}
func (client *Client) DiscoveredHost(ctx context.Context, agentBaseURL string, body interface{}) error {
req := &util.Request{
Method: http.MethodPut,
Url: fmt.Sprintf("%s/host/discover", agentBaseURL),
Context: ctx,
}
reqBody, err := util.ToJSONBytes(body)
if err != nil {
return err
}
req.Body = reqBody
resBody := map[string]interface{}{}
err = client.doRequest(req, &resBody)
if err != nil {
return err
}
if resBody["success"] != true {
return fmt.Errorf("discover host callback error: %v", resBody["error"])
}
return nil
}
func (client *Client) GetElasticProcess(ctx context.Context, agentBaseURL string, agentID string)(interface{}, error) {
req := &util.Request{
Method: http.MethodGet,

View File

@ -25,7 +25,6 @@ func RegisterClient(client ClientAPI) {
}
type ClientAPI interface {
GetHostInfo(ctx context.Context, agentBaseURL string) (*host.HostInfo, error)
DiscoveredHost(ctx context.Context, agentBaseURL string, body interface{}) error
GetElasticProcess(ctx context.Context, agentBaseURL string, agentID string)(interface{}, error)
GetElasticLogFiles(ctx context.Context, agentBaseURL string, logsPath string)(interface{}, error)
GetElasticLogFileContent(ctx context.Context, agentBaseURL string, body interface{})(interface{}, error)

View File

@ -70,6 +70,7 @@ func (sm *StateManager) checkAgentStatus() {
for agentID, status := range sm.agentIds {
if _, ok := onlineAgentIDs[agentID]; ok {
sm.syncSettings(agentID)
host.UpdateHostAgentStatus(agentID, StatusOnline)
if status == StatusOnline {
continue
}