models.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package models
  2. import "time"
  3. // DeviceType 设备类型
  4. type DeviceType string
  5. const (
  6. DeviceTypeCisco DeviceType = "cisco"
  7. DeviceTypeHuawei DeviceType = "huawei"
  8. DeviceTypeH3C DeviceType = "h3c"
  9. DeviceTypeASA DeviceType = "asa"
  10. DeviceTypeLinux DeviceType = "linux"
  11. DeviceTypeWindows DeviceType = "windows"
  12. )
  13. // Device 网络设备
  14. type Device struct {
  15. ID string `json:"id"`
  16. IP string `json:"ip"`
  17. Type DeviceType `json:"type"`
  18. Hostname string `json:"hostname"`
  19. OSVersion string `json:"os_version"`
  20. Uptime string `json:"uptime"`
  21. Interfaces []Interface `json:"interfaces"`
  22. Neighbors []Neighbor `json:"neighbors"`
  23. MACAddresses []string `json:"mac_addresses,omitempty"` // 设备的所有MAC地址(用于邻居匹配)
  24. LastScanned time.Time `json:"last_scanned"`
  25. ScanStatus string `json:"scan_status"` // success, failed, pending
  26. ErrorMessage string `json:"error_message,omitempty"`
  27. }
  28. // Interface 网络接口
  29. type Interface struct {
  30. Name string `json:"name"`
  31. Description string `json:"description"`
  32. IP string `json:"ip"`
  33. Mask string `json:"mask"`
  34. MAC string `json:"mac"`
  35. Status string `json:"status"` // up, down, admin down
  36. Speed string `json:"speed"`
  37. Duplex string `json:"duplex"`
  38. MTU int `json:"mtu"`
  39. VLAN string `json:"vlan"` // VLAN信息(PVID/Access/Trunk)
  40. InBytes int64 `json:"in_bytes"`
  41. OutBytes int64 `json:"out_bytes"`
  42. InPackets int64 `json:"in_packets"`
  43. OutPackets int64 `json:"out_packets"`
  44. }
  45. // Neighbor 邻居设备信息
  46. type Neighbor struct {
  47. LocalInterface string `json:"local_interface"`
  48. RemoteDevice string `json:"remote_device"`
  49. RemoteIP string `json:"remote_ip"`
  50. RemoteMAC string `json:"remote_mac,omitempty"` // MAC地址(用于拓扑匹配)
  51. RemoteInterface string `json:"remote_interface"`
  52. Protocol string `json:"protocol"` // CDP, LLDP, ARP
  53. }
  54. // ScanTask 扫描任务
  55. type ScanTask struct {
  56. ID string `json:"id"`
  57. Status string `json:"status"` // running, completed, failed
  58. Progress int `json:"progress"`
  59. TotalDevices int `json:"total_devices"`
  60. ScannedDevices int `json:"scanned_devices"`
  61. StartTime time.Time `json:"start_time"`
  62. EndTime time.Time `json:"end_time"`
  63. Devices []Device `json:"devices"`
  64. ErrorMessage string `json:"error_message,omitempty"`
  65. }
  66. // TopologyGraph 拓扑图数据
  67. type TopologyGraph struct {
  68. Nodes []TopologyNode `json:"nodes"`
  69. Edges []TopologyEdge `json:"edges"`
  70. }
  71. // TopologyNode 拓扑节点
  72. type TopologyNode struct {
  73. ID string `json:"id"`
  74. IP string `json:"ip"`
  75. Hostname string `json:"hostname"`
  76. Type string `json:"type"`
  77. Icon string `json:"icon"`
  78. }
  79. // TopologyEdge 拓扑边
  80. type TopologyEdge struct {
  81. ID string `json:"id"`
  82. Source string `json:"source"`
  83. Target string `json:"target"`
  84. SourceInterface string `json:"source_interface"`
  85. TargetInterface string `json:"target_interface"`
  86. Protocol string `json:"protocol"`
  87. }
  88. // Topology 网络拓扑(一个拓扑包含多个设备)
  89. type Topology struct {
  90. ID string `json:"id"`
  91. Name string `json:"name"`
  92. Description string `json:"description"`
  93. ScanRange string `json:"scan_range"`
  94. SSHPort int `json:"ssh_port"`
  95. Username string `json:"username"`
  96. CreatedAt time.Time `json:"created_at"`
  97. UpdatedAt time.Time `json:"updated_at"`
  98. DeviceCount int `json:"device_count"`
  99. }