package model import ( "time" ) // PrometheusDataSource Prometheus 数据源配置(参考 Grafana 界面设计) // Logan.Li type PrometheusDataSource struct { ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"` Name string `gorm:"type:varchar(128);not null;uniqueIndex;comment:数据源名称" json:"name"` URL string `gorm:"type:varchar(512);not null;comment:Prometheus 服务地址" json:"url"` Access string `gorm:"type:varchar(16);default:'server';comment:访问模式: server/proxy" json:"access"` // Basic Auth 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"` WithCredentials bool `gorm:"default:false;comment:携带凭证" json:"with_credentials"` // TLS Client Auth TLSClientAuth bool `gorm:"default:false;comment:启用TLS客户端认证" json:"tls_client_auth"` WithCACert bool `gorm:"default:false;comment:携带CA证书" json:"with_ca_cert"` CACert string `gorm:"type:text;comment:CA证书内容(PEM)" json:"ca_cert,omitempty"` SkipTLSVerify bool `gorm:"default:false;comment:跳过TLS验证" json:"skip_tls_verify"` // Custom HTTP Headers (JSON array of {header, value}) CustomHeaders string `gorm:"type:text;comment:自定义HTTP头(JSON)" json:"custom_headers,omitempty"` // Alerting EnableAlerting bool `gorm:"default:true;comment:启用告警管理" json:"enable_alerting"` AlertmanagerDS string `gorm:"type:varchar(128);comment:Alertmanager数据源" json:"alertmanager_ds,omitempty"` // 采集与查询 ScrapeInterval int `gorm:"default:15;comment:采集间隔(秒)" json:"scrape_interval"` QueryTimeout int `gorm:"default:60;comment:查询超时(秒)" json:"query_timeout"` HTTPMethod string `gorm:"type:varchar(8);default:'POST';comment:HTTP方法" json:"http_method"` // 杂项 DisableMetricsLookup bool `gorm:"default:false;comment:禁用指标查找" json:"disable_metrics_lookup"` CustomQueryParams string `gorm:"type:text;comment:自定义查询参数(JSON)" json:"custom_query_params,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;index;comment:创建时间" json:"created_at"` UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"` DeletedAt *time.Time `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"` } // TableName 指定表名 func (PrometheusDataSource) TableName() string { return "monitor_prometheus_datasources" } // ============================================ // 请求/响应 struct // ============================================ // CreatePromDSReq 创建数据源请求 type CreatePromDSReq struct { Name string `json:"name" binding:"required"` URL string `json:"url" binding:"required"` Access string `json:"access"` BasicAuth bool `json:"basic_auth"` BasicAuthUser string `json:"basic_auth_user"` BasicAuthPass string `json:"basic_auth_pass"` WithCredentials bool `json:"with_credentials"` TLSClientAuth bool `json:"tls_client_auth"` WithCACert bool `json:"with_ca_cert"` CACert string `json:"ca_cert"` SkipTLSVerify bool `json:"skip_tls_verify"` CustomHeaders string `json:"custom_headers"` EnableAlerting *bool `json:"enable_alerting"` AlertmanagerDS string `json:"alertmanager_ds"` ScrapeInterval int `json:"scrape_interval"` QueryTimeout int `json:"query_timeout"` HTTPMethod string `json:"http_method"` DisableMetricsLookup bool `json:"disable_metrics_lookup"` CustomQueryParams string `json:"custom_query_params"` IsDefault bool `json:"is_default"` } // UpdatePromDSReq 更新数据源请求 type UpdatePromDSReq struct { Name *string `json:"name"` URL *string `json:"url"` Access *string `json:"access"` BasicAuth *bool `json:"basic_auth"` BasicAuthUser *string `json:"basic_auth_user"` BasicAuthPass *string `json:"basic_auth_pass"` WithCredentials *bool `json:"with_credentials"` TLSClientAuth *bool `json:"tls_client_auth"` WithCACert *bool `json:"with_ca_cert"` CACert *string `json:"ca_cert"` SkipTLSVerify *bool `json:"skip_tls_verify"` CustomHeaders *string `json:"custom_headers"` EnableAlerting *bool `json:"enable_alerting"` AlertmanagerDS *string `json:"alertmanager_ds"` ScrapeInterval *int `json:"scrape_interval"` QueryTimeout *int `json:"query_timeout"` HTTPMethod *string `json:"http_method"` DisableMetricsLookup *bool `json:"disable_metrics_lookup"` CustomQueryParams *string `json:"custom_query_params"` IsDefault *bool `json:"is_default"` Status *int `json:"status"` } // TestPromDSReq 测试数据源连接请求 type TestPromDSReq struct { URL string `json:"url" binding:"required"` BasicAuth bool `json:"basic_auth"` BasicAuthUser string `json:"basic_auth_user"` BasicAuthPass string `json:"basic_auth_pass"` SkipTLSVerify bool `json:"skip_tls_verify"` }