Commit Graph
10 Commits
Author SHA1 Message Date
Lizandro Guarnizo 0cf7c6d279 up 2026-05-21 22:37:31 -05:00
Lizandro GuarnizoandCopilot 6cca8e6fcd fix: reactividad Alpine ping — estado en cx directamente
Alpine v3 NO puede rastrear accesos dinámicos pingCargando[cx.ID]
dentro de x-for porque no sabe qué key observar por item.

Solución: estado de ping embebido en cada objeto cx:
- abrirModal inyecta _pingCargando:false y _pingResultado:null en cada cx
- hacerPing muta cx._pingCargando / cx._pingResultado directamente
- template usa cx._pingCargando y cx._pingResultado (proxy reactivo del x-for)

Esto garantiza que el spinner, el botón deshabilitado y el resultado
del ping se actualicen correctamente para cada card.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-21 12:06:00 -05:00
Lizandro GuarnizoandCopilot 2779c0a15d fix: ping real de BD + campo Host en ConxDb + reactividad Alpine
Problema raíz:
1. El ping TCP usaba Servidor.IpServidor → fallaba si la BD solo escucha
   en localhost del servidor remoto (comportamiento normal en producción)
2. La reactividad Alpine v3.13 no detectaba keys nuevas en objeto vacío {}
   dentro de x-for loops, spinner nunca aparecía

Cambios:
- pkg/models/conx_db.go: nuevo campo Host (vacío = usa Servidor.IpServidor)
  + método HostEfectivo() como fuente única de verdad para host
- pkg/services/query_runner_service.go: todos los puntos (openDynamicDB,
  openDynamicDBWithName, redisConnect, mongoURI) usan c.HostEfectivo()
- rest/controllers/servidor_controller.go: PingConexion reescrito —
  primero prueba conexión real a la BD (no solo TCP), si falla prueba TCP,
  devuelve host+puerto testeado y mensajes de error descriptivos
- servidor_dashboard.html: hacerPing usa spread-replace para forzar
  reactividad + $nextTick, resultado muestra host:puerto testeado y
  mensaje de error completo en múltiples líneas

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-21 11:56:12 -05:00
Lizandro GuarnizoandCopilot d9d3f8a5eb feat: sistema de agente ligero para monitoreo de servidores
Backend:
- Servidor model: AgentToken, AgentLastSeen, MetricasJson nuevos campos
- AgentHeartbeat: endpoint público POST /agent/heartbeat (auth por token)
- GenerateAgentToken: endpoint protegido POST /app/servidor/:id/agent-token
- Ruta pública /agent/install.sh sirve el script de instalación

Agente Go (agent/):
- agent/main.go: binario independiente con gopsutil
  - Recolecta RAM, CPU, Disco, Uptime, OS, Load average
  - Lee agent.yml o flags --api-url / --token
  - Envía POST a /agent/heartbeat cada N segundos
  - Instala como servicio systemd via install.sh
- agent/go.mod: módulo independiente (usite-agent)
- agent/agent.yml.sample: configuración de ejemplo
- agent/install.sh: instalador en 1 curl para Linux (systemd)

Frontend servidor_dashboard.html:
- Cards: badge ● En línea / ● Fuera / ○ Sin agente
- Barras de progreso live: RAM%, CPU%, Disco%
- Valores: GB usado/total, núcleos, uptime, OS real
- Tiempo desde último reporte
- Botón 'Agente' en cada card → modal de configuración
- Modal agente: estado, token con copy, comando curl 1 línea,
  instalación manual/avanzada con collapse, métricas actuales

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-21 11:29:24 -05:00
Lizandro GuarnizoandCopilot f52e266527 fix: corregir ping - mutación directa y manejo de cx.ID || cx.id
- Cambia spread+reassign por mutación directa (this.pingCargando[id] = true)
  para garantizar reactividad correcta en Alpine.js 3.x
- Usa (cx.ID || cx.id) en toda la plantilla para compatibilidad con
  ambos formatos de serialización JSON de GORM
- Agrega type="button" y @click.stop en el botón de verificar
- Maneja respuestas HTTP no-OK con mensaje de error explícito
- Muestra mensaje de error real del catch en la UI

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-21 11:07:39 -05:00
Lizandro GuarnizoandCopilot 194db3e9ed fix: mejorar UX del ping en servidor_dashboard
- Mueve el resultado del ping directamente bajo los datos de la BD
- Muestra mensaje de error cuando falla la conexión (usa campo error del backend)
- Spinner y texto 'Probando...' durante la espera
- Resultado verde/rojo inline con ✓/✗ y tiempo/mensaje de error
- Etiqueta del botón cambia a 'Verificar' (más descriptivo que 'Ping')

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-21 10:48:40 -05:00
Lizandro GuarnizoandCopilot c834e40e83 fix(servidor-dashboard): show DB connection count on server cards
- GetServidor: query conx_count per server with GROUP BY and attach to response
- servidor_dashboard.html: use conx_count from API (fallback to _conexiones.length)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-21 10:25:18 -05:00
Lizandro GuarnizoandCopilot 03ccc75337 Fix servidor dashboard: correct all field names to match models
All fields were using wrong names (Go struct names instead of JSON tags):
- servidor.Nombre → servidor.nombre
- servidor.IP → servidor.ip_servidor
- servidor.TipoServidor → servidor.tipo_servidor
- servidor.ProvServidor → servidor.prov_servidor
- servidor.Ram → servidor.ram
- servidor.CPU → servidor.nucleos (correct field)
- servidor.Almacenamiento → servidor.disco
- servidor.SO → servidor.so
- servidor.FechaExpiracion → servidor.vencimiento
- servidor.Activo → removed (field does not exist)
- servidor.Descripcion → removed (field does not exist)

For ConxDb:
- conexion.Nombre → removed (field does not exist)
- conexion.Host → conexion.servidor.ip_servidor (from preloaded relation)
- conexion.Puerto → conexion.puerto
- conexion.Usuario → conexion.usuario
- conexion.TipoDb → conexion.tipo_db
- conexion.Estado → removed (field does not exist)
- conexion.Version → removed (field does not exist)

Also improved UI: loading skeleton, better card layout, ping badges inline.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-21 10:07:06 -05:00
Lizandro GuarnizoandCopilot 7d02add55e Fix dashboard URLs: remove /api prefix from fetch calls
Routes are registered under /app (web group), not /api/app.
The requests were hitting the JWT-protected API group causing 'Invalid Attempt' error.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-21 09:58:21 -05:00
Lizandro GuarnizoandCopilot 29820c8706 Add Servidor Dashboard with connection monitoring
- Created servidor_dashboard.html with beautiful visual dashboard
- Shows all servers in grid cards with basic info
- Click button opens detailed modal with:
  - Server full information (IP, CPU, RAM, Storage, OS, Expiration)
  - All connected databases in a clean diagram layout
  - Database connection status (active/inactive)
  - Connection details (Host, Port, User, Type)
  - Ping button to test connection with response time
  - View Connection button to open query-runner
- Backend updates:
  - Added ServidorDashboard() controller to render the dashboard view
  - Added GetServidorDashboard() API endpoint to fetch server + connections
  - Added PingConexion() endpoint to test database connections (TCP + DB test)
  - Color-coded status badges and database type indicators
  - Responsive design for mobile and desktop
- Routes:
  - GET /app/servidor-dashboard (render view)
  - GET /api/app/servidor-dashboard/:id (get server details API)
  - GET /api/app/conx-ping/:id (ping connection endpoint)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-21 08:49:18 -05:00