alert.go 2.7 KB
Newer Older
E
eoLinker API Management 已提交
1 2 3 4 5 6
package alert

import (
	"net/http"
	"strconv"

黄孟柱 已提交
7
	log "github.com/eolinker/goku-api-gateway/goku-log"
E
eoLinker API Management 已提交
8

黄孟柱 已提交
9 10
	"github.com/eolinker/goku-api-gateway/console/controller"
	alert_module "github.com/eolinker/goku-api-gateway/console/module/alert"
E
eoLinker API Management 已提交
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
)

// GetAlertMsgList 获取告警信息列表
func GetAlertMsgList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
	_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAlert, controller.OperationREAD)
	if e != nil {
		return
	}

	page := httpRequest.PostFormValue("page")
	pageSize := httpRequest.PostFormValue("pageSize")

	p, err := strconv.Atoi(page)
	if err != nil {
		p = 1
	}
	pSize, err := strconv.Atoi(pageSize)
	if err != nil {
		pSize = 15
	}
	_, result, count, err := alert_module.GetAlertMsgList(p, pSize)

	controller.WriteResultInfoWithPage(httpResponse, "alert", "alertMessageList", result, &controller.PageInfo{
		ItemNum:  len(result),
		TotalNum: count,
		Page:     p,
		PageSize: pSize,
	})
	return
}

Y
Your Name 已提交
42
//ClearAlertMsg 清空告警信息列表
E
eoLinker API Management 已提交
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
func ClearAlertMsg(httpResponse http.ResponseWriter, httpRequest *http.Request) {
	_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAlert, controller.OperationEDIT)
	if e != nil {
		return
	}

	flag, result, err := alert_module.ClearAlertMsg()
	if !flag {

		controller.WriteError(httpResponse,
			"330000",
			"alert",
			result,
			err)
		return
	}

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

Y
Your Name 已提交
64
//DeleteAlertMsg 删除告警信息
E
eoLinker API Management 已提交
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
func DeleteAlertMsg(httpResponse http.ResponseWriter, httpRequest *http.Request) {
	_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAlert, controller.OperationEDIT)
	if e != nil {
		return
	}

	alertID := httpRequest.PostFormValue("alertID")

	id, err := strconv.Atoi(alertID)
	if err != nil {

		log.Debug(err)

		controller.WriteError(httpResponse,
			"330001",
			"alert",
			"[ERROR]Illegal alertID!",
			err)
		return
	}
	flag, result, err := alert_module.DeleteAlertMsg(id)
	if !flag {

		controller.WriteError(httpResponse,
			"330000",
			"alert",
			result,
			err)
		return
	}

	controller.WriteResultInfo(httpResponse, "alert", "", nil)

	return
}

Y
Your Name 已提交
101
//GetAlertConfig 获取告警配置
E
eoLinker API Management 已提交
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
func GetAlertConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
	_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAlert, controller.OperationREAD)
	if e != nil {
		return
	}

	flag, result, err := alert_module.GetAlertConfig()
	if !flag {

		controller.WriteError(httpResponse,
			"320000",
			"gateway",
			"[ERROR]The gateway config does not exist",
			err)
		return
	}

	controller.WriteResultInfo(httpResponse, "alert", "gatewayConfig", result)
	return

}