This commit is contained in:
henrygd
2026-04-22 21:40:52 -04:00
parent 8f03cbf11c
commit 5fc774666f
12 changed files with 160 additions and 85 deletions

View File

@@ -1,13 +1,13 @@
package probe
import "strconv"
// Config defines a network probe task sent from hub to agent.
type Config struct {
Target string `cbor:"0,keyasint" json:"target"`
Protocol string `cbor:"1,keyasint" json:"protocol"` // "icmp", "tcp", or "http"
Port uint16 `cbor:"2,keyasint,omitempty" json:"port,omitempty"`
Interval uint16 `cbor:"3,keyasint" json:"interval"` // seconds
// ID is the stable network_probes record ID generated by the hub.
ID string `cbor:"0,keyasint"`
Target string `cbor:"1,keyasint"`
Protocol string `cbor:"2,keyasint"` // "icmp", "tcp", or "http"
Port uint16 `cbor:"3,keyasint,omitempty"`
Interval uint16 `cbor:"4,keyasint"` // seconds
}
// Result holds aggregated probe results for a single target.
@@ -22,13 +22,3 @@ type Config struct {
//
// 4: packet loss percentage over the last hour (0-100)
type Result []float64
// Key returns the map key used for this probe config (e.g. "icmp:1.1.1.1", "tcp:host:443", "http:https://example.com").
func (c Config) Key() string {
switch c.Protocol {
case "tcp":
return c.Protocol + ":" + c.Target + ":" + strconv.FormatUint(uint64(c.Port), 10)
default:
return c.Protocol + ":" + c.Target
}
}