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

import (
	"strconv"

黄孟柱 已提交
6
	config_log "github.com/eolinker/goku-api-gateway/console/module/config-log"
E
eoLinker API Management 已提交
7

黄孟柱 已提交
8 9 10
	log "github.com/eolinker/goku-api-gateway/goku-log"
	console_mysql "github.com/eolinker/goku-api-gateway/server/dao/console-mysql"
	"github.com/eolinker/goku-api-gateway/utils"
E
eoLinker API Management 已提交
11 12
)

Y
Your Name 已提交
13
//GetAlertMsgList 获取告警信息列表
E
eoLinker API Management 已提交
14 15 16 17
func GetAlertMsgList(page, pageSize int) (bool, []map[string]interface{}, int, error) {
	return console_mysql.GetAlertMsgList(page, pageSize)
}

Y
Your Name 已提交
18
//ClearAlertMsg 清空告警信息列表
E
eoLinker API Management 已提交
19 20 21 22
func ClearAlertMsg() (bool, string, error) {
	return console_mysql.ClearAlertMsg()
}

Y
Your Name 已提交
23
//DeleteAlertMsg 删除告警信息
E
eoLinker API Management 已提交
24 25 26 27
func DeleteAlertMsg(alertID int) (bool, string, error) {
	return console_mysql.DeleteAlertMsg(alertID)
}

Y
Your Name 已提交
28
//AddAlertMsg 新增告警信息
E
eoLinker API Management 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
func AddAlertMsg(apiID, apiName, requestURL, targetServer, targetURL, requestMethod, proxyMethod, headerList, queryParamList, formParamList, responseHeaderList, strategyID, strategyName, requestID string, alertPeriodType, alertCount, responseStatus int, isAlert bool, ip, clusterName string) (bool, string, error) {

	flag, result, err := console_mysql.GetAlertConfig()
	if !flag {
		return false, "", err
	}

	apiAlertInfo := result["apiAlertInfo"].(map[string]interface{})
	AlertLog(requestURL, targetServer, targetURL, requestMethod, proxyMethod, headerList, queryParamList, formParamList, responseHeaderList, responseStatus, ip, strategyID, strategyName, requestID)
	if isAlert {
		// 发送邮件
		log.WithFields(log.Fields(result)).Debug("AddAlertMsg: apiAlertInfo[\"receiverList\"]", apiAlertInfo["receiverList"])

		logConfig, _ := config_log.Get("console")
		go utils.SendAlertMail(result["sender"].(string), result["senderPassword"].(string), result["smtpAddress"].(string), strconv.Itoa(result["smtpPort"].(int)), strconv.Itoa(result["smtpProtocol"].(int)), apiAlertInfo["receiverList"].(string), requestURL, logConfig.Dir, strconv.Itoa(alertPeriodType), strconv.Itoa(alertCount), apiName, apiID, targetServer, targetURL)

		return console_mysql.AddAlertMsg(requestURL, targetServer, targetURL, ip, clusterName, alertPeriodType, alertCount)
	}
Y
Your Name 已提交
47
	return true, "", nil
E
eoLinker API Management 已提交
48 49
}

Y
Your Name 已提交
50
//GetAlertConfig 获取告警配置
E
eoLinker API Management 已提交
51 52 53
func GetAlertConfig() (bool, map[string]interface{}, error) {
	return console_mysql.GetAlertConfig()
}