Example #1
0
func combineQQ() {
	dtos := popAllQQDto()
	count := len(dtos)
	if count == 0 {
		return
	}

	dtoMap := make(map[string][]*QQDto)
	for i := 0; i < count; i++ {
		key := fmt.Sprintf("%d%s%s%s", dtos[i].Priority, dtos[i].Status, dtos[i].Email, dtos[i].Metric)
		if _, ok := dtoMap[key]; ok {
			dtoMap[key] = append(dtoMap[key], dtos[i])
		} else {
			dtoMap[key] = []*QQDto{dtos[i]}
		}
	}

	// 不要在这处理,继续写回redis,否则重启alarm很容易丢数据
	for _, arr := range dtoMap {
		size := len(arr)
		if size == 1 {
			redi.WriteQQ([]string{arr[0].Email}, arr[0].Subject, arr[0].Content)
			continue
		}
		subject := fmt.Sprintf("[P%d][%s] %d %s", arr[0].Priority, arr[0].Status, size, arr[0].Metric)
		contentArr := make([]string, size)
		for i := 0; i < size; i++ {
			contentArr[i] = arr[i].Content
		}
		content := strings.Join(contentArr, "\r\n")
		redi.WriteQQ([]string{arr[0].Email}, subject, content)
	}
}
Example #2
0
// 高优先级的不做报警合并
func consumeHighEvents(event *model.Event, action *api.Action) {
	if action.Uic == "" {
		return
	}

	phones, mails := api.ParseTeams(action.Uic)

	smsContent := GenerateSmsContent(event)
	mailContent := GenerateMailContent(event)
	QQContent := GenerateQQContent(event)

	if event.Priority() < 3 {
		redis.WriteSms(phones, smsContent)
	}

	redis.WriteMail(mails, smsContent, mailContent)
	redis.WriteQQ(mails, smsContent, QQContent)
	ParseUserServerchan(event, action)
}