NTFY is a simple HTTP-based pub-sub notification service. It allows you to send notifications to your phone or desktop via scripts from any computer, and/or using a REST API. It's infinitely flexible, and 100% free software.
PUB-SUB: It is known as the publish-subscribe pattern, which is a messaging pattern where publishers categorize messages into classes that are received by subscribers.
NTFY is a powerful open-source notification tool that can be self-hosted. Suppose a scenario where you are downloading a large file using wget and have to do other work leaving your desktop, but you want to get notified when the task is complete then NTFY comes in handy to use.
Steps to install NTFY
Let's start with the Desktop setup
- Let us set it without using docker
$ wget https://github.com/binwiederhier/ntfy/releases/download/v2.11.0/ntfy_2.11.0_linux_amd64.deb
$ sudo dpkg -i ntfy_*.deb
$ sudo systemctl start ntfy
- If you want to enable ntfy on the start of OS then use the following command.
$ sudo systemctl enable ntfy
- If you are using another OS then visit the link: https://docs.ntfy.sh/install/
Using docker
The ntfy image is available for amd64, armv6, armv7 and arm64.
with persistent cache
$ sudo apt update
$ sudo apt install docker.io -y
- After you install docker to host from a VPN or home network and get notified about the task you need to configure a file. Copy the code from the link: https://github.com/binwiederhier/ntfy/blob/main/server/server.yml then paste it on server.yml
$ sudo nano /etc/ntfy/server.yml
- Now search and change the following code
# Go to the top of the code and uncomment base-url and set the url
# for example
base-url : http/https://your ip address to the internet
# For ISO search for `upstream` in code and uncomment
# In nano press ctrl+w to search
upstream-base-url: "https://ntfy.sh"
# If you use twilio for phone call then find the twilio in the code and give the credential
- Save the changes and run the docker container
$ sudo docker run -v /var/cache/ntfy:/var/cache/ntfy -v /etc/ntfy:/etc/ntfy -p 80:80 -itd binwiederhier/ntfy serve --cache-file /var/cache/ntfy/cache.db
In Mobile
- Download the NTFY app from the Play Store, F-droid or App Store.
https://play.google.com/store/apps/details?id=io.heckel.ntfy
https://f-droid.org/en/packages/io.heckel.ntfy/
https://apps.apple.com/us/app/ntfy/id1625396347
Go to the settings section of the app and Change the default server to the IP address of the base-url that you set early in server.yml
Then go to the notification section click on the plus icon and subscribe to a channel named by yourself that should be unique.
Test to push notification
- Open the terminal and test by using the following command
$ curl -d "Test" (ip-address that you specify in base-url)/channel that you named
For example:
ip-address = 10.23.103.2 and
subscribed channel = ntfytestnotification, then the command will be
$ curl -d "Test" 10.23.103.2/ntfytestnotification
This should work on iOS and Android devices.
using this you can leave your task and at the end, you can write the above command followed by && as shown in the following example
E.g.
$ ping 192.168.1.1 -c 3 && curl -d "Host is up" 10.23.103.2/ntfytestnotification || curl -d "Host is down" 10.23.103.2/ntfytestnotification
In this above example, 192.168.1.1 is pinged 3 times and
if it gets the response then it will push a notification with the Host is up message
else it will push a notification with the Host is down message.
Check the documentation of NTFY by following this link https://docs.ntfy.sh/ where you can do a bunch of things. Here in this blog, I have mentioned only the installation process.