module.go 1.6 KB
Newer Older
Y
Your Name 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
package monitor

import (
	"net/http"
	"strconv"

	"github.com/pkg/errors"

	"github.com/eolinker/goku-api-gateway/console/controller"
	"github.com/eolinker/goku-api-gateway/console/module/monitor"
)

//GetMonitorModules 获取监控模块列表
func GetMonitorModules(httpResponse http.ResponseWriter, httpRequest *http.Request) {
	_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
	if e != nil {
		return
	}

	result, err := monitor.GetMonitorModules()
	if err != nil {
		controller.WriteError(httpResponse,
			"410000",
			"monitor",
			err.Error(),
			err)
		return

	}

	controller.WriteResultInfo(httpResponse, "monitorModule", "moduleList", result)
	return
}

func SetMonitorModule(httpResponse http.ResponseWriter, httpRequest *http.Request) {
	_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
	if e != nil {
		return
	}
	httpRequest.ParseForm()
	moduleName := httpRequest.Form.Get("moduleName")
	moduleStatus := httpRequest.Form.Get("moduleStatus")
	config := httpRequest.Form.Get("config")

	status, err := strconv.Atoi(moduleStatus)
	if err != nil && moduleStatus != "" {
		errInfo := "[error]illegal moduleStatus"
		controller.WriteError(httpResponse,
			"410001",
			"monitor",
			errInfo,
			errors.New(errInfo))
		return
	}

	err = monitor.SetMonitorModule(moduleName, config, status)
	if err != nil {
		controller.WriteError(httpResponse,
			"410000",
			"monitor",
			err.Error(),
			err)
		return
	}

	controller.WriteResultInfo(httpResponse, "monitorModule", "", nil)
	return
}