vendors.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Package rintegration manages external router integrations (#1674): pushers
  2. // that run on the NetPulse server (mode "local") or on the router itself
  3. // (mode "ssh") and push data to the agent ingest endpoint with the external
  4. // agent contract.
  5. package rintegration
  6. import "strings"
  7. // Vendor is one supported external pusher as resolved from the vendor
  8. // catalog. The catalog entries (vendors.json in netpulse-integrations) decide
  9. // which vendors exist; the fields the schema does not carry (Repo, AssetTmpl,
  10. // Init) are derived server-side by the Catalog when it builds this struct.
  11. type Vendor struct {
  12. ID string // catalog "id"
  13. Mode string // "local" (runs on this host) | "ssh" (installed on the router)
  14. Repo string // GitHub repo that publishes the releases (derived: CatalogRepo)
  15. TagPrefix string // release tags for this vendor (e.g. "routeros/v")
  16. AssetTmpl string // asset name template with {version} and {arch} (derived)
  17. Arches []string
  18. Binary string // binary name inside the tarball (catalog "binary")
  19. Init string // on-router init system for Mode "ssh": "procd" (default when empty) | "merlin" (#1681, derived)
  20. Description string
  21. }
  22. // InitSystem returns the on-router layout used by the ssh install scripts:
  23. // "merlin" (/jffs plus a services-start hook) or "procd" (OpenWrt init.d).
  24. // An empty Init means procd, the layout vendors shipped with before #1681.
  25. func (v Vendor) InitSystem() string {
  26. if v.Init == "merlin" {
  27. return "merlin"
  28. }
  29. return "procd"
  30. }
  31. // AssetName renders the asset name for a resolved version and architecture.
  32. func (v Vendor) AssetName(version, arch string) string {
  33. name := v.AssetTmpl
  34. name = strings.ReplaceAll(name, "{version}", version)
  35. name = strings.ReplaceAll(name, "{arch}", arch)
  36. return name
  37. }