ROOTPLOIT
Server: Apache
System: Linux node6122.myfcloud.com 6.14.3-x86_64-linode168 #1 SMP PREEMPT_DYNAMIC Mon Apr 21 19:47:55 EDT 2025 x86_64
User: bashacomputer (1004)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/self/root/lib64/nagios/plugins/check_proxmox_backups.sh
#!/bin/bash
# Ref - 8696dk1zc - check proxmox backups state
#

cahe_interval=21600                       # interval to check
cahe_log="/tmp/check_proxmox_backups.log" # default path to log file
cacheage () {
  file=${1}
  now=$(date +%s)
  mtime=$(stat -c %Y "${file}")
  delta=$(( now - mtime ))
  echo "${delta}"
}

if ! which proxmox-backup-manager > /dev/null 2>&1; then
  echo "check_proxmox_backups - OK - No proxmox backups setup" >${cahe_log}
  cat ${cahe_log}
  exit 0
fi

# go through all proxmox upids and collect last day backup completion data
check_backup_state() {

  last_day=$(date -d "yesterday" +"%a %b %d")
  backup_dc=$(hostname | awk -F '.whgi' '{print $1}' | awk -F '.' '{print $2}')
  backup_today_upid=($(proxmox-backup-manager task list --all | grep "${last_day}" | awk '{print $14}' | grep "${backup_dc}" | grep "@pbs"| grep -v "prune:backup"))
  
  for backup_id in ${backup_today_upid[@]}; do
    upid_data=$(proxmox-backup-manager task log ${backup_id})
    if [[ -n "${upid_data}" ]];then
      if echo "${upid_data}" | grep -q "successfully finished backup"; then
        index_date=$(echo "${upid_data}" | grep 'created new fixed index 1')
        echo "OK - job completed successfully (${index_date})"
      else
        echo "CRIT - ${backup_id} job has not been completed"
      fi
    else
      echo "CRIT - ${backup_id} job has no task log"
    fi
  done
}

# generate a cache
if [[ ! -e ${cahe_log} ]]; then
  touch ${cahe_log}
  check_backup_state >${cahe_log}
else
  fileage=$(cacheage ${cahe_log})
  if [ "${fileage}" -ge "${cahe_interval}" ]; then
    check_backup_state >${cahe_log}
  fi
fi

# use cache to populate monitoring data
if [[ -s "${cahe_log}" ]]; then
  if grep -q CRIT "${cahe_log}"; then
    echo -e "check_proxmox_backups - CRIT\n$(cat ${cahe_log})"
    exit 2
  else
    echo -e "check_proxmox_backups - OK\n$(cat ${cahe_log})"
    exit 0
  fi
fi