Use Nagios for Duplicati Monitoring

Link to Nagios Exchange: check_duplicati_job - Nagios Exchange

Hi,

I’ve made a small set of scripts to allow for an easy monitoring integration with Nagios Core. It looks like this:

You’ll need to place the following files into your nagios installation to set it up. I’ve tested this on Debian 10 (buster). Your Duplicati backup job needs to call the bash script by specifiying the advanced option “–run-script-after=/root/.config/Duplicati/save-job-result.sh” in order to save the job result to a status file. The status file will be read by the nagios plugin to determine the sensor status.

chmod +x /usr/local/nagios/libexec/check_duplicati_job

#!/bin/sh
#
# Command line.
## sh /usr/local/nagios/libexec/check_duplicati_job my-test-backup-job; echo $?
#
EXIT_OK=0
EXIT_WARNING=1
EXIT_CRITICAL=2
#
if [ -z "${1}" ]; then
	echo "WARNING: Duplicati job parameter #1 missing."
	exit ${EXIT_WARNING}
fi
DUPLICATI_JOB_NAME="${1}"
DUPLICATI_JOB_RESULT_FULLFN="/root/.config/Duplicati/jobs/${DUPLICATI_JOB_NAME}.result"
#
if [ ! -f "${DUPLICATI_JOB_RESULT_FULLFN}" ]; then
	echo "WARNING: Job \"${DUPLICATI_JOB_NAME}\" was never executed."
	exit ${EXIT_WARNING}
fi
#
if ( ! grep -q "Success" "${DUPLICATI_JOB_RESULT_FULLFN}" ); then
	echo "CRITICAL: Job \"${DUPLICATI_JOB_NAME}\" $(cat "${DUPLICATI_JOB_RESULT_FULLFN}" 2>/dev/null)"
	exit ${EXIT_CRITICAL}
fi
#
echo "OK: Job \"${DUPLICATI_JOB_NAME}\" $(cat "${DUPLICATI_JOB_RESULT_FULLFN}" 2>/dev/null)"
exit ${EXIT_OK}

/usr/local/nagios/etc/commands/check_duplicati_job.cfg

define command{
	command_name 	check_duplicati_job
	command_line 	$USER1$/check_duplicati_job $ARG1$
}

/usr/local/nagios/etc/servers/my-duplicati-server.cfg

define host {

    use                     linux-server
    host_name               my-duplicati-server
    alias                   my-duplicati-server
    address                 [SERVER_IP_ADDRESS]
    check_period            24x7
    contact_groups          admins
    max_check_attempts      5
}

define service {
	use						local-service
	host_name				my-duplicati-server
	service_description		duplicati-job-1
	check_command			check_duplicati_job!duplicati-job-1
}

The job status saver:
chmod +x /root/.config/Duplicati/save-job-result.sh

#!/bin/bash
#
# Store job result to file for nagios 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

this is a follow up to: Backup Monitoring using Nagios/Sensu

2 Likes