1. Create a slack incoming webhook to your preferred slack channel with the following guide: Slack Webhooks

A. Create a Slack App

Specify the name and choose the Slack Workspace where the notification will be sent.

B. Under the Add features and functionality section, click on Incoming Webhooks and activate Incoming Webhooks.

C. Add New Webhook to Workspace and select which channel on your workspace you would like to send the notifications to.

   2.   Create a bash script to send a webhook notification on your channel and copy the Webhook URL from the Slack App we just created into the SLACK_WEBHOOK_URL portion of the script.

#!/bin/bash

SLACK_WEBHOOK_URL=https://slack.com ## Set the WEBHOOK URL HERE

sIFS=$IFS
declare -A param
while IFS=’=’ read -r -d ‘&’ key value; do
        [[ -z “$key” ]] && continue;
        param[“$key”]=$value
done <<<$(cat)”&”
IFS=$sIFS;

###Slack Section Template###
SECTION_TPL='{    
        “type”: “section”, 
        “text”: { 
            “type”: “mrkdwn”, 
            “text”: “__MESSAGE__” 
    }
}’;

SECTIONS=””
JOB_NAME=${param[name]}
CURRENT_DATE=”$(date)”
STATUS=”” 

addSection() {
    _MSG=”$1″
    _S=””
    [[ “” != “$SECTIONS” ]] && _S=”,”    
    SECTIONS+=${_S}$( echo “$SECTION_TPL” | sed “s/__MESSAGE__/${_MSG}/” )    
}

setStatus(){
    case “${param[status]}” in      
       1)
        STATUS=’Success’
        ;;          
        2)
        STATUS=’Failed’
        ;;
        3)
        STATUS=’Aborted’
        ;;  
        4)
        STATUS=’Partially Completed’
        ;;
   esac  
}

case “${param[stage]}” in 
    “onBackupStart”)
        addSection “Backup Job (${JOB_NAME}) Started at ${CURRENT_DATE}”
    ;;

    “onBackupEnd”)
        setStatus
        addSection “Backup Job (${JOB_NAME}) Finished at ${CURRENT_DATE}”
        addSection “Backup Status: ${STATUS}”
    ;;
    *)
        exit
    ;;
esac

SLACK_MSG='{“text”: “Jetbackup Slack Notification”, “blocks”: [‘”${SECTIONS}”‘]}’
curl -X POST -H ‘Content-type: application/json’ –data “${SLACK_MSG}” “${SLACK_WEBHOOK_URL}”

      

3.   Create a JetBackup Pre and Post Backup Job Hook and specify the path to your slack script.

WHM > JetBackup > Hooks > Create New Hook:

  1. Hook Name: pre-Backup slack notification/post-Backup slack notification
  2. Hook Position: pre/post
  3. Hook Type: Backup
  4. Backup Jobs: {Specify your preferred backup jobs or leave blank to apply for all backup jobs}
  5. Hook Script: {Path to the bash script from Part 2}

4. Start Getting Notifications!

Once your Hooks are set up, you will start receiving notifications on the slack channel depending on your script and hook type. In this case, sending notifications for when a backup starts and finishes and the corresponding status of the backup job.

Further Reading:

JetBackup has additional hook types available for your use.
https://docs.jetbackup.com/manual/whm/Hooks/createNewHook.html#hook-type

Feel free to modify the slack notification bash script in part 2 for additional notifications like getting specific alerts for failed accounts, or when a restore or download was successful.

You could also add customizations and advanced formatting to your slack notification layout with the use of slack’s text formatting and Block Kit.

https://api.slack.com/reference/surfaces/formatting
https://api.slack.com/messaging/composing/layouts