vendors.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Package rintegration manages external integrations (#1674): pushers that
  2. // run on the NetPulse server (mode "local"), on the router itself (mode
  3. // "ssh") or on the monitored host under the operator's own supervision (mode
  4. // "node"), and push data to the agent ingest endpoint with the external agent
  5. // contract.
  6. package rintegration
  7. import "strings"
  8. // Mode values for Vendor.Mode, as declared by the catalog.
  9. const (
  10. // ModeLocal: NetPulse downloads the binary and runs it as a managed
  11. // child on the server host.
  12. ModeLocal = "local"
  13. // ModeSSH: NetPulse installs the pusher inside the router over SSH.
  14. ModeSSH = "ssh"
  15. // ModeNode: the operator installs and supervises the pusher on the
  16. // monitored host. NetPulse only registers the row, issues the token and
  17. // shows what to set (#2272); it never installs, starts or stops it.
  18. ModeNode = "node"
  19. )
  20. // Vendor is one supported external pusher as resolved from the vendor
  21. // catalog. The catalog entries (vendors.json in netpulse-integrations) decide
  22. // which vendors exist; the fields the schema does not carry (Repo, AssetTmpl,
  23. // Init) are derived server-side by the Catalog when it builds this struct.
  24. type Vendor struct {
  25. ID string // catalog "id"
  26. Mode string // "local" (runs on this host) | "ssh" (installed on the router) | "node" (installed on the monitored host)
  27. Repo string // GitHub repo that publishes the releases (derived: CatalogRepo)
  28. TagPrefix string // release tags for this vendor (e.g. "routeros/v")
  29. AssetTmpl string // asset name template with {version} and {arch} (derived)
  30. Arches []string
  31. Binary string // binary name inside the tarball (catalog "binary")
  32. Init string // on-router init system for Mode "ssh": "procd" (default when empty) | "merlin" (#1681, derived)
  33. Description string
  34. }
  35. // InitSystem returns the on-router layout used by the ssh install scripts:
  36. // "merlin" (/jffs plus a services-start hook) or "procd" (OpenWrt init.d).
  37. // An empty Init means procd, the layout vendors shipped with before #1681.
  38. func (v Vendor) InitSystem() string {
  39. if v.Init == "merlin" {
  40. return "merlin"
  41. }
  42. return "procd"
  43. }
  44. // ServerManaged reports whether NetPulse runs the pusher itself, as a child
  45. // process of the server. Only mode "local" works that way.
  46. func (v Vendor) ServerManaged() bool { return v.Mode == ModeLocal }
  47. // ServerInstalls reports whether NetPulse performs the installation of the
  48. // pusher: it downloads the binary for "local" and installs it over SSH for
  49. // "ssh". A "node" vendor is installed by the operator, never by the server.
  50. func (v Vendor) ServerInstalls() bool {
  51. return v.Mode == ModeLocal || v.Mode == ModeSSH
  52. }
  53. // OperatorInstalled reports whether the pusher runs on the monitored host
  54. // under the operator's own supervision (mode "node").
  55. func (v Vendor) OperatorInstalled() bool { return v.Mode == ModeNode }
  56. // ValidMode reports whether the catalog may declare this mode.
  57. func ValidMode(mode string) bool {
  58. return mode == ModeLocal || mode == ModeSSH || mode == ModeNode
  59. }
  60. // AssetName renders the asset name for a resolved version and architecture.
  61. func (v Vendor) AssetName(version, arch string) string {
  62. name := v.AssetTmpl
  63. name = strings.ReplaceAll(name, "{version}", version)
  64. name = strings.ReplaceAll(name, "{arch}", arch)
  65. return name
  66. }