(alertType string)
| 277 | } |
| 278 | |
| 279 | func CheckSendTimeRange(alertType string) bool { |
| 280 | alertRepo := repo.NewIAlertRepo() |
| 281 | config, err := alertRepo.GetConfig(alertRepo.WithByType(constant.CommonConfig)) |
| 282 | if err != nil { |
| 283 | return false |
| 284 | } |
| 285 | var cfg dto.AlertCommonConfig |
| 286 | err = json.Unmarshal([]byte(config.Config), &cfg) |
| 287 | if err != nil { |
| 288 | return false |
| 289 | } |
| 290 | |
| 291 | var timeRange string |
| 292 | if contains(cfg.AlertSendTimeRange.NoticeAlert.Type, alertType) { |
| 293 | timeRange = cfg.AlertSendTimeRange.NoticeAlert.SendTimeRange |
| 294 | } else if contains(cfg.AlertSendTimeRange.ResourceAlert.Type, alertType) { |
| 295 | timeRange = cfg.AlertSendTimeRange.ResourceAlert.SendTimeRange |
| 296 | } else { |
| 297 | global.LOG.Warnf("Alert type not found in sendTimeRange: %s", alertType) |
| 298 | return false |
| 299 | } |
| 300 | |
| 301 | if !isWithinTimeRange(timeRange) { |
| 302 | return false |
| 303 | } |
| 304 | return true |
| 305 | } |
| 306 | |
| 307 | func contains(arr []string, target string) bool { |
| 308 | for _, item := range arr { |
nothing calls this directly
no test coverage detected