MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / CheckSendTimeRange

Function CheckSendTimeRange

agent/utils/alert/alert.go:279–305  ·  view source on GitHub ↗
(alertType string)

Source from the content-addressed store, hash-verified

277}
278
279func 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
307func contains(arr []string, target string) bool {
308 for _, item := range arr {

Callers

nothing calls this directly

Calls 4

GetConfigMethod · 0.95
WithByTypeMethod · 0.95
isWithinTimeRangeFunction · 0.85
containsFunction · 0.70

Tested by

no test coverage detected