|
@@ -37,7 +37,6 @@ const (
|
|
SENDSUCCESS
|
|
SENDSUCCESS
|
|
|
|
|
|
DEFAULTSMSTPL = `
|
|
DEFAULTSMSTPL = `
|
|
-【江苏省电力公司】
|
|
|
|
所属系统:{{app_name}}
|
|
所属系统:{{app_name}}
|
|
事件名称:{{events_name}}
|
|
事件名称:{{events_name}}
|
|
事件创建时间:{{date_time}}
|
|
事件创建时间:{{date_time}}
|
|
@@ -132,7 +131,7 @@ func GetPrometheusInstance() string {
|
|
return extConfig.ExtConfig.Prometheus.Address
|
|
return extConfig.ExtConfig.Prometheus.Address
|
|
}
|
|
}
|
|
|
|
|
|
-func GetSmsConfigInstance() *SmsConfig {
|
|
|
|
|
|
+func GetSmsConfigInstance(db *gorm.DB) *SmsConfig {
|
|
sc := new(SmsConfig)
|
|
sc := new(SmsConfig)
|
|
sc.Appkey = extConfig.ExtConfig.SmsConfig.Appkey
|
|
sc.Appkey = extConfig.ExtConfig.SmsConfig.Appkey
|
|
sc.Appsecret = extConfig.ExtConfig.SmsConfig.Appsecret
|
|
sc.Appsecret = extConfig.ExtConfig.SmsConfig.Appsecret
|
|
@@ -140,20 +139,34 @@ func GetSmsConfigInstance() *SmsConfig {
|
|
// TODO: set default sms template,需要修改为外部模版
|
|
// TODO: set default sms template,需要修改为外部模版
|
|
sc.SmsTpl = DEFAULTSMSTPL
|
|
sc.SmsTpl = DEFAULTSMSTPL
|
|
sc.Url = extConfig.ExtConfig.SmsConfig.Url
|
|
sc.Url = extConfig.ExtConfig.SmsConfig.Url
|
|
- // sc.SQLRecord = extConfig.ExtConfig.SmsConfig.SQLRecord
|
|
|
|
|
|
+ sc.SQLRecord = extConfig.ExtConfig.SmsConfig.SqlRecord
|
|
|
|
+
|
|
|
|
+ //判断使用配置文件默认联系人还是应用管理的联系人,通常快速测试时使用配置文件,此时sqlrecord为false
|
|
recordMap := make(map[string][]string)
|
|
recordMap := make(map[string][]string)
|
|
- parts := strings.Split(extConfig.ExtConfig.SmsConfig.AppsGroup, ";")
|
|
|
|
- for _, part := range parts {
|
|
|
|
- if part == "" {
|
|
|
|
- continue
|
|
|
|
|
|
+ if sc.SQLRecord {
|
|
|
|
+ apps := make([]amodels.OtApps, 0)
|
|
|
|
+ if err := db.Find(&apps).Error; err != nil {
|
|
|
|
+ logger.Error("sms, get app list err: ", err)
|
|
|
|
+ return nil
|
|
|
|
+ }
|
|
|
|
+ for _, app := range apps {
|
|
|
|
+ recordMap[app.Alias] = strings.Split(app.ContractPhone, ",")
|
|
}
|
|
}
|
|
- subParts := strings.SplitN(part, ":", 2)
|
|
|
|
- if len(subParts) != 2 {
|
|
|
|
- continue
|
|
|
|
|
|
+ } else {
|
|
|
|
+ parts := strings.Split(extConfig.ExtConfig.SmsConfig.AppsGroup, ";")
|
|
|
|
+ for _, part := range parts {
|
|
|
|
+ if part == "" {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ subParts := strings.SplitN(part, ":", 2)
|
|
|
|
+ if len(subParts) != 2 {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ id := subParts[0]
|
|
|
|
+ phoneNumbers := subParts[1]
|
|
|
|
+ recordMap[id] = strings.Split(phoneNumbers, ",")
|
|
}
|
|
}
|
|
- id := subParts[0]
|
|
|
|
- phoneNumbers := subParts[1]
|
|
|
|
- recordMap[id] = strings.Split(phoneNumbers, ",")
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
sc.AppsGroup = recordMap
|
|
sc.AppsGroup = recordMap
|
|
logger.Info("sms phone map: ", sc.AppsGroup)
|
|
logger.Info("sms phone map: ", sc.AppsGroup)
|
|
@@ -278,7 +291,7 @@ func (a *AlertManager) PolicyConsumer() {
|
|
func (a *AlertManager) consumerHandler(i interface{}) {
|
|
func (a *AlertManager) consumerHandler(i interface{}) {
|
|
var err error
|
|
var err error
|
|
c := 0
|
|
c := 0
|
|
- eHandler := InitEventHandler(a.PromMap, GetSmsConfigInstance())
|
|
|
|
|
|
+ eHandler := InitEventHandler(a.PromMap, GetSmsConfigInstance(a.DB))
|
|
rp, ok := i.(omodels.OtRulesPolicy)
|
|
rp, ok := i.(omodels.OtRulesPolicy)
|
|
if ok {
|
|
if ok {
|
|
eHandler.RP = &rp
|
|
eHandler.RP = &rp
|