func CentralPostStats(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") store := context.Get(r, "store").(*storage.Storage) payloadJson, err := ioutil.ReadAll(r.Body) if err != nil { libhttp.HandleErrorJson(w, err) return } payload := make(map[string]interface{}) err = json.Unmarshal(payloadJson, &payload) if err != nil { libhttp.HandleErrorJson(w, err) return } hostname := "" hostnameInterface := payload["hostname"] if hostnameInterface != nil { hostname = hostnameInterface.(string) } store.Set("stats:"+hostname, payload) libhttp.HandleSuccessJson(w, "Stats on host: "+hostname+" is saved successfully") }
func AgentPostConfig(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") mcRouterConfigFile := context.Get(r, "mcRouterConfigFile").(string) if mcRouterConfigFile == "" { err := errors.New("McRouter config file is missing") libhttp.HandleErrorJson(w, err) return } configManager, err := models.NewMcRouterConfigManager(mcRouterConfigFile) if err != nil { libhttp.HandleErrorJson(w, err) return } mcRouterConfigJson, err := ioutil.ReadAll(r.Body) if err != nil { libhttp.HandleErrorJson(w, err) return } err = configManager.UpdateConfigJson(mcRouterConfigJson) if err != nil { libhttp.HandleErrorJson(w, err) return } libhttp.HandleSuccessJson(w, "New config is saved successfully") }
func CentralGetConfigs(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") store := context.Get(r, "store").(*storage.Storage) configs, err := store.ToJson("config:") if err != nil { libhttp.HandleErrorJson(w, err) return } w.Write(configs) }
func CentralPostConfigs(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") store := context.Get(r, "store").(*storage.Storage) payloadJson, err := ioutil.ReadAll(r.Body) if err != nil { libhttp.HandleErrorJson(w, err) return } var payload payloads.ReportConfigToCentralPayload err = json.Unmarshal(payloadJson, &payload) if err != nil { libhttp.HandleErrorJson(w, err) return } store.Set("config:"+payload.Hostname, payload.Config) libhttp.HandleSuccessJson(w, "Config on host: "+payload.Hostname+" is saved successfully") }
func AgentGetConfig(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") mcRouterConfigFile := context.Get(r, "mcRouterConfigFile").(string) if mcRouterConfigFile == "" { err := errors.New("McRouter config file is missing") libhttp.HandleErrorJson(w, err) return } configManager, err := models.NewMcRouterConfigManager(mcRouterConfigFile) if err != nil { libhttp.HandleErrorJson(w, err) return } mcRouterConfigJson, err := configManager.ConfigJson() if err != nil { libhttp.HandleErrorJson(w, err) return } w.Write(mcRouterConfigJson) }
func CentralGetConfigsHostname(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") vars := mux.Vars(r) store := context.Get(r, "store").(*storage.Storage) configs := store.All("config:" + vars["hostname"]) if len(configs) == 0 { w.Write([]byte(`{}`)) return } configJson, err := json.Marshal(configs[""]) if err != nil { libhttp.HandleErrorJson(w, err) return } w.Write(configJson) }
func AgentGetStats(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") store := context.Get(r, "store").(*storage.Storage) payloadInterface := store.Get("statsPayload") if payloadInterface == nil { w.Write([]byte(`{}`)) return } payload := payloadInterface.(map[string]interface{}) payloadJson, err := json.Marshal(payload) if err != nil { libhttp.HandleErrorJson(w, err) return } w.Write(payloadJson) }