models

package
v0.26.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DropDB

func DropDB() error

DropDB 中文函数注释:删除事件转发插件相关的表及数据。

func HasEnabledEventConfigs

func HasEnabledEventConfigs() (bool, error)

HasEnabledEventConfigs 中文函数注释:判断是否存在已启用的事件规则。

func InitDB

func InitDB() error

InitDB 中文函数注释:初始化数据库表(GORM自动迁移)。

func UpgradeDB

func UpgradeDB(fromVersion string, toVersion string) error

UpgradeDB 中文函数注释:升级事件转发插件数据库结构与数据。

Types

type EventForwardSetting

type EventForwardSetting struct {
	ID uint `gorm:"primaryKey;autoIncrement" json:"id,omitempty"`

	EventWorkerProcessInterval int `json:"event_worker_process_interval"`
	EventWorkerBatchSize       int `json:"event_worker_batch_size"`
	EventWorkerMaxRetries      int `json:"event_worker_max_retries"`
	EventWatcherBufferSize     int `json:"event_watcher_buffer_size"`

	CreatedAt time.Time `json:"created_at,omitempty" gorm:"<-:create"`
	UpdatedAt time.Time `json:"updated_at,omitempty"`
}

EventForwardSetting 中文函数注释:事件转发总开关与运行参数配置表。

func DefaultEventForwardSetting

func DefaultEventForwardSetting() *EventForwardSetting

DefaultEventForwardSetting 中文函数注释:返回默认配置(默认关闭)。

func GetOrCreateEventForwardSetting

func GetOrCreateEventForwardSetting() (*EventForwardSetting, error)

GetOrCreateEventForwardSetting 中文函数注释:获取事件转发配置;若不存在则写入一条默认记录。

func UpdateEventForwardSetting

func UpdateEventForwardSetting(in *EventForwardSetting) (*EventForwardSetting, error)

UpdateEventForwardSetting 中文函数注释:更新事件转发配置(确保只维护一条记录)。

func (EventForwardSetting) TableName

func (EventForwardSetting) TableName() string

TableName 中文函数注释:设置表名。

type K8sEvent

type K8sEvent struct {
	ID        int64     `gorm:"primaryKey;autoIncrement" json:"id"`
	EvtKey    string    `gorm:"uniqueIndex;" json:"evt_key"`
	Cluster   string    `gorm:"type:varchar(128);" json:"cluster"`
	Namespace string    `gorm:"type:varchar(64);index" json:"namespace"`
	Name      string    `gorm:"type:varchar(128);" json:"name"`
	Type      string    `gorm:"type:varchar(16);" json:"type"`
	Reason    string    `gorm:"type:varchar(128);" json:"reason"`
	Level     string    `gorm:"type:varchar(16);" json:"level"`
	Message   string    `gorm:"type:text;" json:"message"`
	Timestamp time.Time `gorm:"index" json:"timestamp"`
	Processed bool      `gorm:"default:false;index" json:"processed"`
	Attempts  int       `gorm:"default:0" json:"-"`
	CreatedAt time.Time `json:"created_at,omitempty" gorm:"<-:create"`
	UpdatedAt time.Time `json:"-"`
}

K8sEvent 中文函数注释:事件转发插件使用的K8s事件模型。

func (*K8sEvent) Delete

func (e *K8sEvent) Delete(params *dao.Params, ids string, queryFuncs ...func(*gorm.DB) *gorm.DB) error

Delete 中文函数注释:根据ID删除事件记录。

func (*K8sEvent) GetByEvtKey

func (e *K8sEvent) GetByEvtKey(evtKey string) (*K8sEvent, error)

GetByEvtKey 中文函数注释:根据事件键获取事件。

func (*K8sEvent) GetOne

func (e *K8sEvent) GetOne(params *dao.Params, queryFuncs ...func(*gorm.DB) *gorm.DB) (*K8sEvent, error)

GetOne 中文函数注释:获取单条事件记录。

func (*K8sEvent) IncrementAttemptsByID

func (e *K8sEvent) IncrementAttemptsByID(id int64) error

IncrementAttemptsByID 中文函数注释:根据ID增加重试次数。

func (*K8sEvent) IsNormal

