types.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package tools
  2. type PingRequest struct {
  3. Target string `json:"target"`
  4. Count int `json:"count"` // 1 - 20, default 4
  5. Size int `json:"size"` // default 56
  6. Interface string `json:"interface"` // optional source interface
  7. Timeout int `json:"timeout"` // seconds, default 5
  8. DoNotFrag bool `json:"dont_frag"`
  9. }
  10. type PingReply struct {
  11. Seq int `json:"seq"`
  12. Bytes int `json:"bytes"`
  13. From string `json:"from"`
  14. TTL int `json:"ttl"`
  15. TimeMs float64 `json:"time_ms"`
  16. }
  17. type PingResponse struct {
  18. Target string `json:"target"`
  19. PacketsSent int `json:"packets_sent"`
  20. PacketsRecv int `json:"packets_recv"`
  21. PacketLossPct float64 `json:"packet_loss_pct"`
  22. MinRTT float64 `json:"min_rtt_ms"`
  23. AvgRTT float64 `json:"avg_rtt_ms"`
  24. MaxRTT float64 `json:"max_rtt_ms"`
  25. MdevRTT float64 `json:"mdev_rtt_ms"`
  26. Replies []PingReply `json:"replies"`
  27. RawOutput string `json:"raw_output"`
  28. Status string `json:"status"` // "ok", "partial", "timeout", "error"
  29. Error string `json:"error,omitempty"`
  30. }
  31. type PingStreamEvent struct {
  32. Type string `json:"type"` // "header", "reply", "timeout", "unreach", "stats", "done", "error"
  33. Seq int `json:"seq,omitempty"`
  34. Bytes int `json:"bytes,omitempty"`
  35. From string `json:"from,omitempty"`
  36. TTL int `json:"ttl,omitempty"`
  37. TimeMs float64 `json:"time_ms,omitempty"`
  38. PacketsSent int `json:"packets_sent,omitempty"`
  39. PacketsRecv int `json:"packets_recv,omitempty"`
  40. PacketLossPct float64 `json:"packet_loss_pct,omitempty"`
  41. MinRTT float64 `json:"min_rtt_ms,omitempty"`
  42. AvgRTT float64 `json:"avg_rtt_ms,omitempty"`
  43. MaxRTT float64 `json:"max_rtt_ms,omitempty"`
  44. MdevRTT float64 `json:"mdev_rtt_ms,omitempty"`
  45. Message string `json:"message,omitempty"`
  46. Raw string `json:"raw"`
  47. }
  48. type TracerouteRequest struct {
  49. Target string `json:"target"`
  50. MaxHops int `json:"max_hops"` // default 15, max 30
  51. Resolve bool `json:"resolve"` // DNS resolve IPs
  52. Interface string `json:"interface"` // source dev
  53. Protocol string `json:"protocol"` // "icmp", "udp"
  54. }
  55. type TracerouteHop struct {
  56. Hop int `json:"hop"`
  57. Host string `json:"host"`
  58. IP string `json:"ip"`
  59. TimesMs []string `json:"times_ms"`
  60. Status string `json:"status"` // "ok", "timeout"
  61. }
  62. type TracerouteResponse struct {
  63. Target string `json:"target"`
  64. Hops []TracerouteHop `json:"hops"`
  65. RawOutput string `json:"raw_output"`
  66. Error string `json:"error,omitempty"`
  67. }
  68. type TracerouteStreamEvent struct {
  69. Type string `json:"type"` // "header", "hop", "done", "error"
  70. Hop *TracerouteHop `json:"hop,omitempty"`
  71. HopsCount int `json:"hops_count,omitempty"`
  72. Message string `json:"message,omitempty"`
  73. Raw string `json:"raw"`
  74. }
  75. type DNSRequest struct {
  76. Domain string `json:"domain"`
  77. Type string `json:"type"` // A, AAAA, MX, TXT, NS, CNAME, ANY
  78. Server string `json:"server"` // optional DNS server IP
  79. }
  80. type DNSRecord struct {
  81. Name string `json:"name"`
  82. TTL int `json:"ttl"`
  83. Class string `json:"class"`
  84. Type string `json:"type"`
  85. Value string `json:"value"`
  86. }
  87. type DNSResponse struct {
  88. Domain string `json:"domain"`
  89. Type string `json:"type"`
  90. Server string `json:"server"`
  91. QueryTimeMs int `json:"query_time_ms"`
  92. Records []DNSRecord `json:"records"`
  93. RawOutput string `json:"raw_output"`
  94. Error string `json:"error,omitempty"`
  95. }
  96. type PortProbeRequest struct {
  97. Target string `json:"target"`
  98. Port int `json:"port"`
  99. Timeout int `json:"timeout"` // default 2s
  100. }
  101. type PortProbeResponse struct {
  102. Target string `json:"target"`
  103. Port int `json:"port"`
  104. Open bool `json:"open"`
  105. LatencyMs float64 `json:"latency_ms"`
  106. Service string `json:"service,omitempty"`
  107. RawOutput string `json:"raw_output"`
  108. Error string `json:"error,omitempty"`
  109. }
  110. type MTRRequest struct {
  111. Target string `json:"target"`
  112. Count int `json:"count"` // default 3
  113. }
  114. type MTRHop struct {
  115. Hop int `json:"hop"`
  116. Host string `json:"host"`
  117. LossPct float64 `json:"loss_pct"`
  118. Sent int `json:"sent"`
  119. LastMs float64 `json:"last_ms"`
  120. AvgMs float64 `json:"avg_ms"`
  121. BestMs float64 `json:"best_ms"`
  122. WrstMs float64 `json:"wrst_ms"`
  123. StDevMs float64 `json:"stdev_ms"`
  124. }
  125. type MTRResponse struct {
  126. Target string `json:"target"`
  127. Hops []MTRHop `json:"hops"`
  128. RawOutput string `json:"raw_output"`
  129. Error string `json:"error,omitempty"`
  130. }