#!/bin/bash ## .SYNOPSIS ## HTML Report to consume easily via EMAIL, or from the Report Directory ## ## .DESCRIPTION ## This Script will query the Veeam Backup for Azure API and save the job sessions stats for the last 24 hours. Then it saves it into a comfortable HTML, and it is sent over EMAIL ## The Script it is provided as it is, and bear in mind you can not open support Tickets regarding this project. It is a Community Project ## ## .Notes ## NAME: veeam_azure_email_report.sh ## ORIGINAL NAME: veeam_azure_email_report.sh ## LASTEDIT: 22/01/2022 ## VERSION: 3.0 ## KEYWORDS: Veeam, HTML, Report, Azure ## .Link ## https://jorgedelacruz.es/ ## https://jorgedelacruz.uk/ # Configurations ## # Endpoint URL for login action veeamUsername="YOURVEEAMBACKUPUSER" veeamPassword="YOURVEEAMBACKUPPASS" veeamBackupAzureServer="https://YOURVEEAMBACKUPIP" veeamBackupAzurePort="443" #Default Port ## System Variables reportDate=$(date "+%A, %B %d, %Y %r") reportDatePath=$(date "+%A%B%d%Y") reportDateTo=$(date "+%Y-%m-%d") reportDateFrom=$(date -d "$reportDateTo - 1 day" '+%Y-%m-%d') reportPath="/home/oper/vba_azure_reports" html="$reportPath/Azure-Job-Report-$reportDatePath.html" email_add="CHANGETHISWITHYOUREMAIL" color1="#a7a9ac" color2="#f3f4f4" color3="#626365" color4="#e3e3e3" fontsize1="20px" fontsize2="20px" fontsize3="22px" ## Login and Token veeamBearer=$(curl -X POST --header "Content-Type: application/x-www-form-urlencoded" --header "Accept: application/json" -d "Username=$veeamUsername&Password=$veeamPassword&refresh_token=&grant_type=Password&mfa_token=&mfa_code=" "$veeamBackupAzureServer:$veeamBackupAzurePort/api/oauth2/token" -k --silent | jq -r '.access_token') ## # Veeam Backup for Azure Overview. This part will check VBA Overview ## veeamVBAURL="$veeamBackupAzureServer:$veeamBackupAzurePort/api/v3/system/about" veeamVBAOverviewUrl=$(curl -X GET $veeamVBAURL -H "Authorization: Bearer $veeamBearer" -H "accept: application/json" 2>&1 -k --silent) version=$(echo "$veeamVBAOverviewUrl" | jq --raw-output ".serverVersion") workerversion=$(echo "$veeamVBAOverviewUrl" | jq --raw-output ".workerVersion") veeamVBAURL="$veeamBackupAzureServer:$veeamBackupAzurePort/api/v3/system/serverInfo" veeamVBAOverviewUrl=$(curl -X GET $veeamVBAURL -H "Authorization: Bearer $veeamBearer" -H "accept: application/json" 2>&1 -k --silent) serverName=$(echo "$veeamVBAOverviewUrl" | jq --raw-output ".serverName") azureRegion=$(echo "$veeamVBAOverviewUrl" | jq --raw-output ".azureRegion") ## # Veeam Backup for Azure Sessions. This part will check VBA Sessions ## veeamVBAURL="$veeamBackupAzureServer:$veeamBackupAzurePort/api/v3/jobSessions?Types=PolicyBackup&Types=PolicySnapshot&FromUtc=$reportDateFrom&ToUtc=$reportDateTo" veeamVBASessionsBackupUrl=$(curl -X GET $veeamVBAURL -H "Authorization: Bearer $veeamBearer" -H "accept: application/json" 2>&1 -k --silent) declare -i arraysessionsbackup=0 for row in $(echo "$veeamVBASessionsBackupUrl" | jq -r '.results[].id'); do SessionID=$(echo "$veeamVBASessionsBackupUrl" | jq --raw-output ".results[$arraysessionsbackup].id") SessionStatus=$(echo "$veeamVBASessionsBackupUrl" | jq --raw-output ".results[$arraysessionsbackup].status") case $SessionStatus in Success) jobStatus="1" bcolor="#37872D" ;; Warning) jobStatus="2" bcolor="#FA6400" ;; Failed) jobStatus="3" bcolor="#C4162A" ;; esac SessionType=$(echo "$veeamVBASessionsBackupUrl" | jq --raw-output ".results[$arraysessionsbackup].localizedType") SessionDuration=$(echo "$veeamVBASessionsBackupUrl" | jq --raw-output ".results[$arraysessionsbackup].executionDuration") SessionDurationB=$(date -d $SessionDuration '+%H:%M:%S') SessionStartTime=$(echo "$veeamVBASessionsBackupUrl" | jq --raw-output ".results[$arraysessionsbackup].executionStartTime") SessionStartTimeB=$(date -d $SessionStartTime '+%r') SessionDurationReport=$(date -d $SessionStartTime '+%A, %B %d, %Y %r') SessionStopTime=$(echo "$veeamVBASessionsBackupUrl" | jq --raw-output ".results[$arraysessionsbackup].executionStopTime") SessionStopTimeB=$(date -d $SessionStopTime '+%r') SessionPolicyID=$(echo "$veeamVBASessionsBackupUrl" | jq --raw-output ".results[$arraysessionsbackup].backupJobInfo.policyId") SessionPolicyName=$(echo "$veeamVBASessionsBackupUrl" | jq --raw-output ".results[$arraysessionsbackup].backupJobInfo.policyName") if [ "$veeamVBASessionPolicyName" == "" ];then declare -i veeamVBASessionPolicyName=0 fi SessionPolicyProtectedInstances=$(echo "$veeamVBASessionsBackupUrl" | jq --raw-output ".results[$arraysessionsbackup].backupJobInfo.protectedInstancesCount") #Generating HTML file echo '' >> $html echo "" >> $html echo "" >> $html echo '' >> $html echo "" >> $html echo "" >> $html echo '
' >> $html echo '' >> $html echo "" >> $html echo '' >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo '" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "
$SessionType: $SessionPolicyName" >> $html echo '
' >> $html echo "
$SessionStatus" >> $html echo "
$SessionPolicyProtectedInstances of $SessionPolicyProtectedInstances VMs processed
" >> $html echo "
> $html echo '' >> $html echo "" >> $html echo '' >> $html echo "" >> $html echo "" >> $html echo '' >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo '' >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html ## # Veeam Backup for Azure Detailed Sessions. This part will check the Instances inside the Session ## veeamVBAURL="$veeamBackupAzureServer:$veeamBackupAzurePort/api/v3/jobSessions/$SessionID/log" veeamVBASessionsLogBackupUrl=$(curl -X GET $veeamVBAURL -H "Authorization: Bearer $veeamBearer" -H "accept: application/json" 2>&1 -k --silent) declare -i arraysessionslogbackup=0 for row in $(echo "$veeamVBASessionsLogBackupUrl" | jq -r '.log[].logTime'); do SessionLogStatus=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].status") case $SessionLogStatus in Success) bcolor="#37872D" ;; Warning) bcolor="#FA6400" ;; Failed) bcolor="#C4162A" ;; esac SessionLogMessage=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].message") if [[ "$SessionLogMessage" == *"Backing up"* ]]; then SessionLogVMName=$(echo $SessionLogMessage |awk '{print $3}') SessionLogVMTransferred=$(echo $SessionLogMessage | awk -F % '{print $2}' | sed 's/[()]//g' | awk -F transferred '{print $1}') SessionLogType="Backup" SessionLogDuration=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].executionDuration") SessionLogDurationB=$(date -d $SessionLogDuration '+%H:%M:%S') SessionLogStart=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].executionStartTime") SessionLogStartB=$(date -d $SessionLogStart '+%r') echo '' >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html elif [[ "$SessionLogMessage" == "Snapshot backup of"* ]]; then SessionLogVMName=$(echo $SessionLogMessage |awk '{print $4}') SessionLogVMTransferred="N/A" SessionLogType="Snapshot" SessionLogDuration=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].executionDuration") SessionLogDurationB=$(date -d $SessionLogDuration '+%H:%M:%S') SessionLogStart=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].executionStartTime") SessionLogStartB=$(date -d $SessionLogStart '+%r') echo '' >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html fi arraysessionslogbackup=$arraysessionslogbackup+1 done echo "" >> $html echo "
" >> $html echo "$SessionDurationReport" >> $html echo "
" >> $html echo "Start time" >> $html echo "$SessionStartTimeB" >> $html echo "" >> $html echo "
" >> $html echo "End time" >> $html echo "$SessionStopTimeB
" >> $html echo "Duration" >> $html echo "$SessionDurationB
" >> $html echo "Details" >> $html echo "
" >> $html echo "Name" >> $html echo "" >> $html echo "Job Type" >> $html echo "" >> $html echo "Status" >> $html echo "" >> $html echo "Start time" >> $html echo "" >> $html echo "Transferred" >> $html echo "" >> $html echo "Duration" >> $html echo "
$SessionLogVMName$SessionLogType" >> $html echo "$SessionLogStatus" >> $html echo "$SessionLogStartB$SessionLogVMTransferred$SessionLogDurationB
$SessionLogVMName$SessionLogType" >> $html echo "$SessionLogStatus" >> $html echo "$SessionLogStartB$SessionLogVMTransferred$SessionLogDurationB
" >> $html echo "
 
Veeam Backup for Azure - Hostname: $serverName Version: $version - Azure Region: $azureRegion
" >> $html echo "
" >> $html echo "
" >> $html arraysessionsbackup=$arraysessionsbackup+1 done #Sending Email to the user cat $html | s-nail -M "text/html" -s "$veeamBackupAzureServer - Daily Veeam Backup for Azure Report" $email_add