DirectAdmin Push notifications with Pushover

DirectAdmin Pushover NotificationsDirectAdmin has a great notification system that sends Admin messages to your e-mail. And CustomBuild also supports e-mail notifications for new software updates when you use the CustomBuild cronjob. With the Pushover API and the mobile app, it is very easy to receive all these messages from DirectAdmin & CustomBuild immediately to your iOS or Android device as Push Notifications! So if there is an issue with brute force attempts or if backups are failing, with Push Notifications you are immediately notified so you can take action quickly.


Setup Pushover

First, you need an account with Pushover. Follow the steps on the website to create a new account or sign in with your existing account.

When logged in, scroll down until you see “Your Applications (Create an Application/API Token)”. Click Create to start adding an application.

Pushover Create new Application

  • Name
    • Enter your server hostname for example
  • Description
    • Optional
  • URL
    • Optional, you can leave this blank
  • Icon
    • Optional

Click the checkbox to agree to the terms and now you have created a new application. You should now see your API Token/Key. The User Key is also a key you’ll need, which you can find on your dashboard.


DirectAdmin Push scripts

To receive Push notifications whenever there is a notification from DirectAdmin, you need to add a few scripts and use the hooks from DirectAdmin.

  • notification.sh
    • This is the main script for sending notitications
  • send-pushover-notification.sh
    • This is the script that is used in the CustomBuild cronjob
  • sendSystemMessage_post.sh
    • This is the script that is called by DirectAdmin if the admin user receives an message in the notification system

notification.sh

This is the main script for sending notifications to Pushover. It accepts a title and message as parameters.

cd /root
mkdir pushover
cd pushover
touch notification.sh
chmod 700 notification.sh
nano notification.sh
#!/bin/sh

##
#API keys.
##
PUSHOVER_APP_TOKEN=
PUSHOVER_USER_KEY=

##
# Create the title and message strings, and cut them off after x characters for Pushover to accept them.
##
NOTIFICATION_TITLE="${1:0:248}"
NOTIFICATION_MESSAGE="${2:0:1020}"

##
# Send the message.
##
curl -s -o /dev/null \
--form-string "token=${PUSHOVER_APP_TOKEN}" \
--form-string "user=${PUSHOVER_USER_KEY}" \
--form-string "title=${NOTIFICATION_TITLE}" \
--form-string "message=${NOTIFICATION_MESSAGE}" \
https://api.pushover.net/1/messages.json

As you can already see, enter your Pushover App Token & User Key. You can already test if sending notifications is working by running:

./notification.sh "Title" "This is a test message"

If you receive no errors and the App Token & User Key was set up correctly, you should now receive a push message on your configured devices on Pushover. If the title and message parameters are too long, they are cut off because Pushover doesn’t accepts strings longer then 248 characters for the title and 1020 characters for the message.

send-pushover-notification.sh

Script for CustomBuild update notifications:

cd /usr/local/directadmin/custombuild/custom/
mkdir hooks
cd hooks
mkdir cron_execute
cd cron_execute
mkdir post
cd post
touch send-pushover-notification.sh
chmod 700 send-pushover-notification.sh
nano send-pushover-notification.sh
#!/bin/sh

cd /usr/local/directadmin/custombuild
AVAIL_UPDATES="`./build versions_nobold | grep -c -e 'update is available.'`"
if [ "${AVAIL_UPDATES}" -gt 0 ]; then
/root/pushover-notification/notification.sh "`hostname`: ${AVAIL_UPDATES} updates available" "$(./build versions_nobold | grep 'update is available.')"
fi

exit 0;

Now if there are any updates available in CustomBuild you will receive a push message alongside the standard e-mail message!

DirectAdmin system (admin) messages

Create the sendSystemMessage_post.sh script, executed by DirectAdmin after the Admin user receives a message in the notification system:

cd /usr/local/directadmin/scripts/custom/
(if the custom dir does not exists, create it)
touch sendSystemMessage_post.sh
chmod 700 sendSystemMessage_post.sh
nano sendSystemMessage_post.sh

Place this script in the newly created file:

#!/bin/sh

# Notification and Email Title.
NOTIFICATION_ALERT_TITLE="`hostname`: DirectAdmin Message"

NEWLINE=$'\n'
NOTIFICATION_ALERT_MESSAGE="${subject}${NEWLINE}${NEWLINE}${message}"

/root/pushover-notification/notification.sh "${NOTIFICATION_ALERT_TITLE}" "${NOTIFICATION_ALERT_MESSAGE}"

Now if there are messages send to a admin user, you will also receive in instant push notification to your mobile devices!


DirectAdmin Push Notifications: GitHub repository

If you have any suggestions or improvements, open an Issue or Pull Request on the GitHub repository.