diff --git a/docs/DIARIO_DESARROLLO.md b/docs/DIARIO_DESARROLLO.md index 97a3460..0a48eb8 100644 --- a/docs/DIARIO_DESARROLLO.md +++ b/docs/DIARIO_DESARROLLO.md @@ -1,5 +1,98 @@ # Diario de Desarrollo - service-monitor +## 2025-12-08 - Sesión 3: Migración Zig 0.15 + SMTP STARTTLS + +### Contexto +- Migrar de Zig 0.13 a 0.15.2 +- Implementar SMTP con STARTTLS para notificaciones por email + +### Migración a Zig 0.15.2 + +**Cambios requeridos:** + +| Componente | Antes (0.13) | Después (0.15) | +|------------|--------------|----------------| +| build.zig | `root_source_file` | `root_module` con `b.createModule()` | +| stdout | `std.io.getStdOut().writer()` | `std.fs.File.stdout().deprecatedWriter()` | +| ArrayList | `std.ArrayList(T).init(alloc)` | `std.array_list.Managed(T).init(alloc)` | +| file.reader() | sin args | requiere buffer, usar `deprecatedReader()` | +| HTTP Client | `client.open()` + `send()` + `wait()` | `client.fetch()` | +| sleep | `std.time.sleep()` | `std.Thread.sleep()` | + +**Commits:** +- `f31ce95` - Migración a Zig 0.15.2 + +### SMTP con STARTTLS + +**Problema inicial:** +Se intentó implementar TLS nativo con `std.crypto.tls.Client`, pero la nueva API de I/O +de Zig 0.15 resultó demasiado compleja (cambios en Reader/Writer interfaces). + +**Solución adoptada:** +Usar curl como subprocess, igual que para Telegram. Ventajas: +- curl maneja STARTTLS con `--ssl-reqd` transparentemente +- Código mucho más simple y mantenible +- Fiable y probado + +**Configuración SMTP (Mailbox.org):** +``` +Host: smtp.mailbox.org +Puerto: 587 (STARTTLS) +Usuario: reugenio@mailbox.org +Password: App password (en NOTIFICACIONES.md) +``` + +**Commits:** +- `4a9d0e6` - SMTP con STARTTLS via curl + +### Estado Final del Proyecto + +**Todas las funcionalidades implementadas:** +- ✅ Verificación HTTP/HTTPS +- ✅ Verificación TCP +- ✅ Modo watch (loop continuo) +- ✅ Modo daemon (background) +- ✅ Log a archivo +- ✅ Config externo (CSV) +- ✅ Notificación desktop (notify-send) +- ✅ Notificación Telegram (Bot API via curl) +- ✅ Notificación Email (SMTP STARTTLS via curl) + +**Estructura final:** +``` +service-monitor/ +├── build.zig +├── CLAUDE.md +├── services.conf +├── docs/ +│ ├── DIARIO_DESARROLLO.md +│ └── PROYECTO_COMPLETO.md +└── src/ + ├── main.zig # Entry point + CLI + ├── http.zig # Cliente HTTP (fetch API) + ├── tcp.zig # Verificación TCP + ├── config.zig # Parser CSV + ├── notify.zig # notify-send + ├── daemon.zig # fork + setsid + ├── smtp.zig # SMTP via curl + └── telegram.zig # Bot API via curl +``` + +--- + +## 2025-12-07 - Sesión 2: Fases 2 y 3 + +### Implementado +- Modo watch con intervalo configurable +- Modo daemon con fork/setsid +- Log a archivo +- Config externo (services.conf) +- Notificaciones desktop (notify-send) +- Notificaciones Telegram (Bot API) +- SMTP básico (sin STARTTLS) + +--- + ## 2025-12-07 - Sesión 1: Inicio proyecto ### Contexto @@ -40,10 +133,6 @@ service-monitor/ - Código idiomático Zig (snake_case, error handling explícito) - Preparado para open source -### Pendiente - Fases 2 y 3 -- [ ] Fase 2: Modo daemon + intervalo configurable + logs -- [ ] Fase 3: Notificaciones (libnotify, webhook, email) - ### Comandos ```bash zig build # Compilar diff --git a/docs/PROYECTO_COMPLETO.md b/docs/PROYECTO_COMPLETO.md index 688a0cf..7f220d5 100644 --- a/docs/PROYECTO_COMPLETO.md +++ b/docs/PROYECTO_COMPLETO.md @@ -1,7 +1,7 @@ # Service Monitor - Documentación Completa > **Fecha**: 2025-12-08 -> **Versión**: 1.1 +> **Versión**: 1.2 > **Lenguaje**: Zig 0.15.2 > **Repositorio**: https://git.reugenio.com/reugenio/service-monitor @@ -20,7 +20,7 @@ Monitor de servicios HTTP y TCP para verificar disponibilidad del servidor Hetzn | Log a archivo | ✅ | Append mode, timestamps ISO | | Config externo | ✅ | Archivo CSV simple | | Notificación desktop | ✅ | notify-send (Linux) | -| Notificación email | ✅ | SMTP con AUTH LOGIN (sin TLS) | +| Notificación email | ✅ | SMTP con STARTTLS via curl | | Notificación Telegram | ✅ | Bot API via curl | ## Estructura del Proyecto @@ -246,11 +246,11 @@ OK Menzuri (456ms) ### smtp.zig -- Protocolo SMTP completo (RFC 5321) -- Comandos: EHLO, AUTH LOGIN, MAIL FROM, RCPT TO, DATA, QUIT -- Autenticación Base64 -- Múltiples destinatarios -- **Limitación**: No soporta STARTTLS (usar puerto 25 o servidores sin TLS) +- Implementación SMTP usando curl como subprocess +- Soporte completo STARTTLS (puerto 587) +- Curl maneja TLS de forma transparente +- Autenticación con usuario/contraseña +- Compatible con Gmail, Mailbox.org, Outlook, etc. ### telegram.zig @@ -278,10 +278,12 @@ OK Menzuri (456ms) | 5a17d74 | Fase 3: Notificaciones desktop | | 655dcb8 | Daemon mode + config externo | | a011d9e | SMTP y Telegram | +| f31ce95 | Migración a Zig 0.15.2 | +| 4a9d0e6 | SMTP con STARTTLS via curl | ## Pendiente -- [ ] SMTP con STARTTLS (para Gmail/Outlook) +- [x] ~~SMTP con STARTTLS~~ (completado 2025-12-08 via curl) - [x] ~~Migración a Zig 0.15~~ (completado 2025-12-08) - [ ] Notificación de recuperación (servicio vuelve a funcionar) - [ ] Rate limiting de notificaciones (evitar spam) @@ -300,9 +302,40 @@ La migración a Zig 0.15.2 requirió los siguientes cambios: | HTTP Client | `client.open()` + `send()` + `wait()` | `client.fetch()` | | sleep | `std.time.sleep()` | `std.Thread.sleep()` | +## Notas de Implementación SMTP con STARTTLS + +La implementación nativa de TLS en Zig 0.15 resultó compleja debido a cambios en la API de I/O. +Se optó por usar curl como subprocess, que ofrece: + +- **Simplicidad**: curl maneja STARTTLS transparentemente con `--ssl-reqd` +- **Fiabilidad**: curl es estable y bien probado +- **Compatibilidad**: Funciona con cualquier servidor SMTP moderno +- **Consistencia**: Mismo enfoque que Telegram (también usa curl) + +```bash +# Equivalente manual: +echo -e "From: user@mailbox.org\r\nTo: dest@example.com\r\nSubject: Test\r\n\r\nBody" | \ +curl -s --url "smtp://smtp.mailbox.org:587" --ssl-reqd \ + -u "user@mailbox.org:password" \ + --mail-from "" \ + --mail-rcpt "" -T - +``` + +## Configuración SMTP Actual + +| Parámetro | Valor | +|-----------|-------| +| Servidor | smtp.mailbox.org | +| Puerto | 587 (STARTTLS) | +| Usuario | reugenio@mailbox.org | +| Tipo password | App password (solo envío) | + +**Nota**: Credenciales completas en `TEAM_STANDARDS/INFRASTRUCTURE/NOTIFICACIONES.md` + ## Referencias - Zig 0.15 stdlib: https://ziglang.org/documentation/0.15.0/std/ - SMTP RFC 5321: https://tools.ietf.org/html/rfc5321 - Telegram Bot API: https://core.telegram.org/bots/api - Guía Zig 0.15: /mnt/cello2/arno/re/recode/TEAM_STANDARDS/INFRASTRUCTURE/ZIG_0.15_GUIA.md +- Credenciales: /mnt/cello2/arno/re/recode/TEAM_STANDARDS/INFRASTRUCTURE/NOTIFICACIONES.md