#!/bin/bash ## .SYNOPSIS ## HTML Report to consume easily via EMAIL, or from the Report Directory ## ## .DESCRIPTION ## This Script will query the Veeam Backup for Microsoft 365 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_microsoft365_email_report.sh ## ORIGINAL NAME: veeam_aws_email_report.sh ## LASTEDIT: 03/08/2021 ## VERSION: 1.0 ## KEYWORDS: Veeam, HTML, Report, Microsoft 365 ## .Link ## https://jorgedelacruz.es/ ## https://jorgedelacruz.uk/ # Configurations ## # Endpoint URL for login action veeamUsername="YOURVEEAMBACKUPUSER" veeamPassword="YOURVEEAMBACKUPPASS" veeamRestServer="YOURVEEAMBACKUPFORMICROSOFT365IP" veeamRestPort="4443" #Default Port ## System Variables sessionsJob="48" #Based on the VBO schedule, 48 means running the job every 30 minutes for the last 24 hours reportDate=$(date "+%A, %B %d, %Y %r") reportDatePath=$(date "+%A%B%d%Y") reportDateTo=$(date "+%Y-%m-%d") reportDateFrom=$(date -d "$reportDateTo" '+%s') reportPath="/home/oper/vbo_daily_reports" 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 "grant_type=password&username=$veeamUsername&password=$veeamPassword&refresh_token=%27%27" "https://$veeamRestServer:$veeamRestPort/v5/token" -k --silent | jq -r '.access_token') ## # Veeam Backup for Microsoft 365 Jobs Overview. This part will check VBO Jobs Overview ## veeamVBOUrl="https://$veeamRestServer:$veeamRestPort/v5/Jobs" veeamJobsUrl=$(curl -X GET --header "Accept:application/json" --header "Authorization:Bearer $veeamBearer" "$veeamVBOUrl" 2>&1 -k --silent) declare -i arrayJobs=0 for id in $(echo "$veeamJobsUrl" | jq -r '.[].id'); do SessionPolicyName=$(echo "$veeamJobsUrl" | jq --raw-output ".[$arrayJobs].name" | awk '{gsub(/ /,"\\ ");print}') idJob=$(echo "$veeamJobsUrl" | jq --raw-output ".[$arrayJobs].id") # Backup Job Sessions veeamVBOUrl="https://$veeamRestServer:$veeamRestPort/v5/Jobs/$idJob/JobSessions?limit=$sessionsJob" veeamJobSessionsUrl=$(curl -X GET --header "Accept:application/json" --header "Authorization:Bearer $veeamBearer" "$veeamVBOUrl" 2>&1 -k --silent) declare -i arrayJobsSessions=0 for id in $(echo "$veeamJobSessionsUrl" | jq -r '.results[].id'); do creationTime=$(echo "$veeamJobSessionsUrl" | jq --raw-output ".results[$arrayJobsSessions].creationTime") creationTimeUnix=$(date -d "$creationTime" +"%s") creationTimeP=$(date -d $creationTime "+%A, %B %d, %Y %r") creationTimeB=$(date -d $creationTime '+%r') endTime=$(echo "$veeamJobSessionsUrl" | jq --raw-output ".results[$arrayJobsSessions].endTime") endTimeUnix=$(date -d "$endTime" +"%s") endTimeB=$(date -d $endTime '+%r') totalDuration=$(($endTimeUnix - $creationTimeUnix)) totalDurationB=$(echo $(($(($totalDuration - $totalDuration/86400*86400))/3600))h:$(($(($totalDuration - $totalDuration/86400*86400))%3600/60))m:$(($(($totalDuration - $totalDuration/86400*86400))%60))s) SessionStatus=$(echo "$veeamJobSessionsUrl" | jq --raw-output ".results[$arrayJobsSessions].status") case $SessionStatus in Success) bcolor="#37872D" ;; Warning) bcolor="#FA6400" ;; Failed) bcolor="#C4162A" ;; esac processingRate=$(echo "$veeamJobSessionsUrl" | jq --raw-output ".results[$arrayJobsSessions].statistics.processingRateBytesPS") processingRateP=$(echo "scale=2; $processingRate/1024" | bc) readRate=$(echo "$veeamJobSessionsUrl" | jq --raw-output ".results[$arrayJobsSessions].statistics.readRateBytesPS") readRateP=$(echo "scale=2; $readRate/1024" | bc) writeRate=$(echo "$veeamJobSessionsUrl" | jq --raw-output ".results[$arrayJobsSessions].statistics.writeRateBytesPS") writeRateP=$(echo "scale=2; $writeRate/1024" | bc) transferredData=$(echo "$veeamJobSessionsUrl" | jq --raw-output ".results[$arrayJobsSessions].statistics.transferredDataBytes") transferredDataP=$(echo "scale=2; $transferredData/1024" | bc) processedObjects=$(echo "$veeamJobSessionsUrl" | jq --raw-output ".results[$arrayJobsSessions].statistics.processedObjects") bottleneck=$(echo "$veeamJobSessionsUrl" | jq --raw-output ".results[$arrayJobsSessions].statistics.bottleneck") if [[ $creationTimeUnix < $reportDateFrom ]]; then break else #Generating HTML file html="$reportPath/Microsoft365-Job-Report-$SessionPolicyName-$reportDatePath.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 arrayJobsSessions=$arrayJobsSessions+1 fi done echo "" >> $html echo "" >> $html echo "" >> $html echo "" >> $html echo "
Backup job: $SessionPolicyName" >> $html echo '
Veeam Backup for Microsoft Office 365
' >> $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 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 "$creationTimeP" >> $html echo "
" >> $html echo "Start time" >> $html echo "$creationTimeB" >> $html echo "" >> $html echo "
" >> $html echo "End time" >> $html echo "$endTimeB
" >> $html echo "Duration" >> $html echo "$totalDurationB
" >> $html echo "Processing Rate" >> $html echo "$processingRateP KB/s" >> $html echo "Read Rate" >> $html echo "$readRateP KB/s
" >> $html echo "Write Rate" >> $html echo "$writeRateP KB/s" >> $html echo "Transferred Data" >> $html echo "$transferredDataP KB
" >> $html echo "Processed Objects" >> $html echo "$processedObjects" >> $html echo "Bottleneck" >> $html echo "$bottleneck
" >> $html echo "
" >> $html echo "
 
Veeam Backup for Microsoft 365 - Hostname: $veeamRestServer
" >> $html echo "
" >> $html echo "
" >> $html echo "" >> $html echo "" >> $html #Sending Email to the user cat $html | s-nail -M "text/html" -s "$veeamRestServer - Backup Job: $SessionPolicyName - Daily Veeam Backup for Microsoft 365 Report" $email_add arrayJobs=$arrayJobs+1 done