I am hosting this website on a VPS and I have a desire to know when my VPS provider reboots my VPS. I wanted to send a multi-cast notification to any subscribed device when the machine reboots.
I had a lot of options: Telegram bot, Email or WhatsApp. I settled for using the free and open-source ntfy.sh software which I self-host.
It allows you to send one-way messages via a subscription model and feature great integration with web and mobile clients. It supports (user-managed) push notificatios that offer reaction buttons as well as images, icons and markdown-based text.
For linux machines there are easy to follow instructions on this page for how to get it working, but I modified the scriped slightly to pass in an authorization bearer-token as the ntfy.sh instance is protected against unauthorized access. I have also installed fail2ban
.
#!/bin/bash
if [ "${PAM_TYPE}" = "open_session" ]; then
curl -H "Authorization: Bearer [KEY REDACTED]" -H "Tags:loudspeaker" \
-d "SSH login: ${PAM_USER} from ${PAM_RHOST}" \
https://notifications.notlocalhost.dev:8082/alerts
fi