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

+66 -66
View File
@@ -30,9 +30,9 @@ const (
type SNMPPrivProtocol string
const (
SNMPPrivDES SNMPPrivProtocol = "DES" // DES加密
SNMPPrivAES SNMPPrivProtocol = "AES" // AES加密
SNMPPrivAES256 SNMPPrivProtocol = "AES256" // AES256加密
SNMPPrivDES SNMPPrivProtocol = "DES" // DES加密
SNMPPrivAES SNMPPrivProtocol = "AES" // AES加密
SNMPPrivAES256 SNMPPrivProtocol = "AES256" // AES256加密
)
// SNMPDeviceStatus SNMP设备状态
@@ -47,43 +47,43 @@ const (
// SNMPDevice SNMP设备表
// 存储通过SNMP协议监控的网络设备信息
type SNMPDevice struct {
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
Name string `gorm:"type:varchar(128);not null;comment:设备名称" json:"name"`
IP string `gorm:"type:varchar(64);not null;index;comment:设备IP地址" json:"ip"`
Port int `gorm:"default:161;comment:SNMP端口" json:"port"`
Version SNMPVersion `gorm:"type:varchar(4);default:'v2c';comment:SNMP版本: v1/v2c/v3" json:"version"`
Community string `gorm:"type:varchar(64);comment:共同体字符串(v1/v2c)" json:"community,omitempty"`
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
Name string `gorm:"type:varchar(128);not null;comment:设备名称" json:"name"`
IP string `gorm:"type:varchar(64);not null;index;comment:设备IP地址" json:"ip"`
Port int `gorm:"default:161;comment:SNMP端口" json:"port"`
Version SNMPVersion `gorm:"type:varchar(4);default:'v2c';comment:SNMP版本: v1/v2c/v3" json:"version"`
Community string `gorm:"type:varchar(64);comment:共同体字符串(v1/v2c)" json:"community,omitempty"`
// SNMP v3 安全参数
Username string `gorm:"type:varchar(64);comment:v3用户名" json:"username,omitempty"`
AuthProtocol SNMPAuthProtocol `gorm:"type:varchar(16);comment:v3认证协议" json:"auth_protocol,omitempty"`
AuthPassword string `gorm:"type:varchar(128);comment:v3认证密码" json:"auth_password,omitempty"`
PrivProtocol SNMPPrivProtocol `gorm:"type:varchar(16);comment:v3加密协议" json:"priv_protocol,omitempty"`
PrivPassword string `gorm:"type:varchar(128);comment:v3加密密码" json:"priv_password,omitempty"`
SecurityLevel string `gorm:"type:varchar(16);comment:v3安全级别: noAuthNoPriv/authNoPriv/authPriv" json:"security_level,omitempty"`
Username string `gorm:"type:varchar(64);comment:v3用户名" json:"username,omitempty"`
AuthProtocol SNMPAuthProtocol `gorm:"type:varchar(16);comment:v3认证协议" json:"auth_protocol,omitempty"`
AuthPassword string `gorm:"type:varchar(128);comment:v3认证密码" json:"auth_password,omitempty"`
PrivProtocol SNMPPrivProtocol `gorm:"type:varchar(16);comment:v3加密协议" json:"priv_protocol,omitempty"`
PrivPassword string `gorm:"type:varchar(128);comment:v3加密密码" json:"priv_password,omitempty"`
SecurityLevel string `gorm:"type:varchar(16);comment:v3安全级别: noAuthNoPriv/authNoPriv/authPriv" json:"security_level,omitempty"`
// 设备信息
DeviceType string `gorm:"type:varchar(64);comment:设备类型: switch/router/firewall/printer/server" json:"device_type"`
Vendor string `gorm:"type:varchar(64);comment:厂商" json:"vendor,omitempty"`
Model string `gorm:"type:varchar(64);comment:型号" json:"model,omitempty"`
SysDescr string `gorm:"type:text;comment:系统描述" json:"sys_descr,omitempty"`
SysObjectID string `gorm:"type:varchar(128);comment:系统OID" json:"sys_object_id,omitempty"`
SysUptime uint64 `gorm:"comment:系统运行时间(百分之一秒)" json:"sys_uptime,omitempty"`
SysContact string `gorm:"type:varchar(128);comment:系统联系人" json:"sys_contact,omitempty"`
SysName string `gorm:"type:varchar(128);comment:系统名称" json:"sys_name,omitempty"`
SysLocation string `gorm:"type:varchar(128);comment:系统位置" json:"sys_location,omitempty"`
DeviceType string `gorm:"type:varchar(64);comment:设备类型: switch/router/firewall/printer/server" json:"device_type"`
Vendor string `gorm:"type:varchar(64);comment:厂商" json:"vendor,omitempty"`
Model string `gorm:"type:varchar(64);comment:型号" json:"model,omitempty"`
SysDescr string `gorm:"type:text;comment:系统描述" json:"sys_descr,omitempty"`
SysObjectID string `gorm:"type:varchar(128);comment:系统OID" json:"sys_object_id,omitempty"`
SysUptime uint64 `gorm:"comment:系统运行时间(百分之一秒)" json:"sys_uptime,omitempty"`
SysContact string `gorm:"type:varchar(128);comment:系统联系人" json:"sys_contact,omitempty"`
SysName string `gorm:"type:varchar(128);comment:系统名称" json:"sys_name,omitempty"`
SysLocation string `gorm:"type:varchar(128);comment:系统位置" json:"sys_location,omitempty"`
// 采集配置
TemplateID uint `gorm:"index;comment:OID模板ID" json:"template_id,omitempty"`
CollectInterval int `gorm:"default:300;comment:采集间隔(秒)" json:"collect_interval"`
Timeout int `gorm:"default:10;comment:超时时间(秒)" json:"timeout"`
Retries int `gorm:"default:3;comment:重试次数" json:"retries"`
MaxRepetitions uint32 `gorm:"default:25;comment:BulkWalk最大重复数" json:"max_repetitions"`
TemplateID uint `gorm:"index;comment:OID模板ID" json:"template_id,omitempty"`
CollectInterval int `gorm:"default:300;comment:采集间隔(秒)" json:"collect_interval"`
Timeout int `gorm:"default:10;comment:超时时间(秒)" json:"timeout"`
Retries int `gorm:"default:3;comment:重试次数" json:"retries"`
MaxRepetitions uint32 `gorm:"default:25;comment:BulkWalk最大重复数" json:"max_repetitions"`
// 状态
Status SNMPDeviceStatus `gorm:"type:varchar(16);default:'offline';index;comment:状态" json:"status"`
LastCollectAt *time.Time `gorm:"comment:最后采集时间" json:"last_collect_at,omitempty"`
LastError string `gorm:"type:text;comment:最后错误信息" json:"last_error,omitempty"`
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
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 SNMPDeviceStatus `gorm:"type:varchar(16);default:'offline';index;comment:状态" json:"status"`
LastCollectAt *time.Time `gorm:"comment:最后采集时间" json:"last_collect_at,omitempty"`
LastError string `gorm:"type:text;comment:最后错误信息" json:"last_error,omitempty"`
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
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"`
// 关联关系
Template *SNMPTemplate `gorm:"foreignKey:TemplateID" json:"template,omitempty"`
@@ -92,7 +92,7 @@ type SNMPDevice struct {
// TableName 指定表名
func (SNMPDevice) TableName() string {
return "ops_snmp_devices"
return "monitor_snmp_devices"
}
// ============================================
@@ -102,16 +102,16 @@ func (SNMPDevice) TableName() string {
// SNMPTemplate OID模板表
// 预定义的OID模板,用于快速配置同类设备的监控
type SNMPTemplate struct {
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
Name string `gorm:"type:varchar(128);not null;comment:模板名称" json:"name"`
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
DeviceType string `gorm:"type:varchar(64);comment:适用设备类型" json:"device_type,omitempty"`
Vendor string `gorm:"type:varchar(64);comment:适用厂商" json:"vendor,omitempty"`
IsDefault bool `gorm:"default:false;comment:是否默认模板" json:"is_default"`
IsSystem bool `gorm:"default:false;comment:是否系统模板" json:"is_system"`
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"`
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
Name string `gorm:"type:varchar(128);not null;comment:模板名称" json:"name"`
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
DeviceType string `gorm:"type:varchar(64);comment:适用设备类型" json:"device_type,omitempty"`
Vendor string `gorm:"type:varchar(64);comment:适用厂商" json:"vendor,omitempty"`
IsDefault bool `gorm:"default:false;comment:是否默认模板" json:"is_default"`
IsSystem bool `gorm:"default:false;comment:是否系统模板" json:"is_system"`
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"`
// 关联关系
@@ -120,7 +120,7 @@ type SNMPTemplate struct {
// TableName 指定表名
func (SNMPTemplate) TableName() string {
return "ops_snmp_templates"
return "monitor_snmp_templates"
}
// SNMPTemplateOID OID模板条目表
@@ -142,7 +142,7 @@ type SNMPTemplateOID struct {
// TableName 指定表名
func (SNMPTemplateOID) TableName() string {
return "ops_snmp_template_oids"
return "monitor_snmp_template_oids"
}
// ============================================
@@ -170,7 +170,7 @@ type SNMPMetric struct {
// TableName 指定表名
func (SNMPMetric) TableName() string {
return "ops_snmp_metrics"
return "monitor_snmp_samples"
}
// ============================================
@@ -180,26 +180,26 @@ func (SNMPMetric) TableName() string {
// SNMPInterface SNMP接口信息表
// 存储网络设备的接口详细信息
type SNMPInterface struct {
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
DeviceID uint `gorm:"not null;index;comment:设备ID" json:"device_id"`
IfIndex int `gorm:"not null;comment:接口索引" json:"if_index"`
IfDescr string `gorm:"type:varchar(128);comment:接口描述" json:"if_descr,omitempty"`
IfName string `gorm:"type:varchar(64);comment:接口名称" json:"if_name,omitempty"`
IfAlias string `gorm:"type:varchar(128);comment:接口别名" json:"if_alias,omitempty"`
IfType int `gorm:"comment:接口类型" json:"if_type,omitempty"`
IfSpeed uint64 `gorm:"comment:接口速率(bps)" json:"if_speed,omitempty"`
IfPhysAddr string `gorm:"type:varchar(32);comment:物理地址(MAC)" json:"if_phys_addr,omitempty"`
IfAdminStatus int `gorm:"comment:管理状态: 1=up 2=down 3=testing" json:"if_admin_status,omitempty"`
IfOperStatus int `gorm:"comment:操作状态: 1=up 2=down 3=testing" json:"if_oper_status,omitempty"`
IfHighSpeed uint32 `gorm:"comment:高速接口速率(Mbps)" json:"if_high_speed,omitempty"`
Status int `gorm:"default:1;comment:状态" json:"status"`
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
DeviceID uint `gorm:"not null;index;comment:设备ID" json:"device_id"`
IfIndex int `gorm:"not null;comment:接口索引" json:"if_index"`
IfDescr string `gorm:"type:varchar(128);comment:接口描述" json:"if_descr,omitempty"`
IfName string `gorm:"type:varchar(64);comment:接口名称" json:"if_name,omitempty"`
IfAlias string `gorm:"type:varchar(128);comment:接口别名" json:"if_alias,omitempty"`
IfType int `gorm:"comment:接口类型" json:"if_type,omitempty"`
IfSpeed uint64 `gorm:"comment:接口速率(bps)" json:"if_speed,omitempty"`
IfPhysAddr string `gorm:"type:varchar(32);comment:物理地址(MAC)" json:"if_phys_addr,omitempty"`
IfAdminStatus int `gorm:"comment:管理状态: 1=up 2=down 3=testing" json:"if_admin_status,omitempty"`
IfOperStatus int `gorm:"comment:操作状态: 1=up 2=down 3=testing" json:"if_oper_status,omitempty"`
IfHighSpeed uint32 `gorm:"comment:高速接口速率(Mbps)" json:"if_high_speed,omitempty"`
Status int `gorm:"default:1;comment:状态" json:"status"`
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
}
// TableName 指定表名
func (SNMPInterface) TableName() string {
return "ops_snmp_interfaces"
return "monitor_snmp_interfaces"
}
// ============================================