| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- // Package rintegration manages external integrations (#1674): pushers that
- // run on the NetPulse server (mode "local"), on the router itself (mode
- // "ssh") or on the monitored host under the operator's own supervision (mode
- // "node"), and push data to the agent ingest endpoint with the external agent
- // contract.
- package rintegration
- import "strings"
- // Mode values for Vendor.Mode, as declared by the catalog.
- const (
- // ModeLocal: NetPulse downloads the binary and runs it as a managed
- // child on the server host.
- ModeLocal = "local"
- // ModeSSH: NetPulse installs the pusher inside the router over SSH.
- ModeSSH = "ssh"
- // ModeNode: the operator installs and supervises the pusher on the
- // monitored host. NetPulse only registers the row, issues the token and
- // shows what to set (#2272); it never installs, starts or stops it.
- ModeNode = "node"
- )
- // Vendor is one supported external pusher as resolved from the vendor
- // catalog. The catalog entries (vendors.json in netpulse-integrations) decide
- // which vendors exist; the fields the schema does not carry (Repo, AssetTmpl,
- // Init) are derived server-side by the Catalog when it builds this struct.
- type Vendor struct {
- ID string // catalog "id"
- Mode string // "local" (runs on this host) | "ssh" (installed on the router) | "node" (installed on the monitored host)
- Repo string // GitHub repo that publishes the releases (derived: CatalogRepo)
- TagPrefix string // release tags for this vendor (e.g. "routeros/v")
- AssetTmpl string // asset name template with {version} and {arch} (derived)
- Arches []string
- Binary string // binary name inside the tarball (catalog "binary")
- Init string // on-router init system for Mode "ssh": "procd" (default when empty) | "merlin" (#1681, derived)
- Description string
- }
- // InitSystem returns the on-router layout used by the ssh install scripts:
- // "merlin" (/jffs plus a services-start hook) or "procd" (OpenWrt init.d).
- // An empty Init means procd, the layout vendors shipped with before #1681.
- func (v Vendor) InitSystem() string {
- if v.Init == "merlin" {
- return "merlin"
- }
- return "procd"
- }
- // ServerManaged reports whether NetPulse runs the pusher itself, as a child
- // process of the server. Only mode "local" works that way.
- func (v Vendor) ServerManaged() bool { return v.Mode == ModeLocal }
- // ServerInstalls reports whether NetPulse performs the installation of the
- // pusher: it downloads the binary for "local" and installs it over SSH for
- // "ssh". A "node" vendor is installed by the operator, never by the server.
- func (v Vendor) ServerInstalls() bool {
- return v.Mode == ModeLocal || v.Mode == ModeSSH
- }
- // OperatorInstalled reports whether the pusher runs on the monitored host
- // under the operator's own supervision (mode "node").
- func (v Vendor) OperatorInstalled() bool { return v.Mode == ModeNode }
- // ValidMode reports whether the catalog may declare this mode.
- func ValidMode(mode string) bool {
- return mode == ModeLocal || mode == ModeSSH || mode == ModeNode
- }
- // AssetName renders the asset name for a resolved version and architecture.
- func (v Vendor) AssetName(version, arch string) string {
- name := v.AssetTmpl
- name = strings.ReplaceAll(name, "{version}", version)
- name = strings.ReplaceAll(name, "{arch}", arch)
- return name
- }
|