func (e *K8sEvent) IsNormal() bool

IsNormal 中文函数注释:判断是否为正常类型事件。

func (*K8sEvent) IsWarning

func (e *K8sEvent) IsWarning() bool

IsWarning 中文函数注释:判断是否为警告类型事件。

func (*K8sEvent) List

func (e *K8sEvent) List(params *dao.Params, queryFuncs ...func(*gorm.DB) *gorm.DB) ([]*K8sEvent, int64, error)

List 中文函数注释:列出事件记录。

func (*K8sEvent) ListUnprocessed

func (e *K8sEvent) ListUnprocessed(limit int) ([]*K8sEvent, error)

ListUnprocessed 中文函数注释:列出未处理的事件,按时间升序,限制条数。

func (*K8sEvent) MarkProcessedByID

func (e *K8sEvent) MarkProcessedByID(id int64, processed bool) error

MarkProcessedByID 中文函数注释:根据ID更新处理状态。

func (*K8sEvent) Save

func (e *K8sEvent) Save(params *dao.Params, queryFuncs ...func(*gorm.DB) *gorm.DB) error

Save 中文函数注释:保存事件记录。

func (*K8sEvent) SaveEvent

func (e *K8sEvent) SaveEvent() error

SaveEvent 中文函数注释:以默认参数保存事件记录。

func (*K8sEvent) ShouldProcess

func (e *K8sEvent) ShouldProcess() bool

ShouldProcess 中文函数注释:判断事件是否应该被处理。

func (*K8sEvent) TableName

func (e *K8sEvent) TableName() string

TableName 中文函数注释:设置表名。

type K8sEventConfig

type K8sEventConfig struct {
	ID               uint   `gorm:"primaryKey;autoIncrement" json:"id,omitempty"`
	Name             string `json:"name"`                                // 事件转发配置名称
	Description      string `json:"description"`                         // 事件转发配置描述
	Clusters         string `json:"clusters"`                            // 目标集群列表
	Webhooks         string `json:"webhooks"`                            // webhook列表
	WebhookNames     string `json:"webhook_names"`                       // webhook 名称列表
	Enabled          bool   `json:"enabled"`                             // 是否启用该任务
	AIEnabled        bool   `json:"ai_enabled"`                          // 是否启用AI总结功能
	AIPromptTemplate string `gorm:"type:text" json:"ai_prompt_template"` // AI总结提示词模板

	RuleNamespaces string `json:"rule_namespaces" gorm:"type:text"` // []string 精确匹配命名空间
	RuleNames      string `json:"rule_names" gorm:"type:text"`      // []string 包含匹配名称
	RuleReasons    string `json:"rule_reasons" gorm:"type:text"`    // []string 包含匹配Reason、Message两个字段
	RuleReverse    bool   `json:"rule_reverse" gorm:"default:false"`

	CreatedAt time.Time `json:"created_at,omitempty" gorm:"<-:create"`
	UpdatedAt time.Time `json:"updated_at,omitempty"`
}

K8sEventConfig 中文函数注释:Event 监听 转发 发送webhook配置表。

func (*K8sEventConfig) Delete

func (c *K8sEventConfig) Delete(params *dao.Params, ids string, queryFuncs ...func(*gorm.DB) *gorm.DB) error

Delete 中文函数注释:根据指定 ID 删除 K8sEventConfig 实例。

func (*K8sEventConfig) GetOne

func (c *K8sEventConfig) GetOne(params *dao.Params, queryFuncs ...func(*gorm.DB) *gorm.DB) (*K8sEventConfig, error)

GetOne 中文函数注释:获取单个 K8sEventConfig 实例。

func (*K8sEventConfig) List

func (c *K8sEventConfig) List(params *dao.Params, queryFuncs ...func(*gorm.DB) *gorm.DB) ([]*K8sEventConfig, int64, error)

List 中文函数注释:返回符合条件的 K8sEventConfig 列表及总数。

func (*K8sEventConfig) Save

func (c *K8sEventConfig) Save(params *dao.Params, queryFuncs ...func(*gorm.DB) *gorm.DB) error

Save 中文函数注释:保存或更新 K8sEventConfig 实例。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL