diff --git a/console.yml b/console.yml index 590a4206..8c0cff79 100644 --- a/console.yml +++ b/console.yml @@ -1,6 +1,11 @@ path.configs: "config" configs.auto_reload: true +#env: +# INFINI_CONSOLE_ENDPOINT: "http://192.168.3.9:9000" +# INGEST_CLUSTER_ENDPOINT: "http://192.168.3.9:9210" +# INGEST_CLUSTER_CREDENTIAL_ID: chjkp9dath21f1ae9tq0 + web: enabled: true embedding_api: true @@ -64,4 +69,14 @@ badger: # authorize_url: "https://github.com/login/oauth/authorize" # token_url: "https://github.com/login/oauth/access_token" # redirect_url: "" -# scopes: [] \ No newline at end of file +# scopes: [] + +#agent: +# setup: +# download_url: "https://release.infinilabs.com/agent/snapshot" +# version: 0.5.0_NIGHTLY-157 +# ca_cert: "/opt/config/certs/ca.crt" +# ca_key: "/opt/config/certs/ca.key" +# console_endpoint: $[[env.INFINI_CONSOLE_ENDPOINT]] +# ingest_cluster_endpoint: $[[env.INGEST_CLUSTER_ENDPOINT]] +# ingest_cluster_credential_id: $[[env.INGEST_CLUSTER_CREDENTIAL_ID]] \ No newline at end of file diff --git a/modules/agent/api/init.go b/modules/agent/api/init.go index 7a5048fd..63f6d27e 100644 --- a/modules/agent/api/init.go +++ b/modules/agent/api/init.go @@ -14,6 +14,7 @@ func Init() { api.HandleAPIMethod(api.POST, "/agent/instance", handler.createInstance) api.HandleAPIMethod(api.GET, "/agent/instance/_search", handler.RequirePermission(handler.searchInstance, enum.PermissionAgentInstanceRead)) api.HandleAPIMethod(api.GET, "/agent/instance/:instance_id", handler.getInstance) + api.HandleAPIMethod(api.PUT, "/agent/instance/:instance_id", handler.updateInstance) api.HandleAPIMethod(api.DELETE, "/agent/instance/:instance_id", handler.RequirePermission(handler.deleteInstance, enum.PermissionAgentInstanceWrite)) api.HandleAPIMethod(api.POST, "/agent/instance/_stats", handler.RequirePermission(handler.getInstanceStats, enum.PermissionAgentInstanceRead)) api.HandleAPIMethod(api.GET, "/agent/log/node/:node_id/files", handler.RequirePermission(handler.getLogFilesByNode, enum.PermissionAgentInstanceRead)) diff --git a/modules/agent/api/instance.go b/modules/agent/api/instance.go index 49ae9922..f6eff3e7 100644 --- a/modules/agent/api/instance.go +++ b/modules/agent/api/instance.go @@ -312,6 +312,52 @@ func (h *APIHandler) getInstanceStats(w http.ResponseWriter, req *http.Request, h.WriteJSON(w, result, http.StatusOK) } +func (h *APIHandler) updateInstance(w http.ResponseWriter, req *http.Request, ps httprouter.Params) { + id := ps.MustGetParameter("instance_id") + oldInst := agent.Instance{} + oldInst.ID = id + _, err := orm.Get(&oldInst) + if err != nil { + if err == elastic2.ErrNotFound { + h.WriteJSON(w, util.MapStr{ + "_id": id, + "result": "not_found", + }, http.StatusNotFound) + return + } + h.WriteError(w, err.Error(), http.StatusInternalServerError) + log.Error(err) + return + } + + obj := agent.Instance{} + err = h.DecodeJSON(req, &obj) + if err != nil { + h.WriteError(w, err.Error(), http.StatusInternalServerError) + log.Error(err) + return + } + + oldInst.Name = obj.Name + oldInst.Endpoint = obj.Endpoint + oldInst.Description = obj.Description + oldInst.Tags = obj.Tags + oldInst.BasicAuth = obj.BasicAuth + err = orm.Update(&orm.Context{ + Refresh: "wait_for", + }, &oldInst) + if err != nil { + h.WriteError(w, err.Error(), http.StatusInternalServerError) + log.Error(err) + return + } + + h.WriteJSON(w, util.MapStr{ + "_id": obj.ID, + "result": "updated", + }, 200) +} + func (h *APIHandler) searchInstance(w http.ResponseWriter, req *http.Request, ps httprouter.Params) { diff --git a/modules/agent/common/helper.go b/modules/agent/common/helper.go index 43694888..4c4b8d8a 100644 --- a/modules/agent/common/helper.go +++ b/modules/agent/common/helper.go @@ -37,6 +37,7 @@ func ParseAgentSettings(settings []agent.Setting)(*model.ParseAgentSettingsResul Enabled: true, Name: cfg.Name, BasicAuth: cfg.BasicAuth, + //todo get endpoint from agent node info Endpoint: setting.Metadata.Labels["endpoint"].(string), } newCfg.ID = clusterID