This program tracks the logs updates and sends a notification via Telegram for specified patterns.
1.4K
The Log Notification app inspects logs in the /app/logs/ directory and checks new lines for patterns defined in the NOTIFICATION_PATTERNS environment variable. If a match is found, the app sends a notification via Telegram.
/app/logs/ directory for new lines.NOTIFICATION_PATTERNS).WARNINGEXCEPTIONERRORINFOYou can modify these patterns by setting the NOTIFICATION_PATTERNS environment variable.
If you prefer not to build the image yourself, you can pull the pre-built image from Docker Hub.
Pull the Docker Image:
docker pull nemanjaslijepcevic/log_notification
Run the Docker Container:
docker run -d \
-e TELEGRAM_BOT_TOKEN=<your-bot-token> \
-e TELEGRAM_CHAT_ID=<your-chat-id> \
-e NOTIFICATION_PATTERNS=<patterns-to-notify> \
-v /path/to/logs:/app/logs \
nemanjaslijepcevic/log_notification
<your-bot-token> with your Telegram bot's token.<your-chat-id> with the chat ID you want to send notifications to.<patterns-to-notify> with the patterns you want to monitor for in new log lines, separated by commas (e.g., ERROR,FAILURE)./path/to/logs directory on your host machine will be mounted to /app/logs in the container.To monitor multiple log files, just make sure all the log files are in the /path/to/logs directory on your host machine. The app will automatically monitor all .log files in the directory.
Verify the Container is Running:
docker ps
This will show the list of running containers. Ensure the log_notification container is listed.
If you prefer to build the Docker image yourself, follow these steps:
Build the Docker Image:
docker build -t log_notification .
Run the Docker Container:
docker run -d \
-e TELEGRAM_BOT_TOKEN=<your-bot-token> \
-e TELEGRAM_CHAT_ID=<your-chat-id> \
-e NOTIFICATION_PATTERNS=<patterns-to-notify> \
-v /path/to/logs:/app/logs \
log_notification
<your-bot-token> with your Telegram bot's token.<your-chat-id> with the chat ID you want to send notifications to.<patterns-to-notify> with the patterns you want to monitor for in new log lines, separated by commas (e.g., ERROR,FAILURE)./path/to/logs directory on your host machine will be mounted to /app/logs in the container.Verify the Container is Running:
docker ps
This will show the list of running containers. Ensure the log_notification container is listed.
Alternatively, you can deploy the app using Docker Compose.
Create a docker-compose.yml file:
version: '3.8'
services:
log_notification:
build: .
environment:
- TELEGRAM_BOT_TOKEN=${TELEGRAM_BOT_TOKEN}
- TELEGRAM_CHAT_ID=${TELEGRAM_CHAT_ID}
- NOTIFICATION_PATTERNS=${NOTIFICATION_PATTERNS}
volumes:
- ./logs:/app/logs
restart: always
Set Environment Variables:
You can set the required environment variables in a .env file:
TELEGRAM_BOT_TOKEN=<your-bot-token>
TELEGRAM_CHAT_ID=<your-chat-id>
NOTIFICATION_PATTERNS=<patterns-to-notify>
Or, export them in your terminal session:
export TELEGRAM_BOT_TOKEN=<your-bot-token>
export TELEGRAM_CHAT_ID=<your-chat-id>
export NOTIFICATION_PATTERNS=<patterns-to-notify>
Start the App with Docker Compose:
docker-compose up -d
This will build and start the container in detached mode.
Verify the Service:
docker-compose ps
You can check the logs for troubleshooting:
docker-compose logs
To stop the app running in Docker Compose, run:
docker-compose down
In Docker:
docker stop <container-id>
Make sure the logs are accessible in the /app/logs/ directory within the container. You can map this to a directory on your host machine to provide log files to the app.
For example, to map logs from your host system to the container:
-v /path/to/logs:/app/logs
The app will monitor all .log files inside the /app/logs/ directory.
To enable Telegram notifications:
TELEGRAM_BOT_TOKEN: Your bot token.TELEGRAM_CHAT_ID: Your chat ID.NOTIFICATION_PATTERNS: Comma-separated list of patterns to match in log lines. Default patterns are WARNING, EXCEPTION, ERROR, INFO.For example, if the NOTIFICATION_PATTERNS are set to ERROR,FAILURE, the app will monitor new lines in the log files and send a Telegram notification if any of the lines contain "ERROR" or "FAILURE".
docker-compose logs
Content type
Image
Digest
sha256:9fcce68c6…
Size
22.6 MB
Last updated
4 months ago
docker pull nemanjaslijepcevic/log_notification