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))
|
log.Printf("Alerts: sending %d dynamic rules (concurrency: 5)", len(tasks))
|
||||||
sent, failed := parallelUpsert(tasks, config, dryRun, 5)
|
sent, failed := parallelUpsert(tasks, config, dryRun, 5)
|
||||||
log.Printf("Alerts: sent=%d, failed=%d", sent, failed)
|
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)
|
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
|
// Обновляем шаблон сообщения Contact Point
|
||||||
if err := upsertContactPoint(tmpl, config, dryRun); err != nil {
|
if err := upsertContactPoint(tmpl, config, dryRun); err != nil {
|
||||||
log.Printf("Warning: failed to update contact point message template: %v", err)
|
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)
|
relFrom := int64(900)
|
||||||
|
|
||||||
|
forDuration := "1m"
|
||||||
|
if errCode == 4 {
|
||||||
|
forDuration = "3m"
|
||||||
|
}
|
||||||
|
|
||||||
return map[string]interface{}{
|
return map[string]interface{}{
|
||||||
"uid": uid,
|
"uid": uid,
|
||||||
"title": fmt.Sprintf("%s %s", codeName, client.ClientTitle),
|
"title": fmt.Sprintf("%s %s", codeName, client.ClientTitle),
|
||||||
|
|
@ -431,7 +436,7 @@ func buildErrorRateAlertRule(client ClientData, errCode, limitPct int, tmpl Aler
|
||||||
"isPaused": false,
|
"isPaused": false,
|
||||||
"folderUID": "",
|
"folderUID": "",
|
||||||
"ruleGroup": group,
|
"ruleGroup": group,
|
||||||
"for": "1m",
|
"for": forDuration,
|
||||||
"annotations": map[string]string{"summary": summary},
|
"annotations": map[string]string{"summary": summary},
|
||||||
"notification_settings": map[string]string{"receiver": receiver},
|
"notification_settings": map[string]string{"receiver": receiver},
|
||||||
"data": []interface{}{
|
"data": []interface{}{
|
||||||
|
|
@ -569,7 +574,7 @@ func sendStaticAlerts(tmpl AlertRulesTemplate, config Config, dryRun bool) error
|
||||||
folderUID = uid
|
folderUID = uid
|
||||||
}
|
}
|
||||||
|
|
||||||
group := orDefault(config.AlertsGroup, defaults.Group)
|
group := "[SYS] " + orDefault(config.AlertsGroup, defaults.Group)
|
||||||
receiver := orDefault(config.AlertsReceiver, defaults.Receiver)
|
receiver := orDefault(config.AlertsReceiver, defaults.Receiver)
|
||||||
|
|
||||||
log.Printf("Alerts: sending %d static alert rules (concurrency: 5)", len(tmpl.StaticAlerts))
|
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,
|
"uid": uid,
|
||||||
"title": fmt.Sprintf("VL RPS %s", client.ClientTitle),
|
"title": fmt.Sprintf("VL RPS %s", client.ClientTitle),
|
||||||
"condition": thresholdRefID,
|
"condition": thresholdRefID,
|
||||||
"noDataState": defaults.NoDataState,
|
"noDataState": "NoData", // VL: нет данных = нет алерта
|
||||||
"execErrState": defaults.ExecErrState,
|
"execErrState": "Error", // VL: ошибка datasource = Error, не Alerting
|
||||||
"isPaused": false,
|
"isPaused": false,
|
||||||
"folderUID": "",
|
"folderUID": "",
|
||||||
"ruleGroup": group,
|
"ruleGroup": group,
|
||||||
|
|
@ -253,8 +253,8 @@ func buildErrorRateAlertRuleVL(client ClientData, errCode, limitPct int, tmpl Al
|
||||||
"uid": uid,
|
"uid": uid,
|
||||||
"title": fmt.Sprintf("VL %s %s", codeName, client.ClientTitle),
|
"title": fmt.Sprintf("VL %s %s", codeName, client.ClientTitle),
|
||||||
"condition": thresholdRefID,
|
"condition": thresholdRefID,
|
||||||
"noDataState": defaults.NoDataState,
|
"noDataState": "NoData", // VL: нет данных = нет алерта
|
||||||
"execErrState": defaults.ExecErrState,
|
"execErrState": "Error", // VL: ошибка datasource = Error, не Alerting
|
||||||
"isPaused": false,
|
"isPaused": false,
|
||||||
"folderUID": "",
|
"folderUID": "",
|
||||||
"ruleGroup": group,
|
"ruleGroup": group,
|
||||||
|
|
@ -376,5 +376,14 @@ func generateAndSendAlertsVL(clients map[string]ClientData, tmpl AlertRulesTempl
|
||||||
|
|
||||||
sent, failed := parallelUpsert(tasks, config, dryRun, 5)
|
sent, failed := parallelUpsert(tasks, config, dryRun, 5)
|
||||||
log.Printf("VL Alerts: sent=%d failed=%d", sent, failed)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue