Added shared memory alerts

This commit is contained in:
Magnus Root 2026-04-30 17:00:42 +03:00
parent 77db1d29f1
commit 91a2c15ad3
2 changed files with 11 additions and 8 deletions

View file

@ -74,7 +74,7 @@ func buildRPSAlertRule(client ClientData, tmpl AlertRulesTemplate, config Config
// Получаем настройки из шаблона
defaults := tmpl.Defaults
receiver := orDefault(config.AlertsReceiver, defaults.Receiver)
group := fmt.Sprintf("%s %s", orDefault(config.AlertsGroup, defaults.Group), client.ClientTitle)
group := client.ClientTitle
timeRangeFrom := int64(1800)
if v, ok := tmpl.RPSAlert["relative_time_range_from"].(float64); ok {
@ -405,7 +405,7 @@ func buildErrorRateAlertRules(client ClientData, domain DomainInfo, errCode, lim
datasourceUID := config.AlertsDatasourceUID
defaults := tmpl.Defaults
receiver := orDefault(config.AlertsReceiver, defaults.Receiver)
group := fmt.Sprintf("%s %s", orDefault(config.AlertsGroup, defaults.Group), client.ClientTitle)
group := client.ClientTitle
codeRange := "[400 TO 499]"
codeName := "4xx"
@ -609,7 +609,7 @@ func sendStaticAlerts(tmpl AlertRulesTemplate, config Config, dryRun bool) error
folderUID = uid
}
group := "[SYS] " + orDefault(config.AlertsGroup, defaults.Group)
group := "[SYSTEM]"
receiver := orDefault(config.AlertsReceiver, defaults.Receiver)
log.Printf("Alerts: sending %d static alert rules (concurrency: 5)", len(tmpl.StaticAlerts))
@ -626,7 +626,10 @@ func sendStaticAlerts(tmpl AlertRulesTemplate, config Config, dryRun bool) error
rule["execErrState"] = defaults.ExecErrState
}
rule["folderUID"] = folderUID
rule["ruleGroup"] = group
// Используем группу из шаблона если задана, иначе дефолтную
if rg, ok := rule["ruleGroup"].(string); !ok || rg == "" {
rule["ruleGroup"] = group
}
if _, ok := rule["notification_settings"]; !ok {
rule["notification_settings"] = map[string]string{"receiver": receiver}
}
@ -946,7 +949,7 @@ func buildWAFBlockAlertRule(client ClientData, domain DomainInfo, tmpl AlertRule
datasourceUID := config.AlertsDatasourceUID
defaults := tmpl.Defaults
receiver := orDefault(config.AlertsReceiver, defaults.Receiver)
group := fmt.Sprintf("%s %s", orDefault(config.AlertsGroup, defaults.Group), client.ClientTitle)
group := client.ClientTitle
uid := generateAlertUID(client.ClientTitle+"_"+domain.SID, "waf_block")
title := fmt.Sprintf("%s WAF %s / %s SID:%s", client.PtafFallbackCode, client.ClientTitle, domain.DomainName, domain.SID)

View file

@ -26,7 +26,7 @@ func buildRPSAlertRuleVL(client ClientData, tmpl AlertRulesTemplate, config Conf
defaults := tmpl.Defaults
receiver := orDefault(config.AlertsReceiver, defaults.Receiver)
group := fmt.Sprintf("%s %s", orDefault(config.AlertsGroup, defaults.Group), client.ClientTitle)
group := client.ClientTitle
timeRangeFrom := int64(1800)
if v, ok := tmpl.RPSAlert["relative_time_range_from"].(float64); ok {
@ -190,7 +190,7 @@ func buildErrorRateAlertRulesVL(client ClientData, domain DomainInfo, errCode, l
defaults := tmpl.Defaults
receiver := orDefault(config.AlertsReceiver, defaults.Receiver)
group := fmt.Sprintf("%s %s", orDefault(config.AlertsGroup, defaults.Group), client.ClientTitle)
group := client.ClientTitle
codeFrom, codeTo := 400, 499
codeName := "4xx"
@ -456,7 +456,7 @@ func buildWAFBlockAlertRuleVL(client ClientData, domain DomainInfo, tmpl AlertRu
defaults := tmpl.Defaults
receiver := orDefault(config.AlertsReceiver, defaults.Receiver)
group := fmt.Sprintf("%s %s", orDefault(config.AlertsGroup, defaults.Group), client.ClientTitle)
group := client.ClientTitle
uid := generateAlertUID(client.ClientTitle+"_vl_"+domain.SID, "waf_block")
title := fmt.Sprintf("VL %s WAF %s / %s SID:%s", client.PtafFallbackCode, client.ClientTitle, domain.DomainName, domain.SID)