Ntfy Push Notifications
What is Ntfy Push Notifications?
Ntfy is a powerful yet simple server for sending and receiving push notifications. It allows you to publish notifications from any system or service to your devices using an easy-to-use HTTP API. Ntfy is particularly handy for setting up notifications for events like system failures, completed tasks, or any important updates that you want to monitor in real-time.
Why Use Ntfy?
Ntfy stands out due to its simplicity and flexibility. Itโs an open-source project that you can self-host, meaning you retain full control over your data. Ntfy works seamlessly with services like IFTTT, Home Assistant, and others, making it an ideal choice for those who prefer to have notifications sent directly to their devices without relying on third-party services.
Key Advantages:
- Self-hosted: Complete control over your notifications and data.
- Easy Integration: Works with various services and systems via a simple HTTP API.
- Customizable: You can tailor notifications to fit your specific needs.
Use Cases of Ntfy
- System Monitoring: Receive real-time alerts when your servers encounter issues.
- Task Automation: Get notified when long-running tasks are completed.
- Home Automation: Integrate with smart home systems like Home Assistant to receive alerts for events such as doors opening or devices malfunctioning.
- Personal Projects: Keep track of your projects or scripts with instant notifications when something important happens.
Prerequisites
- Docker Engine and Docker Compose packages are installed and running.
- A non-root user with Docker privileges.
if you dont want to use the docker you can check the binaries releases page for binaries and deb/rpm packages.
Setting Up the Ntfy Server
Create the Directory Structure
To keep things organized, create a dedicated directory for Ntfy. Hereโs the file structure:
1
2
mkdir ~/docker/ntfy/{etc/ntfy,var/cache/ntfy}
touch ~/docker/ntfy/docker-compose.yml
1
2
3
4
5
6
7
8
๐ ntfy
|--๐ docker-compose.yml
|--๐ etc
| `--๐ ntfy
| `--๐ server.yml
`--๐ var
`--๐ cache
`--๐ ntfy
Docker Configuration
With the directory structure in place, letโs edit the docker-compose.yml file using your favorite text editor. Hereโs an example configuration:
sample docker.yaml
:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
services:
ntfy:
image: binwiederhier/ntfy
container_name: ntfy
command:
- serve
environment:
- TZ=Asia/Kolkata
volumes:
- ./var/cache/ntfy:/var/cache/ntfy
- ./etc/ntfy:/etc/ntfy
ports:
- 80:80
#- 9090:9090 # to enable metrics
restart: unless-stopped
networks:
- proxy
# labels:
# - "traefik.enable=true"
# - "traefik.http.routers.ntfy.entrypoints=http"
# - "traefik.http.routers.ntfy.rule=Host(`ntfyalertmaster.secsys.pro`)"
# - "traefik.http.middlewares.ntfy-https-redirect.redirectscheme.scheme=https"
# - "traefik.http.routers.ntfy.middlewares=ntfy-https-redirect"
# - "traefik.http.routers.ntfy-secure.entrypoints=https"
# - "traefik.http.routers.ntfy-secure.rule=Host(`ntfyalertmaster.secsys.pro`)"
# - "traefik.http.routers.ntfy-secure.tls=true"
# - "traefik.http.routers.ntfy-secure.service=ntfy"
# - "traefik.http.services.ntfy.loadbalancer.server.port=80"
# - "traefik.docker.network=proxy"
# - "traefik.http.routers.ntfy-secure.middlewares=authelia@file"
# - "com.centurylinklabs.watchtower.enable=true"
networks:
proxy:
external: true
sample server.yml
:
1
2
3
4
5
6
7
8
9
10
base-url: "https://ntfy.sh"
attachment-cache-dir: "/var/cache/ntfy/attachments"
attachment-total-size-limit: "5G"
attachment-file-size-limit: "15M"
attachment-expiry-duration: "3h"
visitor-attachment-total-size-limit: "100M"
visitor-attachment-daily-bandwidth-limit: "500M"
# Monitoring metrics
# enable-metrics: true
# metrics-listen-http: "$IP:9090"
enabling Monitoring metrics
you can scrape the metrics by using Grafana by scrape data using Prometheus
In Prometheus, an example scrape config would look like this:
1
2
3
4
scrape_configs:
- job_name: "ntfy"
static_configs:
- targets: ["$IP:9090"]
Verify and Launch the Container
To verify the Docker Compose file has no issues, use the following command:
1
docker compose config
Once youโve confirmed that the docker-compose.yml file is correct, you can launch the container in the background:
1
docker-compose up -d
This will create the volume, download the image, and start the container in the background.
To verify the status of all running containers, run the following command:
1
2
3
docker-compose ps
# OR
docker ps -a
If something goes wrong, you can check the logs for each container using the docker logs command. For example, to check the log of the Ntfy container, run the following command:
1
2
3
docker logs ntfy
# OR
docker compose logs -f ntfy
Accessing the Ntfy Dashboard
If all is well, you can access your Ntfy Server locally by navigating to http://$IP:80 in your web browser.
For more advanced configuration options, refer to the Ntfy manual.