Documentation
¶
Index ¶
- Constants
- type AggregationStatus
- type AlertChannel
- type AlertHistory
- type AlertInhibitionRule
- type AlertSendRecord
- type AlertSilence
- type AlertTemplate
- type Api
- type CasbinRule
- type ChannelStatus
- type ChannelType
- type DingTalkConfig
- type EmailConfig
- type FeishuAppConfig
- type FeishuUser
- type KeycloakUser
- type Matcher
- type Oauth2User
- type Role
- type Tenant
- type User
- type WebhookConfig
Constants ¶
View Source
const ( StatusDisabled int = 0 // 停用 StatusEnabled int = 1 // 启用 AggregationDisabled int = 0 // 启用 AggregationEnabled int = 1 // 启用 )
View Source
const ( AlertSendRecordStatusSuccess = "success" AlertSendRecordStatusFailed = "failed" )
View Source
const ( SilenceDisabled = iota SilenceEnabled = iota SilenceExpired = iota )
View Source
const ( SilenceTypeIdentity = 1 // 精确打击型:基于指纹 (Fingerprint) SilenceTypeLabel = 2 // 范围覆盖型:基于标签 (Matchers) )
View Source
const ( ModelNameUser = "User" PreloadUsers = "Users" )
View Source
const ( UserStatusActive = iota + 1 UserStatusDisabled UserStatusInactive )
View Source
const (
PreloadApis = "Apis"
)
View Source
const PreloadRoles = "Roles"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AggregationStatus ¶
type AggregationStatus int
type AlertChannel ¶
type AlertChannel struct {
ID int `gorm:"primarykey;comment:主键ID" json:"id"`
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt,omitempty"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt,omitempty"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index" json:"-"`
Name string `gorm:"column:name;type:varchar(100);not null;uniqueIndex;comment:告警渠道名称(如: SRE团队钉钉群)" json:"name"`
Type ChannelType `gorm:"column:type;type:varchar(50);not null;index;comment:渠道类型(feishuApp/feishuBoot/webhook)" json:"type"`
Status *int `gorm:"column:status;type:tinyint;not null;default:1;index;comment:状态(0-停用, 1-启用)" json:"status"`
AggregationStatus *int `gorm:"column:aggregation_status;type:tinyint;not null;index;comment:状态(0-停用, 1-启用)" json:"aggregationStatus"`
Config datatypes.JSON `gorm:"column:config;type:json;not null;comment:渠道动态配置(JSON格式)" json:"config"`
Description string `gorm:"column:description;type:varchar(255);comment:描述与备注" json:"description"`
AlertTemplateID int `gorm:"column:alert_template_id;index;comment:绑定的告警模板ID" json:"alertTemplateID"`
AlertTemplate *AlertTemplate `gorm:"foreignKey:AlertTemplateID" json:"alertTemplate,omitempty"`
}
AlertChannel 告警渠道表
func (*AlertChannel) GetFeishuAppConfig ¶
func (a *AlertChannel) GetFeishuAppConfig() (*FeishuAppConfig, error)
GetFeishuAppConfig 获取飞书应用配置
type AlertHistory ¶
type AlertHistory struct {
ID int `gorm:"column:id;primaryKey;autoIncrement;comment:主键ID" json:"id"`
CreatedAt time.Time `gorm:"column:created_at;type:datetime;autoCreateTime;comment:本条记录存入数据库的时间" json:"createdAt"`
Fingerprint string `` /* 127-byte string literal not displayed */
StartsAt time.Time `` /* 139-byte string literal not displayed */
Cluster string `` /* 173-byte string literal not displayed */
Status string `gorm:"column:status;type:varchar(32);not null;index:idx_status_cluster,priority:1;comment:告警状态" json:"status"`
EndsAt *time.Time `gorm:"column:ends_at;type:datetime;index:idx_ends_at;comment:告警恢复时间" json:"endsAt"`
AlertChannelID int `gorm:"column:alert_channel_id;not null;index:idx_channel_id;comment:关联通道ID" json:"alertChannelId"`
AlertSendRecordID *int `gorm:"column:alert_send_record_id;index:idx_send_record_id;comment:关联发送记录ID和分组ID" json:"alertSendRecordID"`
AlertSilenceID int `gorm:"column:alert_silence_id;index:idx_history_silence_id;comment:关联静默规则ID" json:"alertSilenceID"`
Alertname string `gorm:"column:alertname;type:varchar(255);not null" json:"alertname"`
Severity string `gorm:"column:severity;type:varchar(32)" json:"severity"`
Instance string `gorm:"column:instance;type:varchar(255)" json:"instance"`
Labels datatypes.JSON `gorm:"column:labels;type:json" json:"labels"`
Annotations datatypes.JSON `gorm:"column:annotations;type:json" json:"annotations"`
SendCount int `gorm:"column:send_count;type:int;size:3" json:"sendCount"`
IsSilenced bool `gorm:"column:is_silenced;default:false" json:"isSilenced"`
AlertChannel *AlertChannel `gorm:"foreignKey:AlertChannelID" json:"alertChannel"`
AlertSendRecord *AlertSendRecord `gorm:"foreignKey:AlertSendRecordID" json:"alertSendRecord"`
AlertSilence *AlertSilence `gorm:"foreignKey:AlertSilenceID" json:"alertSilence"`
}
AlertHistory 告警历史记录表
func (*AlertHistory) BeforeSave ¶
func (a *AlertHistory) BeforeSave(tx *gorm.DB) (err error)
BeforeSave GORM 钩子:在保存到数据库前,统一截断时间精度到毫秒 这样可以保证:写入数据库的值 == 内存中的值 == 未来查询的值
func (*AlertHistory) TableName ¶
func (*AlertHistory) TableName() string
type AlertInhibitionRule ¶
type AlertInhibitionRule struct {
ID int `gorm:"primaryKey;autoIncrement" json:"id"`
Name string `gorm:"type:varchar(64);comment:规则名称" json:"name"`
SourceMatchers []*Matcher `gorm:"type:json;comment:源告警(抑制者)匹配器" json:"sourceMatchers"`
TargetMatchers []*Matcher `gorm:"type:json;comment:目标告警(被抑制者)匹配器" json:"targetMatchers"`
EqualLabels []string `gorm:"type:json;comment:必须相等的标签列表" json:"equalLabels"`
Status int `gorm:"type:tinyint;default:1;comment:1启用 0禁用" json:"status"`
}
type AlertSendRecord ¶
type AlertSendRecord struct {
ID int `gorm:"primaryKey;autoIncrement" json:"id"`
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt,omitempty"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt,omitempty"`
AlertHistory []*AlertHistory `gorm:"foreignKey:AlertSendRecordID" json:"alertHistory"`
SendStatus string `gorm:"column:send_status;type:varchar(32);not null;index;comment:发送状态(success, failed)" json:"sendStatus"`
ErrorMessage string `gorm:"column:error_message;type:text;comment:如果发送失败,记录失败的报错详情(供排查)" json:"errorMessage"`
ExternalMessageID string `` /* 148-byte string literal not displayed */
}
AlertSendRecord 告警发送明细/日志表
func UpdateSendRecordStatus ¶
func UpdateSendRecordStatus(sendErr error) *AlertSendRecord
func (*AlertSendRecord) TableName ¶
func (*AlertSendRecord) TableName() string
type AlertSilence ¶
type AlertSilence struct {
ID int `gorm:"primaryKey;autoIncrement" json:"id"`
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt,omitempty"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt,omitempty"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index" json:"-"`
Cluster string `` /* 139-byte string literal not displayed */
Type int `gorm:"column:type;comment:1:指纹静默, 2:标签静默" json:"type"`
Fingerprint string `gorm:"index;comment:精确匹配的指纹" json:"fingerprint"`
Status *int `` /* 148-byte string literal not displayed */
EndsAt time.Time `gorm:"column:ends_at;not null;index:idx_cluster_status_ends_starts,priority:3;comment:结束时间" json:"endsAt"`
StartsAt time.Time `gorm:"column:starts_at;not null;index:idx_cluster_status_ends_starts,priority:4;comment:开始时间" json:"startsAt"`
Matchers datatypes.JSON `gorm:"column:matchers;type:json;not null;comment:匹配器集合" json:"matchers"`
CreatedBy string `gorm:"column:created_by;type:varchar(64)" json:"createdBy"`
Comment string `gorm:"column:comment;type:text;comment:静默原因" json:"comment"`
}
AlertSilence 静默规则表
type AlertTemplate ¶
type AlertTemplate struct {
ID int `gorm:"primaryKey" json:"id"`
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt,omitempty"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt,omitempty"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index" json:"-"`
Name string `gorm:"column:name;type:varchar(100);not null;uniqueIndex;comment:模板名称" json:"name"`
Description string `gorm:"column:description;type:varchar(255)" json:"description"`
Template string `gorm:"column:template;type:text;not null;comment:单个告警(Markdown/HTML)模板" json:"template"`
AggregationTemplate string `gorm:"column:aggregation_template;type:text;comment:聚合告警(Markdown/HTML)模板" json:"aggregationTemplate"`
}
AlertTemplate 告警模板表
type Api ¶
type Api struct {
ID int64 `gorm:"column:id;primarykey" json:"id,omitempty"`
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt,omitempty"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt,omitempty"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index" json:"-"`
Name string `gorm:"column:name" json:"name,omitempty"`
Path string `gorm:"column:path" json:"path,omitempty"`
Method string `gorm:"column:method" json:"method,omitempty"`
Effect string `gorm:"column:effect;comment:访问接口的策略:allow或deny;size:5" json:"effect"`
Description string `gorm:"column:description" json:"description,omitempty"`
Roles []*Role `gorm:"many2many:role_apis" json:"roles,omitempty"`
}
type CasbinRule ¶
type CasbinRule struct {
ID int64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
PType *string `gorm:"column:ptype" json:"ptype"`
V0 *string `gorm:"column:v0" json:"v0"`
V1 *string `gorm:"column:v1" json:"v1"`
V2 *string `gorm:"column:v2" json:"v2"`
V3 *string `gorm:"column:v3" json:"v3"`
V4 *string `gorm:"column:v4" json:"v4"`
V5 *string `gorm:"column:v5" json:"v5"`
}
func (*CasbinRule) TableName ¶
func (*CasbinRule) TableName() string
type ChannelStatus ¶
type ChannelStatus int
type ChannelType ¶
type ChannelType string
ChannelType 定义告警渠道的类型
const ( ChannelTypeFeishuApp ChannelType = "feishuApp" ChannelTypeFeishuBoot ChannelType = "feishuBoot" ChannelTypeWebhook ChannelType = "webhook" )
type DingTalkConfig ¶
type DingTalkConfig struct {
WebhookURL string `json:"webhook_url"`
Secret string `json:"secret,omitempty"` // 加签密钥
}
DingTalkConfig 钉钉机器人配置
type EmailConfig ¶
type EmailConfig struct {
SMTPHost string `json:"smtp_host"`
SMTPPort int `json:"smtp_port"`
Username string `json:"username"`
Password string `json:"password"`
To []string `json:"to"` // 收件人列表
}
EmailConfig 邮件配置
type FeishuAppConfig ¶
type FeishuAppConfig struct {
AppID string `json:"app_id"` // 飞书应用的 App ID
AppSecret string `json:"app_secret"` // 飞书应用的 App Secret
ReceiveIdType string `json:"receive_id_type"` // 接收者类型: open_id, user_id, email, chat_id
ReceiveId string `json:"receive_id"` // 接收者ID (具体是哪个用户或哪个群)
}
FeishuAppConfig 飞书自建应用配置
type FeishuUser ¶
type FeishuUser struct {
UID int64 `gorm:"column:uid;primarykey;comment:关联users表中的用户id" json:"uid"`
User *User `gorm:"foreignKey:UID;references:ID" json:"user"`
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index" json:"-"`
AvatarBig string `gorm:"column:avatar_big;size:255;comment:飞书用户avatar_big" json:"avatar_big"`
AvatarMiddle string `gorm:"column:avatar_middle;size:255;comment:飞书用户avatar_middle" json:"avatar_middle"`
AvatarThumb string `gorm:"column:avatar_thumb;size:255;comment:飞书用户avatar_thumb" json:"avatar_thumb"`
AvatarUrl string `gorm:"column:avatar_url;size:255;comment:飞书用户avatar_url" json:"avatar_url"`
Email string `gorm:"column:email;size:255;comment:飞书用户email" json:"email"`
EmployeeNo string `gorm:"column:employee_no;size:255;comment:飞书用户employee_no" json:"employee_no"`
EnName string `gorm:"column:en_name;size:255;comment:飞书用户en_name" json:"en_name"`
EnterpriseEmail string `gorm:"column:enterprise_email;size:255;comment:飞书用户enterprise_email" json:"enterprise_email"`
Mobile string `gorm:"column:mobile;size:255;comment:飞书用户mobile" json:"mobile"`
Name string `gorm:"column:name;size:255;comment:飞书用户name" json:"name"`
OpenID string `gorm:"column:open_id;size:255;comment:飞书用户open_id" json:"open_id"`
TenantKey string `gorm:"column:tenant_key;size:255;comment:飞书用户tenant_key" json:"tenant_key"`
UnionID string `gorm:"column:union_id;size:255;comment:飞书用户union_id" json:"union_id"`
UserID string `gorm:"column:user_id;size:255;comment:飞书用户ID;index:idx_user_id_status,priority:1" json:"user_id"`
}
type KeycloakUser ¶
type KeycloakUser struct {
Sub string `json:"sub"`
EmailVerified bool `json:"email_verified"`
Roles []string `json:"roles"`
Name string `json:"name"`
PreferredUsername string `json:"preferred_username"`
GivenName string `json:"given_name"`
FamilyName string `json:"family_name"`
Email string `json:"email"`
Group []string `json:"group"`
}
type Matcher ¶
type Matcher struct {
Name string `json:"name"` // 标签名
Value string `json:"value"` // 标签值
Type string `json:"type"` // 操作符: =, !=, =~, !~
}
Matcher 匹配器具体结构
type Oauth2User ¶
type Oauth2User struct {
ID int64 `gorm:"column:id;primarykey;autoIncrement" json:"id"`
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index" json:"-"`
Email string `gorm:"column:email;size:255;index" json:"email"`
Provider string `gorm:"column:provider;size:255" json:"provider"`
Details datatypes.JSON `gorm:"column:details" json:"details"`
User *User `gorm:"foreignKey:Email;references:Email" json:"user"`
}
func NewOauth2User ¶
func NewOauth2User(email, provider string, details datatypes.JSON) *Oauth2User
func (*Oauth2User) TableName ¶
func (receiver *Oauth2User) TableName() string
type Role ¶
type Role struct {
ID int64 `gorm:"column:id;primarykey" json:"id,omitempty"`
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt,omitempty"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt,omitempty"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index" json:"-"`
Name string `gorm:"column:name" json:"name,omitempty"`
Description string `gorm:"column:description" json:"description,omitempty"`
Users []*User `gorm:"many2many:user_roles" json:"users,omitempty"`
Apis []*Api `gorm:"many2many:role_apis" json:"apis,omitempty"`
}
type Tenant ¶
type Tenant struct {
ID int64 `gorm:"column:id;primarykey;autoIncrement" json:"id"`
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"`
Name string `gorm:"column:name" json:"name"`
Description string `gorm:"column:description" json:"description"`
}
type User ¶
type User struct {
ID int64 `gorm:"column:id;primarykey;autoIncrement" json:"id"`
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index" json:"-"`
Name string `gorm:"column:name;comment:用户名称;size:50" json:"name"`
NickName string `gorm:"column:nick_name;comment:用户昵称;size:50" json:"nickName"`
Department string `gorm:"column:department;comment:用户部门;size:50" json:"department"`
Email string `gorm:"column:email;comment:邮箱;size:100" json:"email"`
Password string `gorm:"column:password;comment:用户密码;size:255" json:"-"`
Avatar string `gorm:"column:avatar;comment:用户头像;size:1024" json:"avatar"`
Mobile string `gorm:"column:mobile;comment:用户手机号;size:20" json:"mobile"`
Status *int `gorm:"column:status;comment:用户状态,1可用,2禁用,3未激活;size:1;default:1" json:"status"`
Roles []*Role `gorm:"many2many:user_roles" json:"roles,omitempty"`
Oauth2User *Oauth2User `gorm:"foreignKey:Email;references:Email" json:"oauth2User,omitempty"`
}
Click to show internal directories.
Click to hide internal directories.