Monitoring Veeam FLR sessions using PowerCLI

Monitoring Veeam FLR sessions using PowerCLI

Veeam logo
Veeam Backup & Replication comes with a few built-in PowerShell cmdlets. Sadly I couldn’t find a cmdlet which allows me to monitor running Veeam FLR sessions.

Keep in mind that this post only works when you run a FLR which is a non-Windows virtual machine!!

When you perform a restore, Veeam Backup & Replication will start an extra virtual machine which runs with the name VeeamFLR-SERVERNAME-randomhash. The script below will see if a restore is running for a defined amount of hours and then update you with an e-mail.

# Script to determine running Veeam FLR sessions (type: Other OS)
# E-mails a small overview with open sessions with XX hours uptime

# Fill in below
# Set the vCenter Server address
$vcenter = "hostname/ip"
# Set the SMTP Server address
$smtp = "mail.company.com"
# Set the Email address to receive from
$emailfrom = "veeamflr@company.com"
# Set the Email address to send the email to
$emailto = "you@company.com"
# Set the Email subject
$emailsubject = "Veeam FLR Session Running!"
# Uptime a session can have before sending an e-mail (defined in hours)
$hours = "1"

# Don't change below!
New-VIProperty -ObjectType VirtualMachine -Name BootTime
-ValueFromExtensionProperty Summary.Runtime.BootTime -Force | Out-Null

# E-mail function
function Send-Mail($to, $from, $subject, $smtpserver, $body) {
	$mailer = new-object Net.Mail.SMTPclient($smtpserver)
	$msg = new-object Net.Mail.MailMessage($from, $to, $subject, $body)
	$msg.IsBodyHTML = $false
	$mailer.send($msg)
}

# Connect to vCenter
Connect-VIServer -Server $vcenter | Out-Null

# Store sessions in a variabele
$runningsessions = @()

# Loop through VM's starting with "VeeamFLR"
foreach ($vm in Get-VM | where {$_.Name.ToLower().Contains("veeamflr")} |
Select Name, BootTime) {
	if ($vm.BootTime -ne $null) {
		$boottime = [DateTime]::Parse($vm.BootTime.ToLocalTime().DateTime)
		$uptime = [DateTime]::Now.Subtract($boottime)
		$upthours = [int]::Parse($uptime.Hours)
		if ($upthours -gt $hours) {
			$runningsessions += $vm.Name + " `r`n"
		}
	}
}

# Only send an e-mail if there are running sessions
if ($runningsessions -ne $null) {
	$body = "Veeam FLR report:`r`n"
	$body += "===============`r`n`r`n"
	$body += $runningsessions | Sort-Object

	# Send the e-mail
	Send-Mail -to $emailto -from $emailfrom -subject $emailsubject
-smtpserver $smtp -body $body
}

# Disconnect from vCenter
Disconnect-VIServer -Server $vcenter -Confirm:$false | Out-Null

You can automate this task by running the script as a scheduled task.

Enjoy!

Comments are closed.