Пример #1
0
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")
}
Пример #2
0
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")
}
Пример #3
0
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)
}
Пример #4
0
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")
}
Пример #5
0
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)
}
Пример #6
0
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)
}
Пример #7
0
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)
}