models

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent struct {
	ID         string                      `gorm:"primaryKey" json:"id"`                  // 探针ID (UUID)
	Name       string                      `gorm:"index" json:"name"`                     // 探针名称
	Hostname   string                      `gorm:"index" json:"hostname,omitempty"`       // 主机名
	IP         string                      `gorm:"index" json:"ip,omitempty"`             // IP地址
	OS         string                      `json:"os"`                                    // 操作系统
	Arch       string                      `json:"arch"`                                  // 架构
	Version    string                      `json:"version"`                               // 探针版本
	Tags       datatypes.JSONSlice[string] `json:"tags"`                                  // 标签
	ExpireTime int64                       `json:"expireTime"`                            // 到期时间(时间戳毫秒)
	Status     int                         `json:"status"`                                // 状态: 0-离线, 1-在线
	Visibility string                      `gorm:"default:public" json:"visibility"`      // 可见性: public-匿名可见, private-登录可见
	LastSeenAt int64                       `gorm:"index" json:"lastSeenAt"`               // 最后上线时间(时间戳毫秒)
	CreatedAt  int64                       `json:"createdAt"`                             // 创建时间(时间戳毫秒)
	UpdatedAt  int64                       `json:"updatedAt" gorm:"autoUpdateTime:milli"` // 更新时间(时间戳毫秒)

	// 流量统计相关字段
	TrafficLimit        uint64 `json:"trafficLimit"`        // 流量限额(字节), 0表示不限制
	TrafficUsed         uint64 `json:"trafficUsed"`         // 当前周期已使用流量(字节)
	TrafficResetDay     int    `json:"trafficResetDay"`     // 流量重置日期(1-31), 0表示不自动重置
	TrafficPeriodStart  int64  `json:"trafficPeriodStart"`  // 当前周期开始时间(时间戳毫秒)
	TrafficBaselineRecv uint64 `json:"trafficBaselineRecv"` // 当前周期流量基线(BytesRecvTotal)
	TrafficAlertSent80  bool   `json:"trafficAlertSent80"`  // 是否已发送80%告警
	TrafficAlertSent90  bool   `json:"trafficAlertSent90"`  // 是否已发送90%告警
	TrafficAlertSent100 bool   `json:"trafficAlertSent100"` // 是否已发送100%告警
}

Agent 探针信息

func (Agent) TableName

func (Agent) TableName() string

type AlertConfig

type AlertConfig struct {
	Enabled bool       `json:"enabled"` // 是否启用全局告警
	MaskIP  bool       `json:"maskIP"`  // 是否在通知中打码 IP 地址
	Rules   AlertRules `json:"rules"`   // 告警规则
}

AlertConfig 全局告警配置

type AlertRecord

type AlertRecord struct {
	ID          int64   `gorm:"primaryKey;autoIncrement" json:"id"`    // 记录ID
	AgentID     string  `gorm:"index" json:"agentId"`                  // 探针ID
	AgentName   string  `json:"agentName"`                             // 探针名称
	AlertType   string  `json:"alertType"`                             // 告警类型: cpu, memory, disk, network
	Message     string  `json:"message"`                               // 告警消息
	Threshold   float64 `json:"threshold"`                             // 告警阈值
	ActualValue float64 `json:"actualValue"`                           // 实际值
	Level       string  `json:"level"`                                 // 告警级别: info, warning, critical
	Status      string  `json:"status"`                                // 状态: firing(告警中), resolved(已恢复)
	FiredAt     int64   `gorm:"index" json:"firedAt"`                  // 触发时间(时间戳毫秒)
	ResolvedAt  int64   `json:"resolvedAt,omitempty"`                  // 恢复时间(时间戳毫秒)
	CreatedAt   int64   `json:"createdAt"`                             // 创建时间(时间戳毫秒)
	UpdatedAt   int64   `json:"updatedAt" gorm:"autoUpdateTime:milli"` // 更新时间(时间戳毫秒)
}

AlertRecord 告警记录

func (AlertRecord) TableName

func (AlertRecord) TableName() string

type AlertRules

type AlertRules struct {
	// CPU 告警配置
	CPUEnabled   bool    `json:"cpuEnabled"`   // 是否启用CPU告警
	CPUThreshold float64 `json:"cpuThreshold"` // CPU使用率阈值(0-100)
	CPUDuration  int     `json:"cpuDuration"`  // 持续时间(秒)

	// 内存告警配置
	MemoryEnabled   bool    `json:"memoryEnabled"`   // 是否启用内存告警
	MemoryThreshold float64 `json:"memoryThreshold"` // 内存使用率阈值(0-100)
	MemoryDuration  int     `json:"memoryDuration"`  // 持续时间(秒)

	// 磁盘告警配置
	DiskEnabled   bool    `json:"diskEnabled"`   // 是否启用磁盘告警
	DiskThreshold float64 `json:"diskThreshold"` // 磁盘使用率阈值(0-100)
	DiskDuration  int     `json:"diskDuration"`  // 持续时间(秒)

	// 网络告警配置
	NetworkEnabled   bool    `json:"networkEnabled"`   // 是否启用网络告警
	NetworkThreshold float64 `json:"networkThreshold"` // 网速阈值(MB/s)
	NetworkDuration  int     `json:"networkDuration"`  // 持续时间(秒)

	// HTTPS 证书告警配置
	CertEnabled   bool    `json:"certEnabled"`   // 是否启用证书告警
	CertThreshold float64 `json:"certThreshold"` // 证书剩余天数阈值

	// 服务下线告警配置
	ServiceEnabled  bool `json:"serviceEnabled"`  // 是否启用服务下线告警
	ServiceDuration int  `json:"serviceDuration"` // 持续时间(秒)

	// 探针离线告警配置
	AgentOfflineEnabled  bool `json:"agentOfflineEnabled"`  // 是否启用探针离线告警
	AgentOfflineDuration int  `json:"agentOfflineDuration"` // 持续时间(秒)
}

AlertRules 告警规则

type AlertState

type AlertState struct {
	ID            string  `gorm:"primaryKey" json:"id"`                  // 状态ID(格式:agentId:configId:alertType)
	AgentID       string  `gorm:"index" json:"agentId"`                  // 探针ID
	AlertType     string  `gorm:"index" json:"alertType"`                // 告警类型
	Value         float64 `json:"value"`                                 // 当前值
	Threshold     float64 `json:"threshold"`                             // 阈值
	StartTime     int64   `json:"startTime"`                             // 开始超过阈值的时间
	Duration      int     `json:"duration"`                              // 需要持续的时间(秒)
	LastCheckTime int64   `json:"lastCheckTime"`                         // 上次检查时间
	IsFiring      bool    `json:"isFiring"`                              // 是否正在告警
	LastRecordID  int64   `json:"lastRecordId"`                          // 最后一条告警记录ID
	CreatedAt     int64   `json:"createdAt"`                             // 创建时间(时间戳毫秒)
	UpdatedAt     int64   `json:"updatedAt" gorm:"autoUpdateTime:milli"` // 更新时间(时间戳毫秒)
}

AlertState 告警状态(持久化到数据库,用于判断是否持续超过阈值)

func (AlertState) TableName

func (AlertState) TableName() string

type ApiKey

type ApiKey struct {
	ID        string `gorm:"primaryKey" json:"id"`                  // 密钥ID (UUID)
	Name      string `gorm:"index" json:"name"`                     // 密钥名称/备注
	Key       string `gorm:"uniqueIndex" json:"key"`                // API密钥
	Enabled   bool   `gorm:"index;default:true" json:"enabled"`     // 是否启用
	CreatedBy string `gorm:"index" json:"createdBy"`                // 创建人ID
	CreatedAt int64  `json:"createdAt"`                             // 创建时间(时间戳毫秒)
	UpdatedAt int64  `json:"updatedAt" gorm:"autoUpdateTime:milli"` // 更新时间(时间戳毫秒)
}

ApiKey API密钥信息

func (ApiKey) TableName

func (ApiKey) TableName() string

type AuditResult

type AuditResult struct {
	ID        int64  `gorm:"primaryKey;autoIncrement" json:"id"`
	AgentID   string `gorm:"type:varchar(64);not null;index" json:"agentId"`
	Type      string `gorm:"type:varchar(32);not null" json:"type"` // vps_audit
	Result    string `gorm:"type:text;not null" json:"result"`      // JSON格式的审计结果
	StartTime int64  `gorm:"not null" json:"startTime"`
	EndTime   int64  `gorm:"not null" json:"endTime"`
	CreatedAt int64  `gorm:"not null" json:"createdAt"`
}

AuditResult 审计结果模型

func (AuditResult) TableName

func (AuditResult) TableName() string

TableName 表名

type DDNSConfig

type DDNSConfig struct {
	ID       string `gorm:"primaryKey" json:"id"`        // 配置ID (UUID)
	AgentID  string `gorm:"index" json:"agentId"`        // 探针ID
	Name     string `json:"name"`                        // 配置名称
	Enabled  bool   `gorm:"default:true" json:"enabled"` // 是否启用
	Provider string `gorm:"index" json:"provider"`       // DNS服务商类型: aliyun, tencentcloud, cloudflare, huaweicloud

	// 域名配置(IPv4 和 IPv6 分开)
	DomainsIPv4 datatypes.JSONSlice[string] `json:"domainsIpv4"` // IPv4 域名列表
	DomainsIPv6 datatypes.JSONSlice[string] `json:"domainsIpv6"` // IPv6 域名列表

	// IP 获取配置
	EnableIPv4    bool   `gorm:"default:true" json:"enableIpv4"`  // 是否启用 IPv4
	EnableIPv6    bool   `gorm:"default:false" json:"enableIpv6"` // 是否启用 IPv6
	IPv4GetMethod string `json:"ipv4GetMethod"`                   // IPv4 获取方式: api, interface
	IPv6GetMethod string `json:"ipv6GetMethod"`                   // IPv6 获取方式: api, interface
	IPv4GetValue  string `json:"ipv4GetValue,omitempty"`          // IPv4 获取配置值(接口名/API URL)
	IPv6GetValue  string `json:"ipv6GetValue,omitempty"`          // IPv6 获取配置值(接口名/API URL)

	CreatedAt int64 `json:"createdAt"`                             // 创建时间(时间戳毫秒)
	UpdatedAt int64 `json:"updatedAt" gorm:"autoUpdateTime:milli"` // 更新时间(时间戳毫秒)
}

DDNSConfig DDNS 配置

func (DDNSConfig) TableName

func (DDNSConfig) TableName() string

type DDNSRecord

type DDNSRecord struct {
	ID           string `gorm:"primaryKey" json:"id"`   // 记录ID
	ConfigID     string `gorm:"index" json:"configId"`  // 配置ID
	AgentID      string `gorm:"index" json:"agentId"`   // 探针ID
	Domain       string `gorm:"index" json:"domain"`    // 域名
	RecordType   string `json:"recordType"`             // 记录类型: A, AAAA
	OldIP        string `json:"oldIp,omitempty"`        // 旧IP
	NewIP        string `json:"newIp"`                  // 新IP
	Status       string `json:"status"`                 // 更新状态: success, failed
	ErrorMessage string `json:"errorMessage,omitempty"` // 错误信息
	CreatedAt    int64  `gorm:"index" json:"createdAt"` // 创建时间(时间戳毫秒)
}

DDNSRecord DDNS 更新记录

func (DDNSRecord) TableName

func (DDNSRecord) TableName() string

type DNSProviderConfig

type DNSProviderConfig struct {
	Provider string                 `json:"provider"` // 服务商类型: aliyun, tencentcloud, cloudflare, huaweicloud
	Enabled  bool                   `json:"enabled"`  // 是否启用
	Config   map[string]interface{} `json:"config"`   // 配置对象(敏感信息)
}

DNSProviderConfig DNS 服务商配置(存储在 Property 中)

type HostMetric

type HostMetric struct {
	ID              uint   `gorm:"primaryKey;autoIncrement" json:"id"`
	AgentID         string `gorm:"uniqueIndex:ux_host_agent" json:"agentId"` // 探针ID(唯一约束用于 upsert)
	OS              string `json:"os"`                                       // 操作系统
	Platform        string `json:"platform"`                                 // 平台
	PlatformVersion string `json:"platformVersion"`                          // 平台版本
	KernelVersion   string `json:"kernelVersion"`                            // 内核版本
	KernelArch      string `json:"kernelArch"`                               // 内核架构
	Uptime          uint64 `json:"uptime"`                                   // 运行时间(秒)
	BootTime        uint64 `json:"bootTime"`                                 // 启动时间(Unix时间戳-秒)
	Procs           uint64 `json:"procs"`                                    // 进程数
	Timestamp       int64  `gorm:"index:idx_host_ts" json:"timestamp"`       // 时间戳(毫秒)
}

HostMetric 主机信息指标(静态信息,保存在 PostgreSQL)

func (HostMetric) TableName

func (HostMetric) TableName() string

type MonitorTask

type MonitorTask struct {
	ID               string                                         `gorm:"primaryKey" json:"id"`                  // 任务 ID
	Name             string                                         `gorm:"uniqueIndex" json:"name"`               // 任务名称
	Type             string                                         `gorm:"index" json:"type"`                     // 监控类型 http/tcp
	Target           string                                         `json:"target"`                                // 目标地址
	Description      string                                         `json:"description"`                           // 描述信息
	Enabled          bool                                           `json:"enabled"`                               // 是否启用
	ShowTargetPublic bool                                           `json:"showTargetPublic"`                      // 在公开页面是否显示目标地址
	Visibility       string                                         `gorm:"default:public" json:"visibility"`      // 可见性: public-匿名可见, private-登录可见
	Interval         int                                            `json:"interval"`                              // 检测频率(秒),默认 60
	AgentIds         datatypes.JSONSlice[string]                    `json:"agentIds"`                              // 指定的探针 ID 列表(JSON 数组)
	AgentNames       []string                                       `gorm:"-" json:"agentNames"`                   // 指定的探针名称列表
	HTTPConfig       datatypes.JSONType[protocol.HTTPMonitorConfig] `json:"httpConfig"`                            // HTTP 监控配置
	TCPConfig        datatypes.JSONType[protocol.TCPMonitorConfig]  `json:"tcpConfig"`                             // TCP 监控配置
	ICMPConfig       datatypes.JSONType[protocol.ICMPMonitorConfig] `json:"icmpConfig"`                            // ICMP 监控配置
	CreatedAt        int64                                          `gorm:"autoCreateTime:milli" json:"createdAt"` // 创建时间
	UpdatedAt        int64                                          `gorm:"autoUpdateTime:milli" json:"updatedAt"` // 更新时间
}

MonitorTask 描述一个服务监控任务

func (MonitorTask) TableName

func (MonitorTask) TableName() string

type NotificationChannelConfig

type NotificationChannelConfig struct {
	Type    string                 `json:"type"`    // 类型: dingtalk, wecom, feishu, webhook
	Enabled bool                   `json:"enabled"` // 是否启用
	Config  map[string]interface{} `json:"config"`  // 配置对象
}

NotificationChannelConfig 通知渠道配置(存储在 Property 中)

type Property

type Property struct {
	ID        string `gorm:"primaryKey" json:"id"`                  // 属性ID (如: notification_channels)
	Name      string `json:"name"`                                  // 可读名称
	Value     string `json:"value" gorm:"type:text"`                // JSON配置
	CreatedAt int64  `json:"createdAt"`                             // 创建时间(时间戳毫秒)
	UpdatedAt int64  `json:"updatedAt" gorm:"autoUpdateTime:milli"` // 更新时间(时间戳毫秒)
}

Property 通用属性配置表

func (Property) TableName

func (Property) TableName() string

type SystemConfig

type SystemConfig struct {
	SystemNameZh string `json:"systemNameZh"` // 系统名称(中文)
	SystemNameEn string `json:"systemNameEn"` // 系统名称(英文)
	LogoBase64   string `json:"logoBase64"`   // 系统logo(base64编码)
	ICPCode      string `json:"icpCode"`      // ICP备案号
	DefaultView  string `json:"defaultView"`  // 默认视图 grid | list
	CustomCSS    string `json:"customCSS"`    // 自定义 CSS
	CustomJS     string `json:"customJS"`     // 自定义 JS
	Version      string `json:"-"`            // 系统版本
}

type TamperAlert

type TamperAlert struct {
	ID        string `gorm:"primaryKey" json:"id"`          // 告警ID (UUID)
	AgentID   string `gorm:"index;not null" json:"agentId"` // 探针ID
	Path      string `gorm:"index" json:"path"`             // 被篡改的路径
	Details   string `json:"details"`                       // 详细信息
	Restored  bool   `json:"restored"`                      // 是否已自动恢复
	Timestamp int64  `gorm:"index" json:"timestamp"`        // 检测时间(时间戳毫秒)
	CreatedAt int64  `json:"createdAt"`                     // 记录创建时间(时间戳毫秒)
}

TamperAlert 防篡改属性告警

func (TamperAlert) TableName

func (TamperAlert) TableName() string

type TamperEvent

type TamperEvent struct {
	ID        string `gorm:"primaryKey" json:"id"`          // 事件ID (UUID)
	AgentID   string `gorm:"index;not null" json:"agentId"` // 探针ID
	Path      string `gorm:"index" json:"path"`             // 被修改的路径
	Operation string `json:"operation"`                     // 操作类型: write, remove, rename, chmod, create
	Details   string `json:"details"`                       // 详细信息
	Timestamp int64  `gorm:"index" json:"timestamp"`        // 事件时间(时间戳毫秒)
	CreatedAt int64  `json:"createdAt"`                     // 记录创建时间(时间戳毫秒)
}

TamperEvent 防篡改事件

func (TamperEvent) TableName

func (TamperEvent) TableName() string

type TamperProtectConfig

type TamperProtectConfig struct {
	ID        string                      `gorm:"primaryKey" json:"id"`                  // 配置ID (UUID)
	AgentID   string                      `gorm:"index;not null" json:"agentId"`         // 探针ID
	Paths     datatypes.JSONSlice[string] `json:"paths"`                                 // 受保护的目录列表
	CreatedAt int64                       `json:"createdAt"`                             // 创建时间(时间戳毫秒)
	UpdatedAt int64                       `json:"updatedAt" gorm:"autoUpdateTime:milli"` // 更新时间(时间戳毫秒)
}

TamperProtectConfig 防篡改保护配置

func (TamperProtectConfig) TableName

func (TamperProtectConfig) TableName() string

type WebhookConfig

type WebhookConfig struct {
	URL          string            `json:"url"`                    // Webhook URL
	Method       string            `json:"method,omitempty"`       // 请求方法,默认 POST
	Headers      map[string]string `json:"headers,omitempty"`      // 自定义请求头
	BodyTemplate string            `json:"bodyTemplate,omitempty"` // 请求体模板:json, form, custom
	CustomBody   string            `json:"customBody,omitempty"`   // 自定义请求体模板(支持变量)
}

WebhookConfig 自定义 Webhook 配置结构

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL