miércoles, 14 de julio de 2021

Proxmox vm backup status

For comment: Zabbix Share - Proxmox VMs Backup Status Template


The comment is still in  pending status, I paste it here:

Hi,
I have modified the status script to process several backup storages for different jobs. If you have only a job backup the script works as original.

I have added an 8th status: 8 => At least a VM backup OK, but not all. Thus, we know that at least a backup is ok, but not all our jobs were successfully executed.

[....]

The definition of the 8th state trigger prototype:
Name: At least a VM backup for VM {#VM_NUMBER} OK, but not all
Expression: {Template App Proxmox VMs Backup Status:proxmox-vms-backup-status[{#VM_NUMBER},{$BACKUP_PERIOD}].last()}=8
Add value mapping description 8 mapped to "At least a VM backup is OK, but not all"


Modified script:

#!/bin/bash

# Script for checking ProxMox virtual machines backup. For use in Zabbix. Skygge@2016
# Modified: MR_Andrew, 2018. Fran Couñago, 2021
# Special thanks: Max Dark, Marinero from cyberforum.ru

#Variables

backupconfig='/etc/pve/vzdump.cron'
storageconfig='/etc/pve/storage.cfg'
configdir='/etc/pve/local/qemu-server'

# Check every VM for existing backup files and check if they're newer than 7 days

mapfile -t bckstorarray < <( awk  -v vm=$1 '$0 ~ vm {for(i=1;i<NF;i++) {if( $i ~ /--storage/) print $(i+1)}}'  $backupconfig|sort|uniq)
# read physical backup path from storage configuration file for VM $1
if [ ${#bckstorarray[@]} = 0 ]; then
	#echo "Invalid VM number, or backup for VM $1 is not configured."
	echo 0
else
	#Array with multiple errors
	ONEBAD=0
	ONEGOOD=0
	for backupstorage in "${bckstorarray[@]}"
	do		
		backupdirectory=`cat $storageconfig|grep -w -A 1 $backupstorage|grep path|rev|cut -d " " -f 1|rev`		
		#echo BCKDIR=$backupdirectory
		if [ -d $backupdirectory/dump ]; then
				# check if backup file(s) exists on backup path for VM $1
				backup=`ls $backupdirectory/dump/|grep "$1" |grep -v -E "log|tmp|dat"|wc -l`
				if [ "$backup" = "0" ]; then
					#echo "VM $1 has no backup file."
					ONEBAD=2					
				else
					# check if backup file is newer than $2 day(s) for VM $1
					newbackup=`find $backupdirectory/dump/ -type f -name "*$1*" -not -name "*.log" -not -name "*.tmp" -not -name "*.dat" -mtime -$2 | sort -nr | head -1|wc -l`
						if [ "$newbackup" = "0" ]; then
							#echo "VM $1 backup is older than $2 day(s)."
							ONEBAD=3
						else
								#check last log file for errors
								backuplastlog=`ls $backupdirectory/dump/ | grep "$1" | grep log | tail -1`
								backupresult=`cat $backupdirectory/dump/$backuplastlog | grep -i -E "ERROR|FAILED"`
										if [ "$backupresult" = "" ];then
												#echo "VM $1 backup is OK, no errors found."
												ONEGOOD=1												
										else
												#echo "VM $1 backup finished with errors. Please, check logs."
												ONEBAD=0
										fi
						fi
				fi			
		else
			#echo "Backup directory for VM $1 does not exists."
			ONEBAD=1
		fi		
	done
	if [ $ONEGOOD = 1 ]; then
		if [ $ONEBAD != 0 ] ; then
			echo 8
		else
			echo 7
		fi
	else
		echo $ONEBAD
	fi
fi

Add Trigger Prototype:


Add Value Mapping



No hay comentarios:

Publicar un comentario

L2TP Ipsec Windows to Mikrotik eror 789

 Add this to registry REG ADD HKLM\SYSTEM\CurrentControlSet\Services\PolicyAgent /v AssumeUDPEncapsulationContextOnSendRule /t REG_DWORD /d...