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: environment:
- TZ=America/Havana - TZ=America/Havana
- PYTHONUNBUFFERED=1 - PYTHONUNBUFFERED=1
# Pasa el nombre del host al contenedor del notificador - WATCHTOWER_NOTIFICATION_REPORT_HOSTNAME=Servidor-Easypanel
- WATCHTOWER_NOTIFICATIONS_HOSTNAME=Servidor-Easypanel - TELEGRAM_BOT_TOKEN=7676713419:AAG-tfwzgrA9JaU5xNjvG5iBlFeZpz2ahiY
- TELEGRAM_CHAT_ID=7940222048
volumes: volumes:
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock
depends_on: depends_on:
@ -30,7 +31,7 @@ services:
- WATCHTOWER_INCLUDE_STOPPED=true - WATCHTOWER_INCLUDE_STOPPED=true
- WATCHTOWER_POLL_INTERVAL=86400 - WATCHTOWER_POLL_INTERVAL=86400
- WATCHTOWER_DEBUG=false - WATCHTOWER_DEBUG=false
- WATCHTOWER_NOTIFICATIONS_HOSTNAME=Servidor-Easypanel - WATCHTOWER_NOTIFICATION_REPORT_HOSTNAME=Servidor-Easypanel
- WATCHTOWER_NOTIFICATION_REPORT=true - WATCHTOWER_NOTIFICATION_REPORT=true
volumes: volumes:
- /var/run/docker.sock:/var/run/docker.sock - /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 Monitorea los logs de Watchtower y envía notificaciones detalladas a Telegram
""" """
import os
import docker import docker
import requests import requests
import time
import re import re
import os
from datetime import datetime from datetime import datetime
from threading import Thread from threading import Thread
import logging import logging
import time
# Configuración # Configuración
TELEGRAM_BOT_TOKEN = "7676713419:AAG-tfwzgrA9JaU5xNjvG5iBlFeZpz2ahiY" # Obtener el token y el chat ID de las variables de entorno
TELEGRAM_CHAT_ID = "7940222048" TELEGRAM_BOT_TOKEN = os.environ.get("TELEGRAM_BOT_TOKEN")
TELEGRAM_CHAT_ID = os.environ.get("TELEGRAM_CHAT_ID")
WATCHTOWER_CONTAINER_NAME = "watchtower" WATCHTOWER_CONTAINER_NAME = "watchtower"
# Obtener el nombre del host de una variable de entorno, con un valor por defecto HOSTNAME = os.environ.get("WATCHTOWER_NOTIFICATION_REPORT_HOSTNAME", "Servidor-Easypanel")
HOSTNAME = os.environ.get("WATCHTOWER_NOTIFICATIONS_HOSTNAME", "Servidor-Easypanel")
# Configurar logging # Configurar logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@ -33,6 +33,9 @@ class WatchtowerTelegramNotifier:
def send_telegram_message(self, message): def send_telegram_message(self, message):
"""Envía mensaje a Telegram""" """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: try:
payload = { payload = {
'chat_id': TELEGRAM_CHAT_ID, 'chat_id': TELEGRAM_CHAT_ID,
@ -44,7 +47,7 @@ class WatchtowerTelegramNotifier:
logger.info("✅ Mensaje enviado a Telegram exitosamente") logger.info("✅ Mensaje enviado a Telegram exitosamente")
return True return True
else: else:
logger.error(f"❌ Error enviando mensaje: {response.status_code}") logger.error(f"❌ Error enviando mensaje: {response.status_code} - {response.text}")
return False return False
except Exception as e: except Exception as e:
logger.error(f"❌ Error conectando a Telegram: {e}") logger.error(f"❌ Error conectando a Telegram: {e}")
@ -228,7 +231,12 @@ def main():
notifier = WatchtowerTelegramNotifier() 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>" 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): if notifier.send_telegram_message(test_message):