selfhosted-apps-docker/gotify-ntfy-signal/readme.md

251 lines
5.8 KiB
Markdown
Raw Permalink Normal View History

2023-01-21 20:48:29 +00:00
# gotify ntfy signal
###### guide-by-example
2024-01-14 09:43:27 +00:00
![logo](https://i.imgur.com/ZkGGeT5.png)
2023-01-21 20:48:29 +00:00
# Purpose & Overview
2024-01-14 09:43:27 +00:00
Instant push notifications if email feels old timey and crowded
2023-01-21 20:48:29 +00:00
* [gotify](https://github.com/gotify/server)
* [ntfy](https://github.com/binwiederhier/ntfy)
* [bbernhard/signal-cli-rest-api ](https://github.com/bbernhard/signal-cli-rest-api)
---
# Overview
* **gotify** - great for single person use, but the moment theres more people
they need to share single account and so lack the ability to choose
2023-02-12 18:45:01 +00:00
what to get and what not to get.
2023-01-21 20:48:29 +00:00
* **ntfy** - simple original approach to just subscribing to "topics" without
2024-01-14 09:43:27 +00:00
authentification. Simple single line code for push notification.
Support for multiple users, supports ios.
* **signal-cli-rest-api** - no gui, needs a sim card, a phone number registred,
notification are send through that phone number.
Signal wider spread might make it a winner, since you are not asking people
2023-03-05 09:50:50 +00:00
to install an another app.
2023-01-21 20:48:29 +00:00
2023-03-05 09:50:50 +00:00
Afte few weeks of tinkering with these... **ntfy is the winner for me**, for now.<br>
2023-01-29 19:20:41 +00:00
Compose files for the other two are at the end.
2023-01-21 20:48:29 +00:00
2023-01-29 19:20:41 +00:00
# docker-compose for ntfy
2023-01-21 20:48:29 +00:00
2023-01-29 19:20:41 +00:00
`docker-compose.yml`
2023-01-21 20:48:29 +00:00
```yml
services:
ntfy:
image: binwiederhier/ntfy
container_name: ntfy
hostname: ntfy
env_file: .env
restart: unless-stopped
command:
- serve
2023-05-10 16:42:16 +00:00
ports:
- "80:80"
2023-01-21 20:48:29 +00:00
volumes:
2023-02-20 17:52:41 +00:00
- ./ntfy_cache:/var/cache/ntfy
- ./ntfy_etc:/etc/ntfy
2023-01-21 20:48:29 +00:00
networks:
default:
name: $DOCKER_MY_NETWORK
external: true
```
2023-01-29 19:20:41 +00:00
`.env`
```bash
# GENERAL
DOCKER_MY_NETWORK=caddy_net
TZ=Europe/Bratislava
```
# Reverse proxy
Caddy is used, details
[here](https://github.com/DoTheEvo/selfhosted-apps-docker/tree/master/caddy_v2).</br>
`Caddyfile`
```
ntfy.{$MY_DOMAIN} {
reverse_proxy ntfy:80
}
```
# The usage
2023-02-20 17:52:41 +00:00
[Documentation](https://docs.ntfy.sh/publish/)
ntfy uses "topics" for categorization, which creates a very handy disconnect from
sender and receiver.<br>
Lets say there's a minecraft server and there are notifications when someone
2024-01-14 09:43:27 +00:00
joins. These notifications are send to `minecraft` topic, not to specified users.
2023-04-14 06:24:37 +00:00
Users can subscribe to the topic if they want those notifications.
2023-02-20 17:52:41 +00:00
This gives great flexibility and is the main reason why ntfy wins
over other solutions.
2023-01-29 19:20:41 +00:00
#### Linux
2023-02-20 17:52:41 +00:00
`curl -d "a player joined" https://ntfy.example.com/minecraft`
2023-01-29 19:20:41 +00:00
#### Windows
* win10+
2023-02-20 17:52:41 +00:00
`Invoke-RestMethod -Method 'Post' -Uri https://ntfy.example.com/minecraft -Body "a player joined" -UseBasicParsing`
2023-01-29 19:20:41 +00:00
* win8.1 and older need bit extra for https to work<br>
```
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
2023-02-20 17:52:41 +00:00
Invoke-RestMethod -Method 'Post' -Uri https://ntfy.example.com/minecraft -Body "a player joined" -UseBasicParsing
2023-01-29 19:20:41 +00:00
```
2023-02-20 17:52:41 +00:00
#### systemd unit file service
2023-01-29 19:20:41 +00:00
To allows use of ntfy `OnFailure` and `OnSuccess` inside systemd unit files.
To send useful info [specifiers](https://www.freedesktop.org/software/systemd/man/systemd.unit.html#Specifiers)
are used.
* %n - full unit name
* %p - prefix part of the name
* %i - instance name, between @ and suffix
* %H - machine hostname
Systemd template unit file is used.
These contains `@` to allow for dynamical naming at runtime.
They are called with additional info added between `@` and the suffix `.service`
`ntfy@.service`
```
[Unit]
Description=ntfy notification service
After=network.target
[Service]
Type=simple
ExecStart=/bin/curl -d "%i | %H" https://ntfy.example.com/systemd
```
2023-02-05 18:26:14 +00:00
Example of a service using the above defined service to send notifications.
2023-01-29 19:20:41 +00:00
`borg.service`
```
[Unit]
Description=BorgBackup docker
OnFailure=ntfy@failure-%p.service
OnSuccess=ntfy@success-%p.service
[Service]
Type=simple
ExecStart=/opt/borg_backup.sh
```
2023-03-05 09:50:50 +00:00
# Grafana to ntfy
2023-03-17 20:54:41 +00:00
![ntfy](https://i.imgur.com/gL81jRg.png)
2023-05-10 16:42:16 +00:00
Alerting in grafana to ntfy works, but its ugly with just json shown.
2023-03-05 09:50:50 +00:00
To solve this
2023-05-10 16:42:16 +00:00
* Add container [grafana-to-ntfy](https://github.com/kittyandrew/grafana-to-ntfy).
Set in `.env` ntfy local url
2023-03-05 09:50:50 +00:00
* in grafana set contact point webhook aimed at `http://grafana-to-ntfy:8080`,
with credentials from the `.env`
`docker-compose.yml`
```yml
services:
2023-05-10 16:42:16 +00:00
ntfy:
image: binwiederhier/ntfy:v2.4.0
container_name: ntfy
hostname: ntfy
env_file: .env
restart: unless-stopped
command:
- serve
ports:
- "80:80"
volumes:
- ./ntfy_cache:/var/cache/ntfy
- ./ntfy_etc:/etc/ntfy
2023-03-05 09:50:50 +00:00
grafana-to-ntfy:
container_name: grafana-to-ntfy
hostname: grafana-to-ntfy
image: kittyandrew/grafana-to-ntfy
restart: unless-stopped
env_file:
- .env
2023-05-10 16:42:16 +00:00
ports:
- "8080:8080"
2023-03-05 09:50:50 +00:00
networks:
default:
name: $DOCKER_MY_NETWORK
external: true
2023-05-10 16:42:16 +00:00
2023-03-05 09:50:50 +00:00
```
`.env`
```php
# GENERAL
DOCKER_MY_NETWORK=caddy_net
TZ=Europe/Bratislava
2023-05-10 16:42:16 +00:00
NTFY_URL=http://ntfy:80/whatever
2023-03-05 09:50:50 +00:00
BAUTH_USER=admin
BAUTH_PASS=test
```
2023-01-29 19:20:41 +00:00
<details>
<summary><h1>gotify and signal compose</h1></summary>
`gotify-docker-compose.yml`
```yml
services:
gotify:
image: gotify/server
container_name: gotify
hostname: gotify
restart: unless-stopped
env_file: .env
volumes:
- "./gotify_data:/app/data"
networks:
default:
name: caddy_net
external: true
```
2023-01-21 20:48:29 +00:00
`signal-docker-compose.yml`
```yml
signal:
image: bbernhard/signal-cli-rest-api
container_name: signal
hostname: signal
env_file: .env
restart: unless-stopped
volumes:
- "./signal-cli-config:/home/.local/share/signal-cli" #map "signal-cli-config" folder on host system into docker container. the folder contains the password and cryptographic keys when a new number is registered
networks:
default:
2023-01-29 19:20:41 +00:00
name: caddy_net
2023-01-21 20:48:29 +00:00
external: true
```
2023-01-29 19:20:41 +00:00
</details>
2023-01-21 20:48:29 +00:00
2023-01-29 19:20:41 +00:00
---
---