File: //usr/lib64/nagios/plugins/vz7_check_a2_backups-running.sh
#!/bin/bash
#
# Separated this check so it won't be cached - SYSENG-3818
# Refactored a bit to include ndb proc format etc - SYSENG-4387
# 2/2024 - Skips parts if remote Virtuozzo Backups enabled - SYSENG-26958
# 8/2024 - Refactored to fix OK/CRIT status together - BFENG-1974
# 2/2025 - Refactored for Icinga - lcsiki
threshold=18000 # N value in seconds, 5 hours
# Ref - BFENG-1701 - skip check if it is a VZBK server.
if [[ $(hostname) =~ vzbk ]]; then
exit 0
fi
# In the event we don't want backups, adding if statement
if [ -e /root/.no_backup_mounts ]; then
echo "vz7-backups-running - Not supposed to be backed up or mounted"
exit 0
fi
# Initialize status and exit code
status_message="vz7-backups-running - Running and ownership OK"
exit_code=0
# count and find backup/nbd pid & age
prlctl_backup_pid=$(pgrep -f 'prlctl backup |qemu-nbd')
total_pids=$(echo "${prlctl_backup_pid}" | wc -l)
data_pids=$(for bupid in ${prlctl_backup_pid}; do
proc_age=$(ps -o etimes --no-headers -p ${bupid})
if [[ ${proc_age} -gt ${threshold} ]]; then
proc_name=$(ps -o comm= -p ${bupid})
printf "pid:${bupid}:${proc_name}:$(expr ${proc_age} / 60 / 60)hrs\n"
fi
done)
# Check if there are long-running backup processes
if [[ ! -z "${data_pids}" ]]; then
status_message="vz7-backups-running - WARNING: ${data_pids} |proc(s):${total_pids}"
exit_code=2
fi
### START NFS LOCAL part which doesn't apply if Remote Virtuozzo Backups enabled
if [ ! -f /etc/vz/backup_location ]; then
backup_dir="/backup-local"
# Check if mount is nfs
backup_dir_type=$(stat -fLc %T "${backup_dir}")
if [[ (-z "$(mount | grep local | grep rw)") || ("${backup_dir_type}" != "nfs") ]]; then
status_message="vz7-backups-running - CRITICAL: Backup dir is not read-write or not an NFS mounted dir"
exit_code=2
else
# Check dir permission
dir_ownership=$(stat -c "%U:%G" "${backup_dir}")
if [[ "${dir_ownership}" != "nobody:nobody" ]]; then
status_message="vz7-backups-running - WARNING: Incorrect directory ownership (${dir_ownership}) - Please check"
exit_code=2
fi
fi
fi
### END NFS LOCAL
# Print final status message and exit with appropriate code
echo "${status_message}"
exit ${exit_code}