Skip to content

Commit c64a58d

Browse files
authored
fix: Fix the issue of not sending SMS alerts (#11599)
1 parent 57c60ab commit c64a58d

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

agent/utils/alert/alert.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func CheckSMSSendLimit(method string) bool {
208208
return false
209209
}
210210
var cfg dto.AlertSmsConfig
211-
err = json.Unmarshal([]byte(config.Config), &cfg)
211+
cfg, err = ParseAlertSmsConfig(config.Config)
212212
if err != nil {
213213
return false
214214
}
@@ -572,3 +572,27 @@ func loadOutboundIP() string {
572572
localAddr := conn.LocalAddr().(*network.UDPAddr)
573573
return localAddr.IP.String()
574574
}
575+
576+
func ParseAlertSmsConfig(configJSON string) (dto.AlertSmsConfig, error) {
577+
var tempMap map[string]interface{}
578+
err := json.Unmarshal([]byte(configJSON), &tempMap)
579+
if err != nil {
580+
return dto.AlertSmsConfig{}, err
581+
}
582+
583+
var cfg dto.AlertSmsConfig
584+
if phone, ok := tempMap["phone"].(string); ok {
585+
cfg.Phone = phone
586+
}
587+
588+
switch v := tempMap["alertDailyNum"].(type) {
589+
case float64:
590+
cfg.AlertDailyNum = strconv.FormatFloat(v, 'f', 0, 64)
591+
case string:
592+
cfg.AlertDailyNum = v
593+
default:
594+
cfg.AlertDailyNum = "50"
595+
}
596+
597+
return cfg, nil
598+
}

0 commit comments

Comments
 (0)