#!/bin/bash ## .SYNOPSIS ## HTML Report to consume easily via EMAIL, or from the Report Directory ## ## .DESCRIPTION ## This Script will query the Veeam Backup for AWS 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_aws_email_report.sh ## ORIGINAL NAME: veeam_aws_email_report.sh ## LASTEDIT: 13/04/2022 ## VERSION: 4.1 ## KEYWORDS: Veeam, HTML, Report, AWS ## .Link ## https://jorgedelacruz.es/ ## https://jorgedelacruz.uk/ # Configurations ## # Endpoint URL for login action veeamUsername="YOURVEEAMBACKUPUSER" veeamPassword="YOURVEEAMBACKUPPASS" veeamBackupAWSServer="https://YOURVEEAMBACKUPFORAWSIP" veeamBackupAWSPort="11005" #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_aws_reports" html="$reportPath/AWS-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" --header "x-api-version: 1.2-rev0" -d "username=$veeamUsername&password=$veeamPassword&grant_type=password" "$veeamBackupAWSServer:$veeamBackupAWSPort/api/v1/token" -k --silent | jq -r '.access_token') ## # Veeam Backup for AWS Overview. This part will check VBA Overview ## veeamVBAURL="$veeamBackupAWSServer:$veeamBackupAWSPort/api/v1/system/version" veeamVBAOverviewUrl=$(curl -X GET $veeamVBAURL -H "Authorization: Bearer $veeamBearer" -H "x-api-version: 1.2-rev0" "accept: application/json" 2>&1 -k --silent) version=$(echo "$veeamVBAOverviewUrl" | jq --raw-output ".version" |awk '{$1=$1};1') veeamVBAURL="$veeamBackupAWSServer:$veeamBackupAWSPort/api/v1/statistics/summary" veeamVBAOverviewUrl=$(curl -X GET $veeamVBAURL -H "Authorization: Bearer $veeamBearer" -H -H "x-api-version: 1.2-rev0" "accept: application/json" 2>&1 -k --silent) VMsCount=$(echo "$veeamVBAOverviewUrl" | jq --raw-output ".instancesCount") VMsProtected=$(echo "$veeamVBAOverviewUrl" | jq --raw-output ".protectedInstancesCount") PoliciesCount=$(echo "$veeamVBAOverviewUrl" | jq --raw-output ".policiesCount") RepositoriesCount=$(echo "$veeamVBAOverviewUrl" | jq --raw-output ".repositoriesCount") ## # Veeam Backup for AWS EC2 Sessions. This part will check VBA Sessions for EC2 Backup Jobs ## veeamVBAURL="$veeamBackupAWSServer:$veeamBackupAWSPort/api/v1/sessions?Types=Policy&FromUtc=$reportDateFrom&ToUtc=$reportDateTo" veeamVBASessionsBackupUrl=$(curl -X GET $veeamVBAURL -H "Authorization: Bearer $veeamBearer" -H "x-api-version: 1.2-rev0" -H "accept: application/json" 2>&1 -k --silent) declare -i arraysessionsbackup=0 for id in $(echo "$veeamVBASessionsBackupUrl" | jq -r '.results[].id'); do SessionID=$(echo "$veeamVBASessionsBackupUrl" | jq --raw-output ".results[$arraysessionsbackup].id") SessionPolicyName=$(echo "$veeamVBASessionsBackupUrl" | jq --raw-output ".results[$arraysessionsbackup].name") SessionStatus=$(echo "$veeamVBASessionsBackupUrl" | jq --raw-output ".results[$arraysessionsbackup].result") case $SessionStatus in Success) bcolor="#54B948" ;; Warning) bcolor="#F2C973" ;; Failed) bcolor="#E8595A" ;; Error) bcolor="#E8595A" ;; esac SessionExtendedType=$(echo "$veeamVBASessionsBackupUrl" | jq --raw-output ".results[$arraysessionsbackup].extendedSessionType") case $SessionExtendedType in PolicyBackup) SessionType="EC2 Policy Backup" ;; PolicySnapshot) SessionType="EC2 Policy Snapshot" ;; VpcBackup) SessionType="VPC Backup" ;; PolicyRdsSnapshot) SessionType="RDS Policy Snapshot" esac SessionDurationM=$(echo "$veeamVBASessionsBackupUrl" | jq --raw-output ".results[$arraysessionsbackup].executionDuration") SessionLogDurationS=$(echo $(($SessionDurationM/1000))) SessionDurationB=$(echo $(($(($SessionLogDurationS - $SessionLogDurationS/86400*86400))/3600))h:$(($(($SessionLogDurationS - $SessionLogDurationS/86400*86400))%3600/60))m:$(($(($SessionLogDurationS - $SessionLogDurationS/86400*86400))%60))s) SessionStartTime=$(echo "$veeamVBASessionsBackupUrl" | jq --raw-output ".results[$arraysessionsbackup].executionStartTime") SessionStartTimeB=$(date -d $SessionStartTime '+%r') SessionStopTime=$(echo "$veeamVBASessionsBackupUrl" | jq --raw-output ".results[$arraysessionsbackup].executionStopTime") SessionStopTimeB=$(date -d $SessionStopTime '+%r') ## # Veeam Backup for AWS Detailed Sessions. This part will check the Instances inside the Session ## veeamVBAURL="$veeamBackupAWSServer:$veeamBackupAWSPort/api/v1/sessions/$SessionID/log" veeamVBASessionsLogBackupUrl=$(curl -X GET $veeamVBAURL -H "Authorization: Bearer $veeamBearer" -H "x-api-version: 1.2-rev0" -H "accept: application/json" 2>&1 -k --silent) #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 "
$SessionType: $SessionPolicyName" >> $html echo '
' >> $html echo "
$SessionStatus" >> $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 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="#54B948" ;; Warning) bcolor="#F2C973" ;; Failed) bcolor="#E8595A" ;; Error) bcolor="#E8595A" ;; esac case $SessionExtendedType in PolicyBackup) SessionLogMessage=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].message") case $SessionLogMessage in Processing*) SessionLogWorkloadName=$(echo $SessionLogMessage |awk '{print $2}' | sed 's/.$//') SessionLogWorkloadTransferred=$(echo $SessionLogMessage | awk -F %, '{print $2}') SessionLogWorkloadType="EC2 Backup" SessionLogStartTime=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].executionStartTime") SessionLogStoptTime=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].logTime") SessionLogDurationS=$(echo $(( $(date -d "$SessionLogStoptTime" "+%s") - $(date -d "$SessionLogStartTime" "+%s") ))) SessionLogDurationB=$(echo $(($(($SessionLogDurationS - $SessionLogDurationS/86400*86400))/3600))h:$(($(($SessionLogDurationS -$SessionLogDurationS/86400*86400))%3600/60))m:$(($(($SessionLogDurationS - $SessionLogDurationS/86400*86400))%60))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 ;; esac ;; PolicySnapshot) SessionLogMessage=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].message") case $SessionLogMessage in Processing*) SessionLogWorkloadName=$(echo $SessionLogMessage |awk '{print $2}' | sed 's/.$//') SessionLogWorkloadTransferred="N/A" SessionLogWorkloadType="EC2 Snapshot" SessionLogStartTime=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].executionStartTime") SessionLogStoptTime=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].logTime") SessionLogDurationS=$(echo $(( $(date -d "$SessionLogStoptTime" "+%s") - $(date -d "$SessionLogStartTime" "+%s") ))) SessionLogDurationB=$(echo $(($(($SessionLogDurationS - $SessionLogDurationS/86400*86400))/3600))h:$(($(($SessionLogDurationS - $SessionLogDurationS/86400*86400))%3600/60))m:$(($(($SessionLogDurationS - $SessionLogDurationS/86400*86400))%60))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 ;; esac ;; PolicyRemoteSnapshot) SessionLogMessage=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].message") case $SessionLogMessage in Processing*) SessionLogWorkloadName=$(echo $SessionLogMessage |awk '{print $2}' | sed 's/.$//') SessionLogWorkloadTransferred="N/A" SessionLogWorkloadType="EC2 Replica Snapshot" SessionLogStartTime=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].executionStartTime") SessionLogStoptTime=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].logTime") SessionLogDurationS=$(echo $(( $(date -d "$SessionLogStoptTime" "+%s") - $(date -d "$SessionLogStartTime" "+%s") ))) SessionLogDurationB=$(echo $(($(($SessionLogDurationS - $SessionLogDurationS/86400*86400))/3600))h:$(($(($SessionLogDurationS - $SessionLogDurationS/86400*86400))%3600/60))m:$(($(($SessionLogDurationS - $SessionLogDurationS/86400*86400))%60))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 ;; esac ;; VpcBackup) SessionLogMessage=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].message") case $SessionLogMessage in Performing*) SessionLogWorkloadName=$(echo $SessionLogMessage |awk '{print $5" "$6" "$7" - AWS Account "$12}') SessionLogWorkloadTransferred="N/A" SessionLogWorkloadType="VPC Backup" SessionLogStartTime=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].executionStartTime") SessionLogStoptTime=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].logTime") SessionLogDurationS=$(echo $(( $(date -d "$SessionLogStoptTime" "+%s") - $(date -d "$SessionLogStartTime" "+%s") ))) SessionLogDurationB=$(echo $(($(($SessionLogDurationS - $SessionLogDurationS/86400*86400))/3600))h:$(($(($SessionLogDurationS - $SessionLogDurationS/86400*86400))%3600/60))m:$(($(($SessionLogDurationS - $SessionLogDurationS/86400*86400))%60))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 ;; esac ;; PolicyRdsSnapshot) SessionLogMessage=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].message") case $SessionLogMessage in Processing*) SessionLogWorkloadName=$(echo $SessionLogMessage |awk '{print $2}' | sed 's/.$//') SessionLogWorkloadTransferred="N/A" SessionLogWorkloadType="RDS Snapshot" SessionLogStartTime=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].executionStartTime") SessionLogStoptTime=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].logTime") SessionLogDurationS=$(echo $(( $(date -d "$SessionLogStoptTime" "+%s") - $(date -d "$SessionLogStartTime" "+%s") ))) SessionLogDurationB=$(echo $(($(($SessionLogDurationS - $SessionLogDurationS/86400*86400))/3600))h:$(($(($SessionLogDurationS - $SessionLogDurationS/86400*86400))%3600/60))m:$(($(($SessionLogDurationS - $SessionLogDurationS/86400*86400))%60))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 ;; esac ;; PolicyEfsBackup) SessionLogMessage=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].message") case $SessionLogMessage in Processing*) SessionLogWorkloadName=$(echo $SessionLogMessage |awk '{print $2}' | sed 's/.$//') SessionLogWorkloadTransferred="N/A" SessionLogWorkloadType="EFS Backup" SessionLogStartTime=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].executionStartTime") SessionLogStoptTime=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].logTime") SessionLogDurationS=$(echo $(( $(date -d "$SessionLogStoptTime" "+%s") - $(date -d "$SessionLogStartTime" "+%s") ))) SessionLogDurationB=$(echo $(($(($SessionLogDurationS - $SessionLogDurationS/86400*86400))/3600))h:$(($(($SessionLogDurationS -$SessionLogDurationS/86400*86400))%3600/60))m:$(($(($SessionLogDurationS - $SessionLogDurationS/86400*86400))%60))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 ;; esac ;; PolicyEfsBackupCopy) SessionLogMessage=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].message") case $SessionLogMessage in Processing*) SessionLogWorkloadName=$(echo $SessionLogMessage |awk '{print $2}' | sed 's/.$//') SessionLogWorkloadTransferred="N/A" SessionLogWorkloadType="EFS Backup Copy" SessionLogStartTime=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].executionStartTime") SessionLogStoptTime=$(echo "$veeamVBASessionsLogBackupUrl" | jq --raw-output ".log[$arraysessionslogbackup].logTime") SessionLogDurationS=$(echo $(( $(date -d "$SessionLogStoptTime" "+%s") - $(date -d "$SessionLogStartTime" "+%s") ))) SessionLogDurationB=$(echo $(($(($SessionLogDurationS - $SessionLogDurationS/86400*86400))/3600))h:$(($(($SessionLogDurationS -$SessionLogDurationS/86400*86400))%3600/60))m:$(($(($SessionLogDurationS - $SessionLogDurationS/86400*86400))%60))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 ;; esac ;; esac arraysessionslogbackup=$arraysessionslogbackup+1 done echo "" >> $html echo "
" >> $html echo "$reportDate" >> $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 "
$SessionLogWorkloadName$SessionLogWorkloadType" >> $html echo "$SessionLogStatus" >> $html echo "$SessionLogStartB$SessionLogWorkloadTransferred$SessionLogDurationB
$SessionLogWorkloadName$SessionLogWorkloadType" >> $html echo "$SessionLogStatus" >> $html echo "$SessionLogStartB$SessionLogWorkloadTransferred$SessionLogDurationB
$SessionLogWorkloadName$SessionLogWorkloadType" >> $html echo "$SessionLogStatus" >> $html echo "$SessionLogStartB$SessionLogWorkloadTransferred$SessionLogDurationB
$SessionLogWorkloadName$SessionLogWorkloadType" >> $html echo "$SessionLogStatus" >> $html echo "$SessionLogStartB$SessionLogWorkloadTransferred$SessionLogDurationB
$SessionLogWorkloadName$SessionLogWorkloadType" >> $html echo "$SessionLogStatus" >> $html echo "$SessionLogStartB$SessionLogWorkloadTransferred$SessionLogDurationB
EFS Workloads$SessionLogWorkloadType" >> $html echo "$SessionLogStatus" >> $html echo "$SessionLogStartB$SessionLogWorkloadTransferred$SessionLogDurationB
EFS Workloads$SessionLogWorkloadType" >> $html echo "$SessionLogStatus" >> $html echo "$SessionLogStartB$SessionLogWorkloadTransferred$SessionLogDurationB
" >> $html echo "
 
" >> $html echo "
" >> $html echo "
" >> $html arraysessionsbackup=$arraysessionsbackup+1 done echo "
Veeam Backup for AWS - Hostname: $veeamBackupAWSServer Version: $version
" >> $html #Sending Email to the user cat $html | s-nail -M "text/html" -s "$veeamBackupAWSServer - Daily Veeam Backup for AWS Report" $email_add