This commit is contained in:
Logan committed 2026-07-09 14:16:56 +08:00
1 parent 0690285147
commit 5618cd2738
154 files changed
+5021 -3161

No files matched your search

+95 -95
View File
@@ -12,14 +12,14 @@ import (
type SiteTaskType string
const (
SiteTaskTypeHTTP SiteTaskType = "http" // HTTP/HTTPS Web 拨测
SiteTaskTypeSSL SiteTaskType = "ssl" // SSL/TLS 证书拨测
SiteTaskTypeTCP SiteTaskType = "tcp" // TCP拨测
SiteTaskTypePing SiteTaskType = "ping" // ICMP Ping拨测
SiteTaskTypeDNS SiteTaskType = "dns" // DNS拨测
SiteTaskTypeUDP SiteTaskType = "udp" // UDP拨测
SiteTaskTypeFTP SiteTaskType = "ftp" // FTP拨测
SiteTaskTypeSMTP SiteTaskType = "smtp" // SMTP拨测
SiteTaskTypeHTTP SiteTaskType = "http" // HTTP/HTTPS Web 拨测
SiteTaskTypeSSL SiteTaskType = "ssl" // SSL/TLS 证书拨测
SiteTaskTypeTCP SiteTaskType = "tcp" // TCP拨测
SiteTaskTypePing SiteTaskType = "ping" // ICMP Ping拨测
SiteTaskTypeDNS SiteTaskType = "dns" // DNS拨测
SiteTaskTypeUDP SiteTaskType = "udp" // UDP拨测
SiteTaskTypeFTP SiteTaskType = "ftp" // FTP拨测
SiteTaskTypeSMTP SiteTaskType = "smtp" // SMTP拨测
SiteTaskTypeTraceroute SiteTaskType = "traceroute" // 路由追踪
)
@@ -27,9 +27,9 @@ const (
type SiteTaskMethod string
const (
SiteTaskMethodGET SiteTaskMethod = "GET"
SiteTaskMethodPOST SiteTaskMethod = "POST"
SiteTaskMethodHEAD SiteTaskMethod = "HEAD"
SiteTaskMethodGET SiteTaskMethod = "GET"
SiteTaskMethodPOST SiteTaskMethod = "POST"
SiteTaskMethodHEAD SiteTaskMethod = "HEAD"
)
// SiteTaskStatus 拨测任务状态
@@ -44,37 +44,37 @@ const (
// SiteTask 站点拨测任务表
// 定义对网站、服务等进行主动拨测的任务配置
type SiteTask struct {
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
Name string `gorm:"type:varchar(128);not null;comment:任务名称" json:"name"`
URL string `gorm:"type:varchar(512);not null;comment:拨测URL/地址" json:"url"`
TaskType SiteTaskType `gorm:"type:varchar(16);not null;comment:拨测类型" json:"task_type"`
Method SiteTaskMethod `gorm:"type:varchar(8);default:'GET';comment:HTTP方法" json:"method"`
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
Name string `gorm:"type:varchar(128);not null;comment:任务名称" json:"name"`
URL string `gorm:"type:varchar(512);not null;comment:拨测URL/地址" json:"url"`
TaskType SiteTaskType `gorm:"type:varchar(16);not null;comment:拨测类型" json:"task_type"`
Method SiteTaskMethod `gorm:"type:varchar(8);default:'GET';comment:HTTP方法" json:"method"`
// HTTP 拨测配置
Headers string `gorm:"type:text;comment:请求头JSON" json:"headers,omitempty"`
Body string `gorm:"type:text;comment:请求体" json:"body,omitempty"`
Timeout int `gorm:"default:10;comment:超时时间(秒)" json:"timeout"`
FollowRedirect bool `gorm:"default:true;comment:是否跟随重定向" json:"follow_redirect"`
VerifySSL bool `gorm:"default:true;comment:是否验证SSL证书" json:"verify_ssl"`
Headers string `gorm:"type:text;comment:请求头JSON" json:"headers,omitempty"`
Body string `gorm:"type:text;comment:请求体" json:"body,omitempty"`
Timeout int `gorm:"default:10;comment:超时时间(秒)" json:"timeout"`
FollowRedirect bool `gorm:"default:true;comment:是否跟随重定向" json:"follow_redirect"`
VerifySSL bool `gorm:"default:true;comment:是否验证SSL证书" json:"verify_ssl"`
// 期望响应配置
ExpectedStatus int `gorm:"default:200;comment:期望状态码" json:"expected_status"`
ExpectedContent string `gorm:"type:text;comment:期望响应内容(支持正则)" json:"expected_content,omitempty"`
ExpectedLength int `gorm:"default:0;comment:期望响应长度(0表示不检查)" json:"expected_length"`
// 执行配置
Frequency int `gorm:"default:60;comment:拨测频率(秒)" json:"frequency"`
Nodes string `gorm:"type:varchar(256);comment:执行节点列表JSON" json:"nodes,omitempty"`
Frequency int `gorm:"default:60;comment:拨测频率(秒)" json:"frequency"`
Nodes string `gorm:"type:varchar(256);comment:执行节点列表JSON" json:"nodes,omitempty"`
// DNS 配置
DNSResolver string `gorm:"type:varchar(64);comment:DNS解析服务器" json:"dns_resolver,omitempty"`
DNSResolver string `gorm:"type:varchar(64);comment:DNS解析服务器" json:"dns_resolver,omitempty"`
// 状态
Status SiteTaskStatus `gorm:"type:varchar(16);default:'running';comment:任务状态" json:"status"`
LastResult string `gorm:"type:varchar(16);comment:最近结果: success/fail" json:"last_result,omitempty"`
LastCheckAt *time.Time `gorm:"comment:最近检查时间" json:"last_check_at,omitempty"`
SuccessRate float64 `gorm:"type:decimal(5,2);default:100.00;comment:成功率(%)" json:"success_rate"`
AvgResponse float64 `gorm:"comment:平均响应时间(ms)" json:"avg_response,omitempty"`
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
CreatedBy uint `gorm:"index;comment:创建人ID" json:"created_by"`
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"`
Status SiteTaskStatus `gorm:"type:varchar(16);default:'running';comment:任务状态" json:"status"`
LastResult string `gorm:"type:varchar(16);comment:最近结果: success/fail" json:"last_result,omitempty"`
LastCheckAt *time.Time `gorm:"comment:最近检查时间" json:"last_check_at,omitempty"`
SuccessRate float64 `gorm:"type:decimal(5,2);default:100.00;comment:成功率(%)" json:"success_rate"`
AvgResponse float64 `gorm:"comment:平均响应时间(ms)" json:"avg_response,omitempty"`
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
CreatedBy uint `gorm:"index;comment:创建人ID" json:"created_by"`
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"`
// 关联关系
Results []SiteResult `gorm:"foreignKey:TaskID" json:"results,omitempty"`
@@ -83,7 +83,7 @@ type SiteTask struct {
// TableName 指定表名
func (SiteTask) TableName() string {
return "ops_site_tasks"
return "monitor_site_tasks"
}
// ============================================
@@ -117,16 +117,16 @@ type SiteResult struct {
ResponseSize int `gorm:"comment:响应大小(bytes)" json:"response_size,omitempty"`
ResponseBody string `gorm:"type:text;comment:响应内容摘要" json:"response_body,omitempty"`
// 网络信息
RemoteIP string `gorm:"type:varchar(64);comment:远端IP" json:"remote_ip,omitempty"`
LocalNode string `gorm:"type:varchar(64);comment:执行节点" json:"local_node,omitempty"`
RemoteIP string `gorm:"type:varchar(64);comment:远端IP" json:"remote_ip,omitempty"`
LocalNode string `gorm:"type:varchar(64);comment:执行节点" json:"local_node,omitempty"`
// 错误信息
ErrorMessage string `gorm:"type:text;comment:错误信息" json:"error_message,omitempty"`
ErrorDetail string `gorm:"type:text;comment:错误详情" json:"error_detail,omitempty"`
// SSL 证书信息
SSLCertExpiry *time.Time `gorm:"comment:SSL证书过期时间" json:"ssl_cert_expiry,omitempty"`
SSLCertIssuer string `gorm:"type:varchar(256);comment:SSL证书签发者" json:"ssl_cert_issuer,omitempty"`
SSLCertSubject string `gorm:"type:varchar(256);comment:SSL证书主题" json:"ssl_cert_subject,omitempty"`
SSLDaysRemaining int `gorm:"comment:SSL证书剩余天数" json:"ssl_days_remaining,omitempty"`
SSLCertExpiry *time.Time `gorm:"comment:SSL证书过期时间" json:"ssl_cert_expiry,omitempty"`
SSLCertIssuer string `gorm:"type:varchar(256);comment:SSL证书签发者" json:"ssl_cert_issuer,omitempty"`
SSLCertSubject string `gorm:"type:varchar(256);comment:SSL证书主题" json:"ssl_cert_subject,omitempty"`
SSLDaysRemaining int `gorm:"comment:SSL证书剩余天数" json:"ssl_days_remaining,omitempty"`
// 检查内容匹配
ContentMatch bool `gorm:"comment:内容匹配结果" json:"content_match,omitempty"`
// 时间戳
@@ -139,7 +139,7 @@ type SiteResult struct {
// TableName 指定表名
func (SiteResult) TableName() string {
return "ops_site_results"
return "monitor_site_results"
}
// ============================================
@@ -167,31 +167,31 @@ const (
// SiteAlert 拨测告警表
// 记录拨测任务触发的告警事件
type SiteAlert struct {
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
TaskID uint `gorm:"not null;index;comment:任务ID" json:"task_id"`
Severity SiteAlertSeverity `gorm:"type:varchar(16);not null;comment:告警级别" json:"severity"`
Status SiteAlertStatus `gorm:"type:varchar(16);default:'active';index;comment:告警状态" json:"status"`
Title string `gorm:"type:varchar(256);not null;comment:告警标题" json:"title"`
Message string `gorm:"type:text;comment:告警详情" json:"message,omitempty"`
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
TaskID uint `gorm:"not null;index;comment:任务ID" json:"task_id"`
Severity SiteAlertSeverity `gorm:"type:varchar(16);not null;comment:告警级别" json:"severity"`
Status SiteAlertStatus `gorm:"type:varchar(16);default:'active';index;comment:告警状态" json:"status"`
Title string `gorm:"type:varchar(256);not null;comment:告警标题" json:"title"`
Message string `gorm:"type:text;comment:告警详情" json:"message,omitempty"`
// 触发条件
TriggerType string `gorm:"type:varchar(32);comment:触发类型: timeout/status_error/response_time/ssl_expiry" json:"trigger_type"`
TriggerValue string `gorm:"type:varchar(128);comment:触发值" json:"trigger_value,omitempty"`
Threshold float64 `gorm:"comment:阈值" json:"threshold,omitempty"`
TriggerType string `gorm:"type:varchar(32);comment:触发类型: timeout/status_error/response_time/ssl_expiry" json:"trigger_type"`
TriggerValue string `gorm:"type:varchar(128);comment:触发值" json:"trigger_value,omitempty"`
Threshold float64 `gorm:"comment:阈值" json:"threshold,omitempty"`
// 响应信息
ResponseTime float64 `gorm:"comment:响应时间(ms)" json:"response_time,omitempty"`
HTTPStatus int `gorm:"comment:HTTP状态码" json:"http_status,omitempty"`
ErrorMessage string `gorm:"type:text;comment:错误信息" json:"error_message,omitempty"`
ResponseTime float64 `gorm:"comment:响应时间(ms)" json:"response_time,omitempty"`
HTTPStatus int `gorm:"comment:HTTP状态码" json:"http_status,omitempty"`
ErrorMessage string `gorm:"type:text;comment:错误信息" json:"error_message,omitempty"`
// 状态变化
StartedAt time.Time `gorm:"not null;comment:告警开始时间" json:"started_at"`
ResolvedAt *time.Time `gorm:"comment:告警恢复时间" json:"resolved_at,omitempty"`
Duration int `gorm:"comment:持续时间(秒)" json:"duration,omitempty"`
NotifyCount int `gorm:"default:0;comment:通知次数" json:"notify_count"`
LastNotifyAt *time.Time `gorm:"comment:最近通知时间" json:"last_notify_at,omitempty"`
Acknowledged bool `gorm:"default:false;comment:是否已确认" json:"acknowledged"`
AcknowledgedBy uint `gorm:"comment:确认人ID" json:"acknowledged_by,omitempty"`
AcknowledgedAt *time.Time `gorm:"comment:确认时间" json:"acknowledged_at,omitempty"`
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
StartedAt time.Time `gorm:"not null;comment:告警开始时间" json:"started_at"`
ResolvedAt *time.Time `gorm:"comment:告警恢复时间" json:"resolved_at,omitempty"`
Duration int `gorm:"comment:持续时间(秒)" json:"duration,omitempty"`
NotifyCount int `gorm:"default:0;comment:通知次数" json:"notify_count"`
LastNotifyAt *time.Time `gorm:"comment:最近通知时间" json:"last_notify_at,omitempty"`
Acknowledged bool `gorm:"default:false;comment:是否已确认" json:"acknowledged"`
AcknowledgedBy uint `gorm:"comment:确认人ID" json:"acknowledged_by,omitempty"`
AcknowledgedAt *time.Time `gorm:"comment:确认时间" json:"acknowledged_at,omitempty"`
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
// 关联关系
Task *SiteTask `gorm:"foreignKey:TaskID" json:"task,omitempty"`
@@ -199,45 +199,45 @@ type SiteAlert struct {
// TableName 指定表名
func (SiteAlert) TableName() string {
return "ops_site_alerts"
return "monitor_site_alerts"
}
// SiteTaskCreateRequest 拨测任务创建请求
type SiteTaskCreateRequest struct {
Name string `json:"name" binding:"required,max=128"`
URL string `json:"url" binding:"required,max=512,url"`
TaskType SiteTaskType `json:"task_type" binding:"required"`
Method SiteTaskMethod `json:"method"`
Headers string `json:"headers"`
Body string `json:"body"`
Timeout int `json:"timeout"`
FollowRedirect bool `json:"follow_redirect"`
VerifySSL bool `json:"verify_ssl"`
ExpectedStatus int `json:"expected_status"`
ExpectedContent string `json:"expected_content"`
ExpectedLength int `json:"expected_length"`
Frequency int `json:"frequency"`
Nodes []string `json:"nodes"`
DNSResolver string `json:"dns_resolver"`
Description string `json:"description"`
Name string `json:"name" binding:"required,max=128"`
URL string `json:"url" binding:"required,max=512,url"`
TaskType SiteTaskType `json:"task_type" binding:"required"`
Method SiteTaskMethod `json:"method"`
Headers string `json:"headers"`
Body string `json:"body"`
Timeout int `json:"timeout"`
FollowRedirect bool `json:"follow_redirect"`
VerifySSL bool `json:"verify_ssl"`
ExpectedStatus int `json:"expected_status"`
ExpectedContent string `json:"expected_content"`
ExpectedLength int `json:"expected_length"`
Frequency int `json:"frequency"`
Nodes []string `json:"nodes"`
DNSResolver string `json:"dns_resolver"`
Description string `json:"description"`
}
// SiteTaskUpdateRequest 拨测任务更新请求
type SiteTaskUpdateRequest struct {
Name string `json:"name" binding:"max=128"`
URL string `json:"url" binding:"max=512,url"`
Method SiteTaskMethod `json:"method"`
Headers string `json:"headers"`
Body string `json:"body"`
Timeout int `json:"timeout"`
FollowRedirect bool `json:"follow_redirect"`
VerifySSL bool `json:"verify_ssl"`
ExpectedStatus int `json:"expected_status"`
ExpectedContent string `json:"expected_content"`
Frequency int `json:"frequency"`
Nodes []string `json:"nodes"`
Status SiteTaskStatus `json:"status"`
Description string `json:"description"`
Name string `json:"name" binding:"max=128"`
URL string `json:"url" binding:"max=512,url"`
Method SiteTaskMethod `json:"method"`
Headers string `json:"headers"`
Body string `json:"body"`
Timeout int `json:"timeout"`
FollowRedirect bool `json:"follow_redirect"`
VerifySSL bool `json:"verify_ssl"`
ExpectedStatus int `json:"expected_status"`
ExpectedContent string `json:"expected_content"`
Frequency int `json:"frequency"`
Nodes []string `json:"nodes"`
Status SiteTaskStatus `json:"status"`
Description string `json:"description"`
}
// SiteTaskStatistics 拨测任务统计