fix host list
This commit is contained in:
parent
2bcde3c422
commit
0cb91e7c78
|
@ -34,7 +34,7 @@ func (h *APIHandler) enrollHost(w http.ResponseWriter, req *http.Request, ps htt
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
errors := util.MapStr{}
|
errors := util.MapStr{}
|
||||||
for _, hi := range reqBody {
|
for i, hi := range reqBody {
|
||||||
var (
|
var (
|
||||||
hostInfo *host.HostInfo
|
hostInfo *host.HostInfo
|
||||||
)
|
)
|
||||||
|
@ -74,7 +74,13 @@ func (h *APIHandler) enrollHost(w http.ResponseWriter, req *http.Request, ps htt
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
hostInfo.Timestamp = time.Now()
|
hostInfo.Timestamp = time.Now()
|
||||||
err = orm.Create(nil, hostInfo)
|
var ctx *orm.Context
|
||||||
|
if i == len(reqBody) - 1 {
|
||||||
|
ctx = &orm.Context{
|
||||||
|
Refresh: "wait_for",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err = orm.Create(ctx, hostInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errors[hi.IP] = util.MapStr{
|
errors[hi.IP] = util.MapStr{
|
||||||
"error": err.Error(),
|
"error": err.Error(),
|
||||||
|
@ -94,6 +100,26 @@ func (h *APIHandler) enrollHost(w http.ResponseWriter, req *http.Request, ps htt
|
||||||
h.WriteJSON(w, resBody, http.StatusOK)
|
h.WriteJSON(w, resBody, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *APIHandler) deleteHost(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
|
hostID := ps.MustGetParameter("host_id")
|
||||||
|
hostInfo, err := getHost(hostID)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx := orm.Context{
|
||||||
|
Refresh: "wait_for",
|
||||||
|
}
|
||||||
|
err = orm.Delete(&ctx, hostInfo)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
h.WriteDeletedOKJSON(w, hostID)
|
||||||
|
}
|
||||||
|
|
||||||
func (h *APIHandler) GetHostAgentInfo(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *APIHandler) GetHostAgentInfo(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
hostID := ps.MustGetParameter("host_id")
|
hostID := ps.MustGetParameter("host_id")
|
||||||
hostInfo, err := getHost(hostID)
|
hostInfo, err := getHost(hostID)
|
||||||
|
@ -123,7 +149,7 @@ func (h *APIHandler) GetHostAgentInfo(w http.ResponseWriter, req *http.Request,
|
||||||
"host_id": hostID,
|
"host_id": hostID,
|
||||||
"agent_id": ag.ID,
|
"agent_id": ag.ID,
|
||||||
"version": ag.Version,
|
"version": ag.Version,
|
||||||
"status": ag.Status,
|
"status": hostInfo.AgentStatus,
|
||||||
"endpoint": ag.GetEndpoint(),
|
"endpoint": ag.GetEndpoint(),
|
||||||
}, http.StatusOK)
|
}, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ func Init() {
|
||||||
api.HandleAPIMethod(api.POST, "/host/_enroll", handler.enrollHost)
|
api.HandleAPIMethod(api.POST, "/host/_enroll", handler.enrollHost)
|
||||||
api.HandleAPIMethod(api.GET, "/host/:host_id/agent/info",handler.GetHostAgentInfo)
|
api.HandleAPIMethod(api.GET, "/host/:host_id/agent/info",handler.GetHostAgentInfo)
|
||||||
api.HandleAPIMethod(api.GET, "/host/:host_id/processes",handler.GetHostElasticProcess)
|
api.HandleAPIMethod(api.GET, "/host/:host_id/processes",handler.GetHostElasticProcess)
|
||||||
|
api.HandleAPIMethod(api.DELETE, "/host/:host_id",handler.deleteHost)
|
||||||
|
|
||||||
|
|
||||||
api.HandleAPIMethod(api.POST, "/agent/install_command", handler.RequireLogin(handler.generateInstallCommand))
|
api.HandleAPIMethod(api.POST, "/agent/install_command", handler.RequireLogin(handler.generateInstallCommand))
|
||||||
|
|
Loading…
Reference in New Issue