diff --git a/agent/utils/alert/alert.go b/agent/utils/alert/alert.go index 22847324f27a..08e2ccd7091e 100644 --- a/agent/utils/alert/alert.go +++ b/agent/utils/alert/alert.go @@ -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 } @@ -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 +}