82 lines
3.9 KiB
Go
82 lines
3.9 KiB
Go
package model
|
||
|
||
import (
|
||
"time"
|
||
)
|
||
|
||
// LogDataSource 日志数据源连接配置(Loki / Elasticsearch)
|
||
// 平台不存储海量日志,仅存连接信息与告警策略 // Logan.Li
|
||
type LogDataSource struct {
|
||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||
Name string `gorm:"type:varchar(128);not null;uniqueIndex;comment:数据源名称" json:"name"`
|
||
Type string `gorm:"type:varchar(32);not null;index;comment:类型 loki/elasticsearch" json:"type"`
|
||
URL string `gorm:"type:varchar(512);not null;comment:服务地址" json:"url"`
|
||
AuthType string `gorm:"type:varchar(32);default:'none';comment:认证方式 none/basic/bearer/custom" json:"auth_type"`
|
||
BasicAuth bool `gorm:"default:false;comment:基础认证(兼容旧版)" json:"basic_auth"`
|
||
BasicAuthUser string `gorm:"type:varchar(128);comment:认证用户名" json:"basic_auth_user,omitempty"`
|
||
BasicAuthPass string `gorm:"type:varchar(256);comment:认证密码" json:"basic_auth_pass,omitempty"`
|
||
Token string `gorm:"type:varchar(512);comment:Bearer Token" json:"token,omitempty"`
|
||
Headers string `gorm:"type:text;comment:自定义Headers JSON数组" json:"headers,omitempty"`
|
||
SkipTLSVerify bool `gorm:"default:false;comment:跳过TLS验证" json:"skip_tls_verify"`
|
||
DefaultIndex string `gorm:"type:varchar(128);comment:ES默认索引" json:"default_index,omitempty"`
|
||
IsDefault bool `gorm:"default:false;index;comment:是否默认" json:"is_default"`
|
||
Status int `gorm:"default:1;comment:状态 1启用 0禁用" json:"status"`
|
||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||
DeletedAt *time.Time `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"`
|
||
}
|
||
|
||
func (LogDataSource) TableName() string {
|
||
return "monitor_log_datasources"
|
||
}
|
||
|
||
// CreateLogDSReq 创建日志数据源 // Logan.Li
|
||
type CreateLogDSReq struct {
|
||
Name string `json:"name" binding:"required"`
|
||
Type string `json:"type" binding:"required"`
|
||
URL string `json:"url" binding:"required"`
|
||
AuthType string `json:"auth_type"`
|
||
BasicAuth bool `json:"basic_auth"`
|
||
BasicAuthUser string `json:"basic_auth_user"`
|
||
BasicAuthPass string `json:"basic_auth_pass"`
|
||
Token string `json:"token"`
|
||
Headers string `json:"headers"`
|
||
SkipTLSVerify bool `json:"skip_tls_verify"`
|
||
DefaultIndex string `json:"default_index"`
|
||
IsDefault bool `json:"is_default"`
|
||
}
|
||
|
||
// UpdateLogDSReq 更新日志数据源 // Logan.Li
|
||
type UpdateLogDSReq struct {
|
||
Name *string `json:"name"`
|
||
Type *string `json:"type"`
|
||
URL *string `json:"url"`
|
||
AuthType *string `json:"auth_type"`
|
||
BasicAuth *bool `json:"basic_auth"`
|
||
BasicAuthUser *string `json:"basic_auth_user"`
|
||
BasicAuthPass *string `json:"basic_auth_pass"`
|
||
Token *string `json:"token"`
|
||
Headers *string `json:"headers"`
|
||
SkipTLSVerify *bool `json:"skip_tls_verify"`
|
||
DefaultIndex *string `json:"default_index"`
|
||
IsDefault *bool `json:"is_default"`
|
||
Status *int `json:"status"`
|
||
}
|
||
|
||
// TestLogDSReq 测试连接 // Logan.Li
|
||
// 支持两种模式:
|
||
// 1. 新建/未保存场景:必须传 type + url + 认证参数;
|
||
// 2. 已保存数据源场景:传 datasource_id,后端读取完整配置(含密码)再测试。// Logan.Li
|
||
type TestLogDSReq struct {
|
||
DatasourceID uint `json:"datasource_id"`
|
||
Type string `json:"type"`
|
||
URL string `json:"url"`
|
||
AuthType string `json:"auth_type"`
|
||
BasicAuth bool `json:"basic_auth"`
|
||
BasicAuthUser string `json:"basic_auth_user"`
|
||
BasicAuthPass string `json:"basic_auth_pass"`
|
||
Token string `json:"token"`
|
||
Headers string `json:"headers"`
|
||
SkipTLSVerify bool `json:"skip_tls_verify"`
|
||
}
|