|
|
@@ -254,8 +254,10 @@ func (s *server) watchIntegrations() {
|
|
|
// entorno 0600 ya existente (el token y la contraseña solo viven ahí); en
|
|
|
// modo ssh el pusher corre dentro del router y no hay nada que arrancar en el
|
|
|
// servidor, pero el estado guardado deja de decir running (no verificado
|
|
|
-// hasta el próximo check/start). Un fallo se loga y deja la fila en estado
|
|
|
-// error: nunca tira el arranque del servidor.
|
|
|
+// hasta el próximo check/start). En modo node el pusher corre en el host
|
|
|
+// monitorizado: la fila vuelve a pending y el primer push la pone viva. Un
|
|
|
+// fallo se loga y deja la fila en estado error: nunca tira el arranque del
|
|
|
+// servidor.
|
|
|
func (s *server) resumeIntegrations() {
|
|
|
if s.integrations == nil || s.db == nil {
|
|
|
return
|
|
|
@@ -270,7 +272,15 @@ func (s *server) resumeIntegrations() {
|
|
|
if !row.Enabled {
|
|
|
continue
|
|
|
}
|
|
|
- if row.Mode != "local" {
|
|
|
+ if row.Mode == rintegration.ModeNode {
|
|
|
+ // Nadie en el servidor instala ni arranca esto (#2272): lo
|
|
|
+ // supervisa el operador en el host monitorizado.
|
|
|
+ if row.State != "pending" {
|
|
|
+ _ = store.SetState(row.Slug, "pending", "")
|
|
|
+ }
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if row.Mode != rintegration.ModeLocal {
|
|
|
// El proceso vive en el router: sin verificar tras el reinicio
|
|
|
// del servidor; check/start lo reconcilian.
|
|
|
if row.State == "running" {
|
|
|
@@ -407,7 +417,15 @@ func (s *server) handleIntegrationsCreate(w http.ResponseWriter, r *http.Request
|
|
|
writeError(w, http.StatusBadRequest, "invalid_vendor", "unknown vendor")
|
|
|
return
|
|
|
}
|
|
|
- if body.Host == "" || body.Username == "" || body.Password == "" {
|
|
|
+ if vendor.OperatorInstalled() {
|
|
|
+ // #2272: en modo node el host es solo la etiqueta de la fila. La
|
|
|
+ // conexión del pusher (token del apiserver, kubelet, rutas) la
|
|
|
+ // configura el operador en el propio nodo, así que el alta no pide
|
|
|
+ // usuario ni contraseña.
|
|
|
+ if body.Host == "" {
|
|
|
+ body.Host = body.Slug
|
|
|
+ }
|
|
|
+ } else if body.Host == "" || body.Username == "" || body.Password == "" {
|
|
|
writeError(w, http.StatusBadRequest, "invalid_input", "host, username and password are required")
|
|
|
return
|
|
|
}
|
|
|
@@ -439,9 +457,11 @@ func (s *server) handleIntegrationsCreate(w http.ResponseWriter, r *http.Request
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // Resolver y descargar el último release verificado. En modo local se
|
|
|
- // extrae el binario aquí (corre en este host); en modo ssh solo se
|
|
|
- // verifica: el router descarga el asset él mismo.
|
|
|
+ // Resolver el último release verificado. En modo local se extrae el
|
|
|
+ // binario aquí (corre en este host); en modo ssh solo se verifica: el
|
|
|
+ // router descarga el asset él mismo; en modo node no se descarga ni se
|
|
|
+ // verifica nada, porque instala el operador (#2272) y la fila solo
|
|
|
+ // conserva versión y nombre del asset para que la UI apunte a la descarga.
|
|
|
fetch := s.integrationFetcher()
|
|
|
res, err := fetch.ResolveLatest(vendor, arch)
|
|
|
if err != nil {
|
|
|
@@ -449,7 +469,7 @@ func (s *server) handleIntegrationsCreate(w http.ResponseWriter, r *http.Request
|
|
|
return
|
|
|
}
|
|
|
binPath := ""
|
|
|
- if vendor.Mode == "local" {
|
|
|
+ if vendor.ServerManaged() {
|
|
|
if s.integrations == nil {
|
|
|
writeError(w, http.StatusServiceUnavailable, "unavailable", "integrations supervisor not configured")
|
|
|
return
|
|
|
@@ -460,7 +480,7 @@ func (s *server) handleIntegrationsCreate(w http.ResponseWriter, r *http.Request
|
|
|
writeError(w, http.StatusBadGateway, "download_failed", err.Error())
|
|
|
return
|
|
|
}
|
|
|
- } else {
|
|
|
+ } else if vendor.Mode == rintegration.ModeSSH {
|
|
|
if s.pool == nil {
|
|
|
writeError(w, http.StatusServiceUnavailable, "ssh_unavailable", "el servidor no tiene pool SSH")
|
|
|
return
|
|
|
@@ -486,7 +506,7 @@ func (s *server) handleIntegrationsCreate(w http.ResponseWriter, r *http.Request
|
|
|
// #1708: en modo ssh la misma contraseña del formulario es la credencial
|
|
|
// SSH del alta y de las acciones posteriores: se guarda en el fichero
|
|
|
// compañero (0600) antes de conectar, nunca en la base de datos.
|
|
|
- if vendor.Mode == "ssh" && s.integrations != nil {
|
|
|
+ if vendor.Mode == rintegration.ModeSSH && s.integrations != nil {
|
|
|
if err := s.integrations.WriteSSHPassword(body.Slug, body.Password); err != nil {
|
|
|
_ = store.Delete(body.Slug)
|
|
|
writeError(w, http.StatusInternalServerError, "ssh_password_write", err.Error())
|
|
|
@@ -507,11 +527,11 @@ func (s *server) handleIntegrationsCreate(w http.ResponseWriter, r *http.Request
|
|
|
s.syncRouters()
|
|
|
|
|
|
rollback := func() {
|
|
|
- if vendor.Mode == "local" && s.integrations != nil {
|
|
|
+ if vendor.ServerManaged() && s.integrations != nil {
|
|
|
_ = s.integrations.Stop(body.Slug)
|
|
|
_ = s.integrations.Cleanup(body.Slug)
|
|
|
}
|
|
|
- if vendor.Mode == "ssh" && s.integrations != nil {
|
|
|
+ if vendor.Mode == rintegration.ModeSSH && s.integrations != nil {
|
|
|
_ = s.integrations.RemoveSSHPassword(body.Slug)
|
|
|
}
|
|
|
_ = routerstore.RemoveRouter(s.db.DB, body.Slug)
|
|
|
@@ -519,9 +539,17 @@ func (s *server) handleIntegrationsCreate(w http.ResponseWriter, r *http.Request
|
|
|
_ = store.Delete(body.Slug)
|
|
|
}
|
|
|
|
|
|
+ // #2272: en modo node la rotación de token no arranca ni instala nada; el
|
|
|
+ // env que el operador debe copiar en el nodo sale en la respuesta una sola
|
|
|
+ // vez, como el token.
|
|
|
+ var nodeEnv map[string]string
|
|
|
token, err := s.rotateAgentTokenAtomic(body.Slug, func(tok string) error {
|
|
|
+ if vendor.OperatorInstalled() {
|
|
|
+ nodeEnv = s.operatorEnv(row, serverURL, tok)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
env := s.pusherEnv(vendor, row, body.Password, serverURL, tok)
|
|
|
- if vendor.Mode == "local" {
|
|
|
+ if vendor.ServerManaged() {
|
|
|
return s.integrations.Start(body.Slug, env, binPath)
|
|
|
}
|
|
|
return s.runSSHInstall(vendor, row, env, res.URL, res.SHA256)
|
|
|
@@ -532,15 +560,21 @@ func (s *server) handleIntegrationsCreate(w http.ResponseWriter, r *http.Request
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- _ = store.SetState(body.Slug, "running", "")
|
|
|
- _ = store.SetLastStart(body.Slug, time.Now().UnixMilli())
|
|
|
+ if !vendor.OperatorInstalled() {
|
|
|
+ _ = store.SetState(body.Slug, "running", "")
|
|
|
+ _ = store.SetLastStart(body.Slug, time.Now().UnixMilli())
|
|
|
+ }
|
|
|
s.broadcastIntegrations()
|
|
|
|
|
|
item, _ := s.getIntegrationRow(body.Slug)
|
|
|
- writeJSON(w, http.StatusCreated, map[string]any{
|
|
|
+ out := map[string]any{
|
|
|
"integration": s.integrationItemOf(item),
|
|
|
"token": token,
|
|
|
- })
|
|
|
+ }
|
|
|
+ if nodeEnv != nil {
|
|
|
+ out["env"] = nodeEnv
|
|
|
+ }
|
|
|
+ writeJSON(w, http.StatusCreated, out)
|
|
|
}
|
|
|
|
|
|
func vendorSupportsArch(v rintegration.Vendor, arch string) bool {
|
|
|
@@ -552,13 +586,31 @@ func vendorSupportsArch(v rintegration.Vendor, arch string) bool {
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
+// operatorEnv builds the environment an operator has to set on a mode "node"
|
|
|
+// pusher (#2272): only the ingest side, because the vendor-specific knobs
|
|
|
+// (credentials, endpoints, file paths) live on the monitored host and the
|
|
|
+// server never learns them. Mirrors pusherEnv for the shared keys so a pusher
|
|
|
+// that speaks the standard contract needs no translation.
|
|
|
+func (s *server) operatorEnv(row rintegration.Row, serverURL, token string) map[string]string {
|
|
|
+ env := map[string]string{
|
|
|
+ "NETPULSE_SERVER": serverURL,
|
|
|
+ "NETPULSE_TOKEN": token,
|
|
|
+ "NETPULSE_SLUG": row.Slug,
|
|
|
+ "NETPULSE_INTERVAL": strconv.Itoa(row.IntervalS) + "s",
|
|
|
+ }
|
|
|
+ for k, v := range pusherPinEnv(serverURL) {
|
|
|
+ env[k] = v
|
|
|
+ }
|
|
|
+ return env
|
|
|
+}
|
|
|
+
|
|
|
// pusherEnv construye el entorno del pusher. En modo ssh el pusher corre en el
|
|
|
// propio router, así que el host del dispositivo es la propia unidad
|
|
|
// (127.0.0.1) en lugar del host SSH de la tabla.
|
|
|
func (s *server) pusherEnv(v rintegration.Vendor, row rintegration.Row, password, serverURL, token string) map[string]string {
|
|
|
prefix := strings.ToUpper(v.ID) + "_"
|
|
|
host := row.Host
|
|
|
- if v.Mode == "ssh" {
|
|
|
+ if v.Mode == rintegration.ModeSSH {
|
|
|
host = "127.0.0.1"
|
|
|
}
|
|
|
env := map[string]string{
|
|
|
@@ -661,8 +713,14 @@ func (s *server) handleIntegrationStart(w http.ResponseWriter, r *http.Request)
|
|
|
writeError(w, http.StatusInternalServerError, "invalid_vendor")
|
|
|
return
|
|
|
}
|
|
|
+ if vendor.OperatorInstalled() {
|
|
|
+ // #2272: no hay proceso en el servidor que arrancar. Lo supervisa el
|
|
|
+ // operador en el host monitorizado.
|
|
|
+ writeError(w, http.StatusConflict, "not_managed", "this pusher runs on the monitored host: start it there")
|
|
|
+ return
|
|
|
+ }
|
|
|
store := s.integrationsStore()
|
|
|
- if vendor.Mode == "local" {
|
|
|
+ if vendor.ServerManaged() {
|
|
|
if s.integrations == nil {
|
|
|
writeError(w, http.StatusServiceUnavailable, "unavailable", "integrations supervisor not configured")
|
|
|
return
|
|
|
@@ -703,7 +761,12 @@ func (s *server) handleIntegrationStop(w http.ResponseWriter, r *http.Request) {
|
|
|
writeError(w, http.StatusInternalServerError, "invalid_vendor")
|
|
|
return
|
|
|
}
|
|
|
- if vendor.Mode == "local" {
|
|
|
+ if vendor.OperatorInstalled() {
|
|
|
+ // #2272: nada que parar desde el servidor.
|
|
|
+ writeError(w, http.StatusConflict, "not_managed", "this pusher runs on the monitored host: stop it there")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if vendor.ServerManaged() {
|
|
|
if s.integrations != nil {
|
|
|
_ = s.integrations.Stop(slug) // ErrNotRunning es no-op aquí
|
|
|
}
|
|
|
@@ -728,8 +791,19 @@ func (s *server) handleIntegrationCheck(w http.ResponseWriter, r *http.Request)
|
|
|
writeError(w, http.StatusInternalServerError, "invalid_vendor")
|
|
|
return
|
|
|
}
|
|
|
+ if vendor.OperatorInstalled() {
|
|
|
+ // #2272: no hay proceso en el servidor que comprobar. La vida la dice
|
|
|
+ // el push (frescura y motivo de offline de la fila), así que el check
|
|
|
+ // no toca el estado guardado y lo declara por lo que es: no gestionado.
|
|
|
+ writeJSON(w, http.StatusOK, map[string]any{
|
|
|
+ "integration": s.integrationItemOf(row),
|
|
|
+ "running": false,
|
|
|
+ "managed": false,
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
running := false
|
|
|
- if vendor.Mode == "local" {
|
|
|
+ if vendor.ServerManaged() {
|
|
|
running = s.integrations != nil && s.integrations.Running(slug)
|
|
|
} else if s.pool != nil {
|
|
|
_, err := s.runIntegrationSSH(row, sshServiceScript(vendor, "check"), 30*time.Second)
|
|
|
@@ -748,6 +822,7 @@ func (s *server) handleIntegrationCheck(w http.ResponseWriter, r *http.Request)
|
|
|
writeJSON(w, http.StatusOK, map[string]any{
|
|
|
"integration": s.integrationItemOf(row),
|
|
|
"running": running,
|
|
|
+ "managed": true,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -772,7 +847,17 @@ func (s *server) handleIntegrationUpdate(w http.ResponseWriter, r *http.Request)
|
|
|
return
|
|
|
}
|
|
|
store := s.integrationsStore()
|
|
|
- if vendor.Mode == "local" {
|
|
|
+ if vendor.OperatorInstalled() {
|
|
|
+ // #2272: el servidor no instala ni reinicia nada en el nodo. Lo único
|
|
|
+ // que puede hacer es refrescar la versión publicada para que la UI
|
|
|
+ // ofrezca la descarga; el operador decide cuándo subirla.
|
|
|
+ _ = store.SetVersion(slug, res.Version, res.AssetName, row.Arch)
|
|
|
+ s.broadcastIntegrations()
|
|
|
+ item, _ := s.getIntegrationRow(slug)
|
|
|
+ writeJSON(w, http.StatusOK, map[string]any{"integration": s.integrationItemOf(item)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if vendor.ServerManaged() {
|
|
|
if s.integrations == nil {
|
|
|
writeError(w, http.StatusServiceUnavailable, "unavailable", "integrations supervisor not configured")
|
|
|
return
|
|
|
@@ -859,6 +944,10 @@ func (s *server) handleIntegrationEdit(w http.ResponseWriter, r *http.Request) {
|
|
|
changed = true
|
|
|
}
|
|
|
if body.Username != nil {
|
|
|
+ if vendor.OperatorInstalled() {
|
|
|
+ writeError(w, http.StatusBadRequest, "invalid_input", "username is set on the monitored host, not here")
|
|
|
+ return
|
|
|
+ }
|
|
|
u := strings.TrimSpace(*body.Username)
|
|
|
if u == "" {
|
|
|
writeError(w, http.StatusBadRequest, "invalid_input", "username cannot be empty")
|
|
|
@@ -877,6 +966,10 @@ func (s *server) handleIntegrationEdit(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
password := ""
|
|
|
if body.Password != nil {
|
|
|
+ if vendor.OperatorInstalled() {
|
|
|
+ writeError(w, http.StatusBadRequest, "invalid_input", "credentials are set on the monitored host, not here")
|
|
|
+ return
|
|
|
+ }
|
|
|
password = *body.Password
|
|
|
changed = true
|
|
|
}
|
|
|
@@ -885,14 +978,28 @@ func (s *server) handleIntegrationEdit(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ store := s.integrationsStore()
|
|
|
+ if vendor.OperatorInstalled() {
|
|
|
+ // #2272: no hay fichero de entorno en el servidor que reescribir ni
|
|
|
+ // proceso que reiniciar. Host es la etiqueta de la fila e intervalo lo
|
|
|
+ // aplica el operador en el nodo; la fila solo guarda ambos.
|
|
|
+ if err := store.Upsert(row); err != nil {
|
|
|
+ writeError(w, http.StatusInternalServerError, "db_error", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ s.broadcastIntegrations()
|
|
|
+ item, _ := s.getIntegrationRow(slug)
|
|
|
+ writeJSON(w, http.StatusOK, map[string]any{"integration": s.integrationItemOf(item)})
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
prefix := strings.ToUpper(vendor.ID) + "_"
|
|
|
host := row.Host
|
|
|
- if vendor.Mode == "ssh" {
|
|
|
+ if vendor.Mode == rintegration.ModeSSH {
|
|
|
host = "127.0.0.1"
|
|
|
}
|
|
|
- store := s.integrationsStore()
|
|
|
|
|
|
- if vendor.Mode == "local" {
|
|
|
+ if vendor.ServerManaged() {
|
|
|
if s.integrations == nil {
|
|
|
writeError(w, http.StatusServiceUnavailable, "unavailable", "integrations supervisor not configured")
|
|
|
return
|
|
|
@@ -980,12 +1087,12 @@ func (s *server) handleIntegrationDelete(w http.ResponseWriter, r *http.Request)
|
|
|
return
|
|
|
}
|
|
|
vendor, _ := s.vendorCatalog.Lookup(row.Vendor)
|
|
|
- if vendor.Mode == "local" {
|
|
|
+ if vendor.ServerManaged() {
|
|
|
if s.integrations != nil {
|
|
|
_ = s.integrations.Stop(slug)
|
|
|
_ = s.integrations.Cleanup(slug)
|
|
|
}
|
|
|
- } else if s.pool != nil {
|
|
|
+ } else if vendor.Mode == rintegration.ModeSSH && s.pool != nil {
|
|
|
_, _ = s.runIntegrationSSH(row, sshUninstallScript(vendor), 60*time.Second)
|
|
|
}
|
|
|
// #1708: la contraseña SSH del fichero compañero muere con la
|