Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion agent/utils/alert/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func CheckSMSSendLimit(method string) bool {
return false
}
var cfg dto.AlertSmsConfig
err = json.Unmarshal([]byte(config.Config), &cfg)
cfg, err = ParseAlertSmsConfig(config.Config)
if err != nil {
return false
}
Expand Down Expand Up @@ -572,3 +572,27 @@ func loadOutboundIP() string {
localAddr := conn.LocalAddr().(*network.UDPAddr)
return localAddr.IP.String()
}

func ParseAlertSmsConfig(configJSON string) (dto.AlertSmsConfig, error) {
var tempMap map[string]interface{}
err := json.Unmarshal([]byte(configJSON), &tempMap)
if err != nil {
return dto.AlertSmsConfig{}, err
}

var cfg dto.AlertSmsConfig
if phone, ok := tempMap["phone"].(string); ok {
cfg.Phone = phone
}

switch v := tempMap["alertDailyNum"].(type) {
case float64:
cfg.AlertDailyNum = strconv.FormatFloat(v, 'f', 0, 64)
case string:
cfg.AlertDailyNum = v
default:
cfg.AlertDailyNum = "50"
}

return cfg, nil
}
Loading