Ver Fonte

fix(integrations): show the raw poll error and stop naming RouterOS (#2039) (#2040)

The offline hint for any vendor said the firmware was too old for the REST
API and named RouterOS 7, because a 404 maps to pusher_api_not_found whatever
the pusher. A UniFi console with a wrong port got that text and it pointed at
the wrong cause.

The raw poll failure was not exposed either: the card tooltip carried lastError,
which only holds install failures, so a reporter had nothing to paste. The
integration payload now includes pollError, read from the same log tail the
classifier already uses, and the card prints it under the hint as selectable
text.
Nacho há 2 semanas atrás
pai
commit
cc0e1ed5d3

+ 2 - 2
app/public/locales/en/translation.json

@@ -1391,8 +1391,8 @@
     "noVitalsTip": "Monitored through SNMP or a beacon: this unit does not report CPU, RAM or temperature",
     "noVitalsTip": "Monitored through SNMP or a beacon: this unit does not report CPU, RAM or temperature",
     "statusReason": {
     "statusReason": {
       "pusher_auth_failed": "Authentication rejected: the device does not accept the stored credentials (wrong user or password).",
       "pusher_auth_failed": "Authentication rejected: the device does not accept the stored credentials (wrong user or password).",
-      "pusher_api_not_found": "The API endpoint does not exist: the firmware is too old for the REST API (RouterOS 7 or newer required).",
-      "pusher_conn_refused": "Connection refused: the device is not answering on the API service or port (check www/www-ssl or api, and the firewall).",
+      "pusher_api_not_found": "The device does not expose the expected API endpoint at this address: check the host, the port and the scheme.",
+      "pusher_conn_refused": "Connection refused: the device is not answering on the API port. Check the service, the port and the firewall.",
       "pusher_stopped": "The integration pusher is stopped: start it from Settings > Integrations.",
       "pusher_stopped": "The integration pusher is stopped: start it from Settings > Integrations.",
       "pusher_error": "The integration pusher logged an error; check its details in Settings > Integrations."
       "pusher_error": "The integration pusher logged an error; check its details in Settings > Integrations."
     }
     }

+ 2 - 2
app/public/locales/es/translation.json

@@ -1391,8 +1391,8 @@
     "noVitalsTip": "Monitorizado por SNMP o beacon: este equipo no reporta CPU, RAM ni temperatura",
     "noVitalsTip": "Monitorizado por SNMP o beacon: este equipo no reporta CPU, RAM ni temperatura",
     "statusReason": {
     "statusReason": {
       "pusher_auth_failed": "Autenticación rechazada: el equipo no acepta las credenciales guardadas (usuario o contraseña incorrectos).",
       "pusher_auth_failed": "Autenticación rechazada: el equipo no acepta las credenciales guardadas (usuario o contraseña incorrectos).",
-      "pusher_api_not_found": "El endpoint de la API no existe: el firmware es demasiado viejo para el API REST (RouterOS necesita 7 o superior).",
-      "pusher_conn_refused": "Conexión rechazada: el equipo no responde en el servicio o puerto de la API (revisa www/www-ssl o api, y el firewall).",
+      "pusher_api_not_found": "El equipo no expone el endpoint esperado de la API en esta dirección: revisa el host, el puerto y el esquema.",
+      "pusher_conn_refused": "Conexión rechazada: el equipo no responde en el puerto de la API. Revisa el servicio, el puerto y el cortafuegos.",
       "pusher_stopped": "El pusher de la integración está parado: arráncalo desde Ajustes > Integraciones.",
       "pusher_stopped": "El pusher de la integración está parado: arráncalo desde Ajustes > Integraciones.",
       "pusher_error": "El pusher de la integración registró un error; revisa su detalle en Ajustes > Integraciones."
       "pusher_error": "El pusher de la integración registró un error; revisa su detalle en Ajustes > Integraciones."
     }
     }

+ 2 - 0
app/src/lib/integrationsApi.ts

@@ -17,6 +17,8 @@ export interface Integration {
   lastError: string
   lastError: string
   /** Código estable del motivo offline (#1718): vacío si empuja o está pausada. */
   /** Código estable del motivo offline (#1718): vacío si empuja o está pausada. */
   offlineReason?: string
   offlineReason?: string
+  /** Último fallo de poll del pusher, en crudo (#2039). */
+  pollError?: string
   lastStartMs: number
   lastStartMs: number
   lastPushMs: number
   lastPushMs: number
   fresh: boolean
   fresh: boolean

+ 10 - 2
app/src/pages/Integrations.tsx

@@ -674,15 +674,23 @@ export default function Integrations({
                 </div>
                 </div>
                 {/* #1718: motivo offline clasificado (mismos códigos que la
                 {/* #1718: motivo offline clasificado (mismos códigos que la
                     tarjeta y el detalle). El tooltip lleva el error crudo del
                     tarjeta y el detalle). El tooltip lleva el error crudo del
-                    pusher para quien quiera el detalle técnico. */}
+                    pusher para quien quiera el detalle técnico.
+                    #2039: el fallo de poll en crudo se pinta debajo, porque un
+                    tooltip no se puede copiar y era el único dato que se pide
+                    en cada reporte. */}
                 {it.offlineReason && (
                 {it.offlineReason && (
                   <div
                   <div
-                    title={it.lastError || undefined}
                     className="mt-1.5 text-caption text-danger"
                     className="mt-1.5 text-caption text-danger"
+                    title={it.lastError || it.pollError || undefined}
                   >
                   >
                     {t(`routers.statusReason.${it.offlineReason}`, { defaultValue: it.offlineReason })}
                     {t(`routers.statusReason.${it.offlineReason}`, { defaultValue: it.offlineReason })}
                   </div>
                   </div>
                 )}
                 )}
+                {it.pollError && (
+                  <div className="mt-0.5 font-mono text-[11px] leading-snug break-all text-text-muted select-all">
+                    {it.pollError}
+                  </div>
+                )}
                 {editing?.slug === it.slug && (
                 {editing?.slug === it.slug && (
                   <form onSubmit={(e) => void submitEdit(e)} className="mt-3 border-t border-border pt-3">
                   <form onSubmit={(e) => void submitEdit(e)} className="mt-3 border-t border-border pt-3">
                     <div className="text-label uppercase text-text-muted">{t('integrations.edit.title')}</div>
                     <div className="text-label uppercase text-text-muted">{t('integrations.edit.title')}</div>

+ 25 - 15
server-go/internal/httpapi/integrations.go

@@ -40,9 +40,13 @@ type integrationItem struct {
 	// no está empujando (mismos códigos que la tarjeta y el detalle desde
 	// no está empujando (mismos códigos que la tarjeta y el detalle desde
 	// #1714). Vacío si está empujando, pausada o sin señal clara.
 	// #1714). Vacío si está empujando, pausada o sin señal clara.
 	OfflineReason string `json:"offlineReason,omitempty"`
 	OfflineReason string `json:"offlineReason,omitempty"`
-	LastStartMs   int64  `json:"lastStartMs"`
-	LastPushMs    int64  `json:"lastPushMs"`
-	Fresh         bool   `json:"fresh"`
+	// PollError (#2039): último fallo de poll del pusher, tal cual lo escribió
+	// en su log. Es el dato que se pide en cada reporte y no llegaba a la UI,
+	// así que el usuario solo veía una pista clasificada.
+	PollError   string `json:"pollError,omitempty"`
+	LastStartMs int64  `json:"lastStartMs"`
+	LastPushMs  int64  `json:"lastPushMs"`
+	Fresh       bool   `json:"fresh"`
 }
 }
 
 
 // vendorView es la vista HTTP del manifiesto de un vendor.
 // vendorView es la vista HTTP del manifiesto de un vendor.
@@ -159,41 +163,47 @@ func (s *server) integrationItemOf(row rintegration.Row) integrationItem {
 	if state == "running" && lastPush > 0 && row.IntervalS > 0 && !fresh {
 	if state == "running" && lastPush > 0 && row.IntervalS > 0 && !fresh {
 		state = "stale"
 		state = "stale"
 	}
 	}
+	reason, pollErr := s.integrationOffline(row, fresh)
 	return integrationItem{
 	return integrationItem{
 		Slug: row.Slug, Vendor: row.Vendor, Mode: row.Mode, Host: row.Host,
 		Slug: row.Slug, Vendor: row.Vendor, Mode: row.Mode, Host: row.Host,
 		Username: row.Username, Version: row.Version, Arch: row.Arch,
 		Username: row.Username, Version: row.Version, Arch: row.Arch,
 		IntervalS: row.IntervalS, Enabled: row.Enabled, State: state,
 		IntervalS: row.IntervalS, Enabled: row.Enabled, State: state,
 		LastError: row.LastError, LastStartMs: row.LastStartMs,
 		LastError: row.LastError, LastStartMs: row.LastStartMs,
 		LastPushMs: lastPush, Fresh: fresh,
 		LastPushMs: lastPush, Fresh: fresh,
-		OfflineReason: s.integrationOfflineReason(row, fresh),
+		OfflineReason: reason,
+		PollError:     pollErr,
 	}
 	}
 }
 }
 
 
-// integrationOfflineReason (#1718) clasifica por qué una integración no está
+// integrationOffline (#1718) clasifica por qué una integración no está
 // empujando, con los mismos códigos y la misma precedencia que StatusReasons
 // empujando, con los mismos códigos y la misma precedencia que StatusReasons
 // en el paquete rintegration (que alimenta la tarjeta y el detalle): parada
 // en el paquete rintegration (que alimenta la tarjeta y el detalle): parada
 // explícita, último error de instalación, o el log del pusher para fallos de
 // explícita, último error de instalación, o el log del pusher para fallos de
 // poll. Pausada o fresca no tienen motivo.
 // poll. Pausada o fresca no tienen motivo.
-func (s *server) integrationOfflineReason(row rintegration.Row, fresh bool) string {
+//
+// Devuelve además el último fallo de poll en crudo (#2039): la UI lo muestra
+// para que un reporte pueda traer el mensaje real en vez de solo la pista
+// clasificada.
+func (s *server) integrationOffline(row rintegration.Row, fresh bool) (code, pollErr string) {
 	if !row.Enabled {
 	if !row.Enabled {
-		return ""
+		return "", ""
 	}
 	}
 	if row.State == "stopped" {
 	if row.State == "stopped" {
-		return rintegration.ReasonStopped
+		return rintegration.ReasonStopped, ""
 	}
 	}
 	if fresh {
 	if fresh {
-		return ""
+		return "", ""
+	}
+	if s.integrations != nil {
+		pollErr = s.integrations.LastPollError(row.Slug)
 	}
 	}
-	code := ""
 	if row.State == "error" && row.LastError != "" {
 	if row.State == "error" && row.LastError != "" {
 		code = rintegration.ClassifyPollError(row.LastError)
 		code = rintegration.ClassifyPollError(row.LastError)
 	}
 	}
-	if (code == "" || code == rintegration.ReasonError) && s.integrations != nil {
-		if msg := s.integrations.LastPollError(row.Slug); msg != "" {
-			code = rintegration.ClassifyPollError(msg)
-		}
+	if (code == "" || code == rintegration.ReasonError) && pollErr != "" {
+		code = rintegration.ClassifyPollError(pollErr)
 	}
 	}
-	return code
+	return code, pollErr
 }
 }
 
 
 func (s *server) integrationList() []integrationItem {
 func (s *server) integrationList() []integrationItem {

+ 10 - 0
server-go/internal/httpapi/integrations_reason_test.go

@@ -93,4 +93,14 @@ func TestIntegrationsOfflineReasonEnFilas(t *testing.T) {
 			t.Fatalf("%s: offlineReason = %q, want %q (item: %v)", slug, got, code, it)
 			t.Fatalf("%s: offlineReason = %q, want %q (item: %v)", slug, got, code, it)
 		}
 		}
 	}
 	}
+
+	// #2039: el fallo de poll viaja en crudo, que es lo que un reporte puede
+	// pegar. Sin fallo en el log no hay nada que enseñar.
+	log404 := items["log-404"]
+	if got, _ := log404["pollError"].(string); got != "404 Not Found: no REST API" {
+		t.Fatalf("log-404: pollError = %q, want the raw log message (item: %v)", got, log404)
+	}
+	if got, _ := items["stale-noerr"]["pollError"].(string); got != "" {
+		t.Fatalf("stale-noerr: pollError = %q, want empty", got)
+	}
 }
 }

+ 5 - 3
server-go/internal/rintegration/reason.go

@@ -115,9 +115,11 @@ func slogErrValue(line string) string {
 
 
 // ClassifyPollError mapea el texto de error de un pusher a un código estable
 // ClassifyPollError mapea el texto de error de un pusher a un código estable
 // de motivo. Los patrones cubren los fallos observables de un poll: credenciales
 // de motivo. Los patrones cubren los fallos observables de un poll: credenciales
-// rechazadas (401/unauthorized), endpoint REST ausente (404: firmware viejo,
-// el REST llega en RouterOS 7) y familia de conexión (refused/timeout/route).
-// Cualquier otro error no vacío cae al código genérico.
+// rechazadas (401/unauthorized), endpoint de la API ausente (404: firmware viejo
+// en RouterOS, puerto o prefijo equivocados en cualquier vendor) y familia de
+// conexión (refused/timeout/route). El código es el mismo para todos los
+// vendors, así que el texto que la UI pone a cada uno no puede nombrar uno en
+// concreto (#2039). Cualquier otro error no vacío cae al código genérico.
 func ClassifyPollError(msg string) string {
 func ClassifyPollError(msg string) string {
 	m := strings.ToLower(msg)
 	m := strings.ToLower(msg)
 	switch {
 	switch {