PRTG custom sensor for Duplicati [HowTo]

image

  1. Setup root@duplicati-server SSH access using PubKeyAuth.
  2. Place the following script onto the machine running Duplicati jobs and make it executable:

chmod 0755 /var/prtg/scriptsxml/duplicati-job-status.sh

#!/bin/sh
#
# Command line.
## sh /var/prtg/scriptsxml/duplicati-job-status.sh my-test-backup-job
#
# Consts.
#
# Functions.
throwXmlError () {
	echo "<prtg>"
	echo "<error>1</error>"
	echo "<text>${1}</text>"
	echo "</prtg>"
	return 0
}
#
#
if [ -z "${1}" ]; then
	throwXmlError "WARNING: Duplicati job parameter #1 missing."
	exit 0
fi
DUPLICATI_JOB_NAME="${1}"
DUPLICATI_JOB_RESULT_FULLFN="/root/.config/Duplicati/jobs/${DUPLICATI_JOB_NAME}.result"
#
if [ ! -f "${DUPLICATI_JOB_RESULT_FULLFN}" ]; then
	throwXmlError "WARNING: Job \"${DUPLICATI_JOB_NAME}\" was never executed."
	exit 0
fi
#
if ( ! grep -q "Success" "${DUPLICATI_JOB_RESULT_FULLFN}" ); then
	throwXmlError "CRITICAL: Job \"${DUPLICATI_JOB_NAME}\" $(cat "${DUPLICATI_JOB_RESULT_FULLFN}" 2>/dev/null)"
	exit 0
fi
#
# Generate XML sensor output.
echo "<prtg>"
echo "<result><channel>Backup Job Status</channel><value>0</value></result>"
echo "<text>OK: Job \"${DUPLICATI_JOB_NAME}\" $(cat "${DUPLICATI_JOB_RESULT_FULLFN}" 2>/dev/null)</text>"
echo "</prtg>"
#
exit 0
  1. In PRTG, create a new sensor.
  • In sensor overview, search for “script” and choose “ssh-script (extended)” as the sensor type.
  • script = duplicati-job-status.sh (choose from dropdown)
    ** If the drop-down shows nothing, most likely your SSH credentials set-up in PRTG are invalid or you just forgot to set them for the parent device.
  • parameter = your-backup-job-name-to-monitor
  • connection timeout = 10 sec
  • query interval = 30 minutes
  1. Make sure, Duplicati executes the following script after a job finished.

chmod 0755 /root/.config/Duplicati/duplicati-post.sh

#!/bin/bash
#
# Store job result to file for monitoring.
SCRIPT_PATH="$(dirname "$(realpath "${0}")")"
mkdir -p "${SCRIPT_PATH}/jobs/"
echo "${DUPLICATI__PARSED_RESULT} ${DUPLICATI__EVENTNAME} ${DUPLICATI__OPERATIONNAME}" > "${SCRIPT_PATH}/jobs/${DUPLICATI__backup_name}.result"
#
exit 0
2 Likes