feat: Zabbix 数据源管理 — 完整 CRUD + 双 Tab 数据源页面
后端: - models/zabbix_datasource.go: Zabbix 数据源 model (15字段, 参照 Grafana) - handlers/zabbix_datasource.go: CRUD + 测试连接 (调用 Zabbix API Auth) - routes.go: /zabbix-datasources 路由组 - database.go: AutoMigrate 前端: - api.ts: zabbixDatasourceApi - ZabbixDatasourceManager.tsx: 表单 (URL/用户名/密码/Trends设置/DB直连) - DatasourcePage.tsx: Prometheus + Zabbix 双 Tab 包装 - App.tsx: /datasources 路由更新
This commit is contained in:
1 parent
d2201fc8c0
commit
c51d0b8b8b
8 files changed
+761
-2
No files matched your search
@@ -0,0 +1,82 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
// ZabbixDataSource Zabbix 数据源配置(参考 Grafana 界面设计) // Logan.Li
|
||||
type ZabbixDataSource 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:Zabbix API地址" json:"url"`
|
||||
Username string `gorm:"type:varchar(128);not null;comment:用户名" json:"username"`
|
||||
Password string `gorm:"type:varchar(256);not null;comment:密码" json:"password,omitempty"`
|
||||
|
||||
// Trends 设置
|
||||
TrendsAfter int `gorm:"default:0;comment:趋势数据起始时间(天前)" json:"trends_after"`
|
||||
TrendsRange int `gorm:"default:0;comment:趋势数据范围(秒)" json:"trends_range"`
|
||||
TrendsCacheTTL int `gorm:"default:3600;comment:趋势缓存TTL(秒)" json:"trends_cache_ttl"`
|
||||
TrendsTimeout int `gorm:"default:30;comment:趋势查询超时(秒)" json:"trends_timeout"`
|
||||
|
||||
// Direct DB Connection
|
||||
DirectDB bool `gorm:"default:false;comment:启用直连数据库" json:"direct_db"`
|
||||
|
||||
// Other
|
||||
DisableAcknowledges bool `gorm:"default:false;comment:只读用户禁用确认" json:"disable_acknowledges"`
|
||||
DisableDataAlignment bool `gorm:"default:false;comment:禁用数据对齐" json:"disable_data_alignment"`
|
||||
|
||||
// 状态
|
||||
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 (ZabbixDataSource) TableName() string {
|
||||
return "zabbix_datasources"
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// 请求/响应 struct
|
||||
// ============================================
|
||||
|
||||
// CreateZabbixDSReq 创建 Zabbix 数据源请求
|
||||
type CreateZabbixDSReq struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
URL string `json:"url" binding:"required"`
|
||||
Username string `json:"username" binding:"required"`
|
||||
Password string `json:"password" binding:"required"`
|
||||
TrendsAfter int `json:"trends_after"`
|
||||
TrendsRange int `json:"trends_range"`
|
||||
TrendsCacheTTL int `json:"trends_cache_ttl"`
|
||||
TrendsTimeout int `json:"trends_timeout"`
|
||||
DirectDB bool `json:"direct_db"`
|
||||
DisableAcknowledges bool `json:"disable_acknowledges"`
|
||||
DisableDataAlignment bool `json:"disable_data_alignment"`
|
||||
IsDefault bool `json:"is_default"`
|
||||
}
|
||||
|
||||
// UpdateZabbixDSReq 更新 Zabbix 数据源请求
|
||||
type UpdateZabbixDSReq struct {
|
||||
Name *string `json:"name"`
|
||||
URL *string `json:"url"`
|
||||
Username *string `json:"username"`
|
||||
Password *string `json:"password"`
|
||||
TrendsAfter *int `json:"trends_after"`
|
||||
TrendsRange *int `json:"trends_range"`
|
||||
TrendsCacheTTL *int `json:"trends_cache_ttl"`
|
||||
TrendsTimeout *int `json:"trends_timeout"`
|
||||
DirectDB *bool `json:"direct_db"`
|
||||
DisableAcknowledges *bool `json:"disable_acknowledges"`
|
||||
DisableDataAlignment *bool `json:"disable_data_alignment"`
|
||||
IsDefault *bool `json:"is_default"`
|
||||
Status *int `json:"status"`
|
||||
}
|
||||
|
||||
// TestZabbixDSReq 测试 Zabbix 连接请求
|
||||
type TestZabbixDSReq struct {
|
||||
URL string `json:"url" binding:"required"`
|
||||
Username string `json:"username" binding:"required"`
|
||||
Password string `json:"password" binding:"required"`
|
||||
}
|
||||
Reference in new issue
Block a user