|
|
|
@@ -585,3 +585,42 @@ func AlertCurEventGetsFromAlertMute(ctx *ctx.Context, alertMute *AlertMute) ([]* |
|
|
|
err := tx.Order("id desc").Find(&lst).Error |
|
|
|
return lst, err |
|
|
|
} |
|
|
|
|
|
|
|
func AlertCurEventStatistics(ctx *ctx.Context, stime time.Time) (res map[string]interface{}) { |
|
|
|
stime24HoursAgoUnix := stime.Add(-24 * time.Hour).Unix() |
|
|
|
//Beginning of today |
|
|
|
stimeMidnightUnix := time.Date(stime.Year(), stime.Month(), stime.Day(), 0, 0, 0, 0, stime.Location()).Unix() |
|
|
|
///Monday of the current week, starting at 00:00 |
|
|
|
daysToMonday := (int(stime.Weekday()) - 1 + 7) % 7 // (DayOfTheWeek - Monday(1) + DaysAWeek(7))/DaysAWeek(7) |
|
|
|
stimeOneWeekAgoUnix := time.Date(stime.Year(), stime.Month(), stime.Day()-daysToMonday, 0, 0, 0, 0, stime.Location()).Unix() |
|
|
|
|
|
|
|
var countNum int64 |
|
|
|
err := DB(ctx).Model(&AlertCurEvent{}).Count(&countNum).Error |
|
|
|
if err != nil { |
|
|
|
logger.Debugf("count alert current rule failed(total), %v", err) |
|
|
|
} |
|
|
|
res["total"] = countNum |
|
|
|
|
|
|
|
countNum = 0 |
|
|
|
err = DB(ctx).Model(&AlertCurEvent{}).Where("trigger_time < ?", stime24HoursAgoUnix).Count(&countNum).Error |
|
|
|
if err != nil { |
|
|
|
logger.Debugf("count alert current rule failed(total_24ago), %v", err) |
|
|
|
} |
|
|
|
res["total_24_ago"] = countNum |
|
|
|
|
|
|
|
countNum = 0 |
|
|
|
err = DB(ctx).Model(&AlertHisEvent{}).Where("trigger_time >= ? and is_recovered = ? ", stimeMidnightUnix, 0).Count(&countNum).Error |
|
|
|
if err != nil { |
|
|
|
logger.Debugf("count alert his rule failed(total_today), %v", err) |
|
|
|
} |
|
|
|
res["total_today"] = countNum |
|
|
|
|
|
|
|
countNum = 0 |
|
|
|
err = DB(ctx).Model(&AlertHisEvent{}).Where("trigger_time >= ? and is_recovered = ? ", stimeOneWeekAgoUnix, 0).Count(&countNum).Error |
|
|
|
if err != nil { |
|
|
|
logger.Debugf("count alert his rule failed(total_today), %v", err) |
|
|
|
} |
|
|
|
res["total_week"] = countNum |
|
|
|
|
|
|
|
return res |
|
|
|
} |