Change alerts order
This commit is contained in:
parent
e09546f3e1
commit
63351eb754
2 changed files with 25 additions and 11 deletions
19
alerts.go
19
alerts.go
|
|
@ -359,6 +359,11 @@ func generateAndSendAlerts(clients map[string]ClientData, tmpl AlertRulesTemplat
|
|||
}
|
||||
}
|
||||
|
||||
// Статические алерты — отправляются первыми (появляются в начале списка)
|
||||
if err := sendStaticAlerts(tmpl, config, dryRun); err != nil {
|
||||
log.Printf("Warning: static alerts error: %v", err)
|
||||
}
|
||||
|
||||
log.Printf("Alerts: sending %d dynamic rules (concurrency: 5)", len(tasks))
|
||||
sent, failed := parallelUpsert(tasks, config, dryRun, 5)
|
||||
log.Printf("Alerts: sent=%d, failed=%d", sent, failed)
|
||||
|
|
@ -366,11 +371,6 @@ func generateAndSendAlerts(clients map[string]ClientData, tmpl AlertRulesTemplat
|
|||
return fmt.Errorf("%d alert rules failed to upsert", failed)
|
||||
}
|
||||
|
||||
// Статические алерты — отправляются всегда вместе с динамическими
|
||||
if err := sendStaticAlerts(tmpl, config, dryRun); err != nil {
|
||||
log.Printf("Warning: static alerts error: %v", err)
|
||||
}
|
||||
|
||||
// Обновляем шаблон сообщения Contact Point
|
||||
if err := upsertContactPoint(tmpl, config, dryRun); err != nil {
|
||||
log.Printf("Warning: failed to update contact point message template: %v", err)
|
||||
|
|
@ -422,6 +422,11 @@ func buildErrorRateAlertRule(client ClientData, errCode, limitPct int, tmpl Aler
|
|||
|
||||
relFrom := int64(900)
|
||||
|
||||
forDuration := "1m"
|
||||
if errCode == 4 {
|
||||
forDuration = "3m"
|
||||
}
|
||||
|
||||
return map[string]interface{}{
|
||||
"uid": uid,
|
||||
"title": fmt.Sprintf("%s %s", codeName, client.ClientTitle),
|
||||
|
|
@ -431,7 +436,7 @@ func buildErrorRateAlertRule(client ClientData, errCode, limitPct int, tmpl Aler
|
|||
"isPaused": false,
|
||||
"folderUID": "",
|
||||
"ruleGroup": group,
|
||||
"for": "1m",
|
||||
"for": forDuration,
|
||||
"annotations": map[string]string{"summary": summary},
|
||||
"notification_settings": map[string]string{"receiver": receiver},
|
||||
"data": []interface{}{
|
||||
|
|
@ -569,7 +574,7 @@ func sendStaticAlerts(tmpl AlertRulesTemplate, config Config, dryRun bool) error
|
|||
folderUID = uid
|
||||
}
|
||||
|
||||
group := orDefault(config.AlertsGroup, defaults.Group)
|
||||
group := "[SYS] " + orDefault(config.AlertsGroup, defaults.Group)
|
||||
receiver := orDefault(config.AlertsReceiver, defaults.Receiver)
|
||||
|
||||
log.Printf("Alerts: sending %d static alert rules (concurrency: 5)", len(tmpl.StaticAlerts))
|
||||
|
|
|
|||
17
alerts_vl.go
17
alerts_vl.go
|
|
@ -57,8 +57,8 @@ func buildRPSAlertRuleVL(client ClientData, tmpl AlertRulesTemplate, config Conf
|
|||
"uid": uid,
|
||||
"title": fmt.Sprintf("VL RPS %s", client.ClientTitle),
|
||||
"condition": thresholdRefID,
|
||||
"noDataState": defaults.NoDataState,
|
||||
"execErrState": defaults.ExecErrState,
|
||||
"noDataState": "NoData", // VL: нет данных = нет алерта
|
||||
"execErrState": "Error", // VL: ошибка datasource = Error, не Alerting
|
||||
"isPaused": false,
|
||||
"folderUID": "",
|
||||
"ruleGroup": group,
|
||||
|
|
@ -253,8 +253,8 @@ func buildErrorRateAlertRuleVL(client ClientData, errCode, limitPct int, tmpl Al
|
|||
"uid": uid,
|
||||
"title": fmt.Sprintf("VL %s %s", codeName, client.ClientTitle),
|
||||
"condition": thresholdRefID,
|
||||
"noDataState": defaults.NoDataState,
|
||||
"execErrState": defaults.ExecErrState,
|
||||
"noDataState": "NoData", // VL: нет данных = нет алерта
|
||||
"execErrState": "Error", // VL: ошибка datasource = Error, не Alerting
|
||||
"isPaused": false,
|
||||
"folderUID": "",
|
||||
"ruleGroup": group,
|
||||
|
|
@ -376,5 +376,14 @@ func generateAndSendAlertsVL(clients map[string]ClientData, tmpl AlertRulesTempl
|
|||
|
||||
sent, failed := parallelUpsert(tasks, config, dryRun, 5)
|
||||
log.Printf("VL Alerts: sent=%d failed=%d", sent, failed)
|
||||
|
||||
// Статические алерты (CPU, RAM, диск, контейнеры, Angie)
|
||||
// Отправляем только если OS алерты отключены, иначе они уже отправлены там
|
||||
if !config.AlertsOSEnabled {
|
||||
if err := sendStaticAlerts(tmpl, config, dryRun); err != nil {
|
||||
log.Printf("Warning: VL static alerts error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue