actualizando

This commit is contained in:
Daniel Fernandez Sotolongo
2025-09-27 12:41:22 -04:00
parent 89cae3d090
commit b9ee4093e2
2 changed files with 20 additions and 11 deletions

View File

@ -10,8 +10,9 @@ services:
environment:
- TZ=America/Havana
- PYTHONUNBUFFERED=1
# Pasa el nombre del host al contenedor del notificador
- WATCHTOWER_NOTIFICATIONS_HOSTNAME=Servidor-Easypanel
- WATCHTOWER_NOTIFICATION_REPORT_HOSTNAME=Servidor-Easypanel
- TELEGRAM_BOT_TOKEN=7676713419:AAG-tfwzgrA9JaU5xNjvG5iBlFeZpz2ahiY
- TELEGRAM_CHAT_ID=7940222048
volumes:
- /var/run/docker.sock:/var/run/docker.sock
depends_on:
@ -30,7 +31,7 @@ services:
- WATCHTOWER_INCLUDE_STOPPED=true
- WATCHTOWER_POLL_INTERVAL=86400
- WATCHTOWER_DEBUG=false
- WATCHTOWER_NOTIFICATIONS_HOSTNAME=Servidor-Easypanel
- WATCHTOWER_NOTIFICATION_REPORT_HOSTNAME=Servidor-Easypanel
- WATCHTOWER_NOTIFICATION_REPORT=true
volumes:
- /var/run/docker.sock:/var/run/docker.sock

View File

@ -4,21 +4,21 @@ Watchtower Telegram Notifier - Notificaciones personalizadas en español
Monitorea los logs de Watchtower y envía notificaciones detalladas a Telegram
"""
import os
import docker
import requests
import time
import re
import os
from datetime import datetime
from threading import Thread
import logging
import time
# Configuración
TELEGRAM_BOT_TOKEN = "7676713419:AAG-tfwzgrA9JaU5xNjvG5iBlFeZpz2ahiY"
TELEGRAM_CHAT_ID = "7940222048"
# Obtener el token y el chat ID de las variables de entorno
TELEGRAM_BOT_TOKEN = os.environ.get("TELEGRAM_BOT_TOKEN")
TELEGRAM_CHAT_ID = os.environ.get("TELEGRAM_CHAT_ID")
WATCHTOWER_CONTAINER_NAME = "watchtower"
# Obtener el nombre del host de una variable de entorno, con un valor por defecto
HOSTNAME = os.environ.get("WATCHTOWER_NOTIFICATIONS_HOSTNAME", "Servidor-Easypanel")
HOSTNAME = os.environ.get("WATCHTOWER_NOTIFICATION_REPORT_HOSTNAME", "Servidor-Easypanel")
# Configurar logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@ -33,6 +33,9 @@ class WatchtowerTelegramNotifier:
def send_telegram_message(self, message):
"""Envía mensaje a Telegram"""
if not TELEGRAM_BOT_TOKEN or not TELEGRAM_CHAT_ID:
logger.error("❌ ERROR: TELEGRAM_BOT_TOKEN o TELEGRAM_CHAT_ID no están definidos.")
return False
try:
payload = {
'chat_id': TELEGRAM_CHAT_ID,
@ -44,7 +47,7 @@ class WatchtowerTelegramNotifier:
logger.info("✅ Mensaje enviado a Telegram exitosamente")
return True
else:
logger.error(f"❌ Error enviando mensaje: {response.status_code}")
logger.error(f"❌ Error enviando mensaje: {response.status_code} - {response.text}")
return False
except Exception as e:
logger.error(f"❌ Error conectando a Telegram: {e}")
@ -228,7 +231,12 @@ def main():
notifier = WatchtowerTelegramNotifier()
# Verificar conexión a Telegram
# Verificar si las credenciales están presentes
if not TELEGRAM_BOT_TOKEN or not TELEGRAM_CHAT_ID:
logger.error("❌ Error: Variables de entorno de Telegram no encontradas. Asegúrate de pasarlas en el docker-compose.yaml.")
return
# Enviar mensaje de verificación inicial
test_message = f"🤖 <b>Bot de notificaciones iniciado</b>\n\n🏠 <b>Servidor:</b> {HOSTNAME}\n📅 <b>Fecha:</b> {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n\n✅ <b>Conexión establecida correctamente</b>"
if notifier.send_telegram_message(test_message):