fix: correlate log alert recovery lifecycle
This commit is contained in:
@@ -108,6 +108,8 @@ func seedDefaultSyslogRules(db *gorm.DB) error {
|
||||
KeywordRegex: "(?i)(link down|interface .* down|port .* down)",
|
||||
SourceMatch: "",
|
||||
MessageRegex: "(?i)(link down|interface .* down|port .* down|LINK_DOWN)",
|
||||
RecoveryMatchRegex: `(?i)(link[ _-]?up|interface .* up|port .* up|ifup)`,
|
||||
LifecycleKey: "syslog-link-state",
|
||||
AlertName: "Syslog链路中断",
|
||||
SeverityCode: "major",
|
||||
SeverityMappingJSON: `{"(?i)(critical|fatal|emergency)":"critical","(?i)(error|LINK_DOWN|down)":"major","(?i)(warning|warn)":"warning"}`,
|
||||
@@ -118,8 +120,10 @@ func seedDefaultSyslogRules(db *gorm.DB) error {
|
||||
Name: "H3C-Syslog-接口中断",
|
||||
Enabled: true,
|
||||
Priority: 120,
|
||||
SourceMatch: "h3c",
|
||||
DeviceNameContains: "h3c",
|
||||
MessageRegex: `(?i)(LINK_DOWN|Interface .* down|port .* down)`,
|
||||
RecoveryMatchRegex: `(?i)(link[ _-]?up|interface .* up|port .* up|ifup)`,
|
||||
LifecycleKey: "h3c-syslog-interface-state",
|
||||
AlertName: "H3C Syslog接口中断",
|
||||
SeverityCode: "major",
|
||||
SeverityMappingJSON: `{"(?i)(LINK_DOWN|down)":"major","(?i)(LINK_UP|up)":"info"}`,
|
||||
@@ -147,6 +151,8 @@ func seedDefaultSyslogRules(db *gorm.DB) error {
|
||||
"source_match",
|
||||
"keyword_regex",
|
||||
"message_regex",
|
||||
"recovery_match_regex",
|
||||
"lifecycle_key",
|
||||
"alert_name",
|
||||
"severity_code",
|
||||
"severity_mapping_json",
|
||||
@@ -162,14 +168,16 @@ func seedDefaultSyslogRules(db *gorm.DB) error {
|
||||
func seedDefaultTrapRules(db *gorm.DB) error {
|
||||
rows := []TrapRule{
|
||||
{
|
||||
Name: "默认-Trap链路中断",
|
||||
Enabled: true,
|
||||
Priority: 100,
|
||||
OIDPrefix: "1.3.6.1.6.3.1.1.5",
|
||||
VarbindMatchRegex: "(?i)(linkdown|ifdown|down)",
|
||||
AlertName: "SNMP Trap链路中断",
|
||||
SeverityCode: "major",
|
||||
PolicyID: 0,
|
||||
Name: "默认-Trap链路中断",
|
||||
Enabled: true,
|
||||
Priority: 100,
|
||||
OIDPrefix: "1.3.6.1.6.3.1.1.5",
|
||||
VarbindMatchRegex: `(?i)(1\.3\.6\.1\.6\.3\.1\.1\.5\.3([^0-9]|$)|\b(linkdown|ifdown|down)\b)`,
|
||||
RecoveryMatchRegex: `(?i)(1\.3\.6\.1\.6\.3\.1\.1\.5\.4([^0-9]|$)|\b(linkup|ifup)\b)`,
|
||||
LifecycleKey: "snmp-interface-link-state",
|
||||
AlertName: "SNMP Trap链路中断",
|
||||
SeverityCode: "major",
|
||||
PolicyID: 0,
|
||||
},
|
||||
}
|
||||
for _, row := range rows {
|
||||
@@ -190,6 +198,8 @@ func seedDefaultTrapRules(db *gorm.DB) error {
|
||||
"priority",
|
||||
"o_id_prefix",
|
||||
"varbind_match_regex",
|
||||
"recovery_match_regex",
|
||||
"lifecycle_key",
|
||||
"alert_name",
|
||||
"severity_code",
|
||||
"policy_id",
|
||||
|
||||
@@ -24,6 +24,10 @@ type SyslogRule struct {
|
||||
KeywordRegex string `gorm:"size:512" json:"keyword_regex"`
|
||||
// MessageRegex 表示消息正文匹配的正则表达式。
|
||||
MessageRegex string `gorm:"size:1024" json:"message_regex"`
|
||||
// RecoveryMatchRegex 匹配同一生命周期的恢复消息。
|
||||
RecoveryMatchRegex string `gorm:"size:1024" json:"recovery_match_regex"`
|
||||
// LifecycleKey 将故障和恢复事件绑定到同一告警生命周期。
|
||||
LifecycleKey string `gorm:"size:256" json:"lifecycle_key"`
|
||||
// AlertName 表示告警名称。
|
||||
AlertName string `gorm:"size:256" json:"alert_name"`
|
||||
// SeverityCode 表示严重级别编码。
|
||||
|
||||
@@ -1,33 +1,37 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
// TrapRule 表示一条 SNMP Trap 规则,用于匹配并触发告警策略。
|
||||
type TrapRule struct {
|
||||
// ID 是数据库主键。
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
// CreatedAt 记录创建时间(GORM 自动维护)。
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
// UpdatedAt 记录更新时间(GORM 自动维护)。
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
// Name 规则名称,用于展示/标识。
|
||||
Name string `gorm:"size:256" json:"name"`
|
||||
// Enabled 表示该规则是否启用。
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
// Priority 表示匹配优先级(数值越高/低需以业务约定为准)。
|
||||
Priority int `gorm:"index" json:"priority"`
|
||||
// OIDPrefix 表示匹配的 OID 前缀。
|
||||
OIDPrefix string `gorm:"size:512" json:"oid_prefix"`
|
||||
// VarbindMatchRegex 表示对 varbind 内容的正则匹配条件。
|
||||
VarbindMatchRegex string `gorm:"size:512" json:"varbind_match_regex"`
|
||||
// AlertName 表示告警名称。
|
||||
AlertName string `gorm:"size:256" json:"alert_name"`
|
||||
// SeverityCode 表示严重级别编码。
|
||||
SeverityCode string `gorm:"size:32" json:"severity_code"`
|
||||
// PolicyID 表示关联的告警/处理策略 ID。
|
||||
PolicyID uint `json:"policy_id"`
|
||||
}
|
||||
|
||||
func (TrapRule) TableName() string {
|
||||
return "logs_trap_rules"
|
||||
}
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
// TrapRule 表示一条 SNMP Trap 规则,用于匹配并触发告警策略。
|
||||
type TrapRule struct {
|
||||
// ID 是数据库主键。
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
// CreatedAt 记录创建时间(GORM 自动维护)。
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
// UpdatedAt 记录更新时间(GORM 自动维护)。
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
// Name 规则名称,用于展示/标识。
|
||||
Name string `gorm:"size:256" json:"name"`
|
||||
// Enabled 表示该规则是否启用。
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
// Priority 表示匹配优先级(数值越高/低需以业务约定为准)。
|
||||
Priority int `gorm:"index" json:"priority"`
|
||||
// OIDPrefix 表示匹配的 OID 前缀。
|
||||
OIDPrefix string `gorm:"size:512" json:"oid_prefix"`
|
||||
// VarbindMatchRegex 表示对 varbind 内容的正则匹配条件。
|
||||
VarbindMatchRegex string `gorm:"size:512" json:"varbind_match_regex"`
|
||||
// RecoveryMatchRegex 匹配同一生命周期的恢复 Trap OID 或 varbind。
|
||||
RecoveryMatchRegex string `gorm:"size:1024" json:"recovery_match_regex"`
|
||||
// LifecycleKey 将故障和恢复事件绑定到同一告警生命周期。
|
||||
LifecycleKey string `gorm:"size:256" json:"lifecycle_key"`
|
||||
// AlertName 表示告警名称。
|
||||
AlertName string `gorm:"size:256" json:"alert_name"`
|
||||
// SeverityCode 表示严重级别编码。
|
||||
SeverityCode string `gorm:"size:32" json:"severity_code"`
|
||||
// PolicyID 表示关联的告警/处理策略 ID。
|
||||
PolicyID uint `json:"policy_id"`
|
||||
}
|
||||
|
||||
func (TrapRule) TableName() string {
|
||||
return "logs_trap_rules"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user