Alerting

Transporting from GitHub:

Would it be worth while to write a script to monitor how the Pi-Hole is working? For another opensource project I wrote the below code to send a push bullet alert when called.

**######### Variables #########**
pb_access_token="" _# Pushbullet Access-Token (Example: "bYdBDvrasdYsjdGsmdSLd38S6" )( "" = PushBullet Alerting OFF)_
pb_device_id="" _# Pushbullet Device ID To Send Alerts To (Example: "ujAczShN1VsKnSTs" )( "" = If Blank the script will alert to all PushBullet Devices )_

**######### Function To Send Alert via PushBullet ##########**
pushbullet_alert () {
pb_message_title="$1"
pb_message_body="$2"
if [ -n "$pb_access_token" ] && [ -n "$pb_device_id" ]; then
    curl -k --header 'Access-Token: '$pb_access_token -X POST https://api.pushbullet.com/v2/pushes --header 'Content-Type: application/json' --data-binary '{"device_iden": "'$pb_device_id'", "type": "note", "title": "'"$pb_message_title"'", "body": "'"$pb_message_body"'"}' > /dev/null 2>&1
    if [[ $? != 0 ]]; then echo -e "PushBullet Alert Push Failed -- \e[31m**SCRIPT FAILED**\e[39m (pushbullet_alert)" >> $script_log_file; fi
elif [ -n "$pb_access_token" ]; then
    curl -k --header 'Access-Token: '$pb_access_token -X POST https://api.pushbullet.com/v2/pushes --header 'Content-Type: application/json' --data-binary '{"type": "note", "title": "'"$pb_message_title"'", "body": "'"$pb_message_body"'"}' > /dev/null 2>&1
    if [[ $? != 0 ]]; then echo -e "PushBullet Alert Push Failed -- \e[31m**SCRIPT FAILED**\e[39m (pushbullet_alert)" >> $script_log_file; fi
fi
}

**######### Example On How To Call The Function #########**
pushbullet_alert "Interface(s) Down" "(Manual Intervention Required) -- Unable to restart Interface(s)"

Nice idea, but I prefer and use Pushover.

We could use both.
A Cron job that calls this script every 5 minutes should work.

#!/bin/sh

ps auxw | grep dnsmasq | grep -v grep > /dev/null

if [ $? != 0 ]
then
        /etc/init.d/dnsmasq start > /dev/null
        sleep 60
fi

ps auxw | grep dnsmasq | grep -v grep > /dev/null

if [ $? != 0 ]
then
        curl -s \
         --form-string "token=APP_TOKEN" \
         --form-string "user=USER_KEY" \
         --form-string "message=Pihole is offline!" \
         https://api.pushover.net/1/messages.json
fi

The same could be used for Pushbullet.

Maybe we could use a monitoring program like Monit but i’m not sure if we actually need that.