42 lines
1.9 KiB
Go
42 lines
1.9 KiB
Go
package models
|
||
|
||
import "time"
|
||
|
||
// SyslogRule 表示一条 Syslog 规则,用于匹配设备日志并触发告警。
|
||
type SyslogRule 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"`
|
||
// DeviceNameContains 表示设备名称包含条件。
|
||
DeviceNameContains string `gorm:"size:512" json:"device_name_contains"`
|
||
// SourceMatch 表示来源匹配条件,可匹配来源 IP、主机名或原始行。
|
||
SourceMatch string `gorm:"size:512" json:"source_match"`
|
||
// KeywordRegex 表示关键字/内容匹配的正则表达式。
|
||
KeywordRegex string `gorm:"size:512" json:"keyword_regex"`
|
||
// MessageRegex 表示消息正文匹配的正则表达式。
|
||
MessageRegex string `gorm:"size:1024" json:"message_regex"`
|
||
// AlertName 表示告警名称。
|
||
AlertName string `gorm:"size:256" json:"alert_name"`
|
||
// SeverityCode 表示严重级别编码。
|
||
SeverityCode string `gorm:"size:32" json:"severity_code"`
|
||
// SeverityMappingJSON 保存按正则分组或厂商级别映射到平台级别的 JSON。
|
||
SeverityMappingJSON string `gorm:"type:text" json:"severity_mapping_json"`
|
||
// ResourceUIDExtractRegex 表示从消息中提取 resource_uid 的正则。
|
||
ResourceUIDExtractRegex string `gorm:"size:1024" json:"resource_uid_extract_regex"`
|
||
// PolicyID 表示关联的告警/处理策略 ID。
|
||
PolicyID uint `json:"policy_id"`
|
||
}
|
||
|
||
func (SyslogRule) TableName() string {
|
||
return "logs_syslog_rules"
|
||
}
|