Automate with NTFY

Abstract: Sync my message with NTFY, like server notification, or text message or any other thing you like.

I am a huge fan of self-hosted services, and there is no doubt about it. In my previous articles, I have shared fascinating insights about n8n and obsidian. Lately, I have been facing a challenge with the OSDI conference deadline. Constantly monitoring my program on the server has left me exhausted. Therefore, it is high time for me to explore an intriguing alternative.

Installation

docker-compose

I strongly suggest install NTFY with docker-compose.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
version: "2.3"

services:
ntfy:
image: binwiederhier/ntfy
container_name: ntfy
command:
- serve
environment:
- TZ=Europe/London # Set timezone to Europe/London for Edinburgh
# user: UID:GID # optional: replace with your own user/group or uid/gid
volumes:
- /var/cache/ntfy:/var/cache/ntfy
- /etc/ntfy:/etc/ntfy
ports:
- 6673:80 # Map port 6673 on the host machine to port 80 inside the container
# healthcheck: # optional: remember to adapt the host:port to your environment
# test: ["CMD-SHELL", "wget -q --tries=1 http://localhost:6673/v1/health -O - | grep -Eo '\"healthy\"\\s*:\\s*true' || exit 1"]
# interval: 60s
# timeout: 10s
# retries: 3
# start_period: 40s
restart: unless-stopped

As my 80 port is occupied by other service on my server, so I use 6673 instead.

And then run

1
docker-compose up -d

Nginx

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
server {
listen 80;
server_name ntfy.xxxx.xxxx;

location / {
return 302 https://$http_host$request_uri$is_args$query_string;

proxy_pass http://127.0.0.1:6673;
proxy_http_version 1.1;

proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_connect_timeout 3m;
proxy_send_timeout 3m;
proxy_read_timeout 3m;

client_max_body_size 0; # Stream request body to backend
}
}

server {
listen 443 ssl http2;
server_name ntfy.xxxx.xxxx;

# See https://ssl-config.mozilla.org/#server=nginx&version=1.18.0&config=intermediate&openssl=1.1.1k&hsts=false&ocsp=false&guideline=5.6see https://ssl-config.mozilla.org/#server=nginx&version=1.18.0&config=intermediate&openssl=1.1.1k&hsts=false&ocsp=false&guideline=5.6
ssl_session_timeout 1d;
ssl_session_cache shared:MozSSL:10m; # about 40000 sessions
ssl_session_tickets off;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;

# ssl_certificate /etc/letsencrypt/live/ntfy.xxxx.xxxx/fullchain.pem;
# ssl_certificate_key /etc/letsencrypt/live/ntfy.xxxx.xxxx/privkey.pem;

ssl_certificate /etc/letsencrypt/live/server.xxxx.xxxx/fullchain.pem; # managed by Certbot
# managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/server.xxxx.xxxx/privkey.pem; # managed by Certbot
# managed by Certbot
access_log /var/log/nginx/server_access.log;
error_log /var/log/nginx/server_error.log;
location / {
proxy_pass http://127.0.0.1:6673;
proxy_http_version 1.1;

proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_connect_timeout 3m;
proxy_send_timeout 3m;
proxy_read_timeout 3m;

client_max_body_size 0; # Stream request body to backend
}
}

Notice: remember to update your port and domain name.

Usage

Send message

On server side:

1
curl -d "Backup successful 😀" https://xxxx.xxxx/mytopic

ntfy doc

Receive message

If you are unable to receive messages promptly on the client, please substitute “https” with “http” and utilize the following URL: http://xxxx.xxxx:6673.


Automate with NTFY
http://blog.chivier.site/2023-12-13/b2cdcf4d6def/
Author
Chivier Humber
Posted on
December 13, 2023
Licensed under