effective.go 766 字节
Newer Older
U
UlricQin 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
package engine

import (
	"strconv"
	"strings"
	"time"

	"github.com/didi/nightingale/v5/src/models"
)

func isNoneffective(timestamp int64, alertRule *models.AlertRule) bool {
	if alertRule.Disabled == 1 {
		return true
	}

	tm := time.Unix(timestamp, 0)
	triggerTime := tm.Format("15:04")
	triggerWeek := strconv.Itoa(int(tm.Weekday()))

	if alertRule.EnableStime <= alertRule.EnableEtime {
		if triggerTime < alertRule.EnableStime || triggerTime > alertRule.EnableEtime {
			return true
		}
	} else {
		if triggerTime < alertRule.EnableStime && triggerTime > alertRule.EnableEtime {
			return true
		}
	}

	alertRule.EnableDaysOfWeek = strings.Replace(alertRule.EnableDaysOfWeek, "7", "0", 1)

X
xtan 已提交
32
	return !strings.Contains(alertRule.EnableDaysOfWeek, triggerWeek)
U
UlricQin 已提交
33
}