package model import ( "time" ) // ============================================ // SNMPDevice SNMP设备 // ============================================ // SNMPVersion SNMP协议版本 type SNMPVersion string const ( SNMPVersionV1 SNMPVersion = "v1" // SNMP v1 SNMPVersionV2c SNMPVersion = "v2c" // SNMP v2c SNMPVersionV3 SNMPVersion = "v3" // SNMP v3 ) // SNMPAuthProtocol SNMP v3 认证协议 type SNMPAuthProtocol string const ( SNMPAuthMD5 SNMPAuthProtocol = "MD5" // MD5认证 SNMPAuthSHA SNMPAuthProtocol = "SHA" // SHA认证 SNMPAuthSHAAES SNMPAuthProtocol = "SHA-AES" // SHA+AES ) // SNMPPrivProtocol SNMP v3 加密协议 type SNMPPrivProtocol string const ( SNMPPrivDES SNMPPrivProtocol = "DES" // DES加密 SNMPPrivAES SNMPPrivProtocol = "AES" // AES加密 SNMPPrivAES256 SNMPPrivProtocol = "AES256" // AES256加密 ) // SNMPDeviceStatus SNMP设备状态 type SNMPDeviceStatus string const ( SNMPDeviceOnline SNMPDeviceStatus = "online" // 在线 SNMPDeviceOffline SNMPDeviceStatus = "offline" // 离线 SNMPDeviceError SNMPDeviceStatus = "error" // 错误 ) // 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"` // 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"` // 设备信息 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"` // 状态 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"` Metrics []SNMPMetric `gorm:"foreignKey:DeviceID" json:"metrics,omitempty"` } // TableName 指定表名 func (SNMPDevice) TableName() string { return "ops_snmp_devices" } // ============================================ // SNMPTemplate OID模板 // ============================================ // 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"` DeletedAt *time.Time `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"` // 关联关系 OIDs []SNMPTemplateOID `gorm:"foreignKey:TemplateID" json:"oids,omitempty"` } // TableName 指定表名 func (SNMPTemplate) TableName() string { return "ops_snmp_templates" } // SNMPTemplateOID OID模板条目表 // 模板中具体的OID定义 type SNMPTemplateOID struct { ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"` TemplateID uint `gorm:"not null;index;comment:模板ID" json:"template_id"` Name string `gorm:"type:varchar(64);not null;comment:OID名称" json:"name"` OID string `gorm:"type:varchar(256);not null;comment:OID字符串" json:"oid"` Description string `gorm:"type:varchar(128);comment:描述" json:"description,omitempty"` DataType string `gorm:"type:varchar(16);comment:数据类型: integer/counter/gauge/string" json:"data_type"` Unit string `gorm:"type:varchar(32);comment:单位" json:"unit,omitempty"` IsIndex bool `gorm:"default:false;comment:是否索引OID" json:"is_index"` Conversion string `gorm:"type:varchar(64);comment:转换公式" json:"conversion,omitempty"` SortOrder int `gorm:"default:0;comment:排序" json:"sort_order"` CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"` UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"` } // TableName 指定表名 func (SNMPTemplateOID) TableName() string { return "ops_snmp_template_oids" } // ============================================ // SNMPMetric SNMP采集指标 // ============================================ // SNMPMetric SNMP采集指标表 // 存储从SNMP设备采集到的指标数据 type SNMPMetric struct { ID uint64 `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"` DeviceID uint `gorm:"not null;index:idx_device_metric;comment:设备ID" json:"device_id"` Name string `gorm:"type:varchar(64);not null;index;comment:指标名称" json:"name"` OID string `gorm:"type:varchar(256);not null;comment:OID" json:"oid"` Index string `gorm:"type:varchar(128);index;comment:索引值(如接口名)" json:"index,omitempty"` Value float64 `gorm:"comment:数值" json:"value"` RawValue string `gorm:"type:text;comment:原始字符串值" json:"raw_value,omitempty"` Unit string `gorm:"type:varchar(32);comment:单位" json:"unit,omitempty"` DataType string `gorm:"type:varchar(16);comment:数据类型" json:"data_type"` Timestamp int64 `gorm:"not null;index:idx_device_metric;comment:采集时间戳" json:"timestamp"` CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"` // 关联关系 Device *SNMPDevice `gorm:"foreignKey:DeviceID" json:"device,omitempty"` } // TableName 指定表名 func (SNMPMetric) TableName() string { return "ops_snmp_metrics" } // ============================================ // SNMPInterface 网络接口信息 // ============================================ // 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"` } // TableName 指定表名 func (SNMPInterface) TableName() string { return "ops_snmp_interfaces" } // ============================================ // SNMPHistory SNMP采集历史 // ============================================ // SNMPHistory SNMP采集历史表(按时间分区) // 存储SNMP指标的时序历史数据,用于趋势分析和报表 type SNMPHistory struct { ID uint64 `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"` DeviceID uint `gorm:"not null;index:idx_snmp_history;comment:设备ID" json:"device_id"` MetricID uint `gorm:"not null;index;comment:指标定义ID" json:"metric_id"` Name string `gorm:"type:varchar(64);not null;comment:指标名称" json:"name"` Index string `gorm:"type:varchar(128);index;comment:索引值" json:"index,omitempty"` Value float64 `gorm:"not null;comment:采集值" json:"value"` Unit string `gorm:"type:varchar(32);comment:单位" json:"unit,omitempty"` Timestamp int64 `gorm:"not null;index:idx_snmp_history;comment:时间戳" json:"timestamp"` CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"` } // TableName 指定表名 func (SNMPHistory) TableName() string { return "snmp_history" } // SNMPWalkResult SNMP Walk 结果 type SNMPWalkResult struct { OID string `json:"oid"` Type string `json:"type"` Value string `json:"value"` Index string `json:"index,omitempty"` Timestamp int64 `json:"timestamp"` } // SNMPConnectionConfig SNMP连接配置 type SNMPConnectionConfig struct { IP string `json:"ip"` Port int `json:"port"` Version SNMPVersion `json:"version"` Community string `json:"community,omitempty"` Username string `json:"username,omitempty"` AuthProtocol SNMPAuthProtocol `json:"auth_protocol,omitempty"` AuthPassword string `json:"auth_password,omitempty"` PrivProtocol SNMPPrivProtocol `json:"priv_protocol,omitempty"` PrivPassword string `json:"priv_password,omitempty"` SecurityLevel string `json:"security_level,omitempty"` Timeout int `json:"timeout"` Retries int `json:"retries"` MaxRepetitions uint32 `json:"max_repetitions"` }