Syncro MSP PowerShell Script: Veeam Backups monitoring

These two scripts are used with Syncro MSP and Veeam Enterprise Backup and Replication to monitor the status of the backups and alert if there are errors. 

Script 1: Veeam Backup Alert daily Errors and Warnings
Checks for errors in the event logs and should be run frequently. We run them once per hour.

Script 2: 
checks the event logs for successful job completion and that all the Veeam services are running. This is designed to catch catastrophic failures that may not report anything. We run this script once a day.

We are making these scripts available to the public to give back to those who have helped us along the way. Feel free to use these scripts for any purpose but please retain credits along with the code.

We also encourage feedback and comments on any bugs or improvements.

Disclaimer: These scripts are available AS IS. You are fully responsible for the function and operation of these scripts.

 

Veeam Backup Alert daily Errors and Warnings

Import-Module $env:SyncroModule

# Create RMMAlerts on Veeam issues in the past day
# Gary Herbstman, Byte Solutions Inc., Jan 2021, https://www.bytesolutions.com
# This was based on the existing Syncro Veeam library script that does not work.
# This script looks for all Warnings and Errors in the Veeam event log and excludes any events listed in the $ExcludeEvents variable.

$BeginDate = (Get-Date).AddDays(-1)
$EntryTypes = @("Error","Warning")

# List of EventIDs to ignore
# Event 1, New error in Veeam 11 when starting the console. Run colsole as admin to eliminate.
# Event 40002, Random SOBR offload error random when copying files to cloud storage. Seems to self correct.
$ExcludeEvents = @('24070','42','1','40002')

Try {
    # Get any Veeam error or warning events in the past 24 hours.
    # Filter out event 24070. A Veeam 10 bug is creating this event. Expected fix in V11
    $Events = Get-EventLog -LogName "Veeam Backup" -EntryType $EntryTypes -After $BeginDate | Where-Object {$_.EventID -notin $ExcludeEvents}
    
    if($Events.count -gt 0) {
      # write-host "Veeam Backup failures found since: $BeginDate"
      $Messages = "Veeam Backup Failures on $($Env:computername) since: $BeginDate `r`n`r`n"
      For ($i=0; $i -le $Events.count; $i++) {
          $Messages = $Messages +  $Events[$i].TimeGenerated + " " + $Events[$i].EntryType + " " + $Events[$i].Message + "`r`n" + $Events[$i].ReplacementStrings + "`r`n`r`n"
      }
      write-host $Messages
      Rmm-Alert -Category "veeam_backup_failed" -Body $Messages
      Exit 2
    } else {
        write-host "No Veeam Backup errors found."
    }
}

Catch { 
    # Let Syncro know there was a script error
    write-host "Script runtime Error`r`n $error[0]"
    Exit 1
}

Veeam Backup Alert – no success events in X days

# Create RMM Alerts on Veeam no success in X days.
# Gary Herbstman, Byte Solutions Inc., Jan 2021, https://www.bytesolutions.com
# Alert if there have not been any successful Veeam Backup jobs that completed in the past X days. 
# This is good to detect catastrophic failures where Veeam event logs are not being updated.
# Update the line below for your desired number of days.
# Suggest running once per day

# Number of days back to check for success. Default: 3
$days2Check = -3
$alertCategory = "veeam_backup_failed"

$filter = @{
    LogName = 'Veeam Backup'
    ID = 0
    StartTime = (Get-Date).AddDays($days2Check)
    Level = 4
}

Try {
    Import-Module $env:SyncroModule

    # Get Veeam success events.
    $events = Get-WinEvent -FilterHashTable $filter -ErrorAction SilentlyContinue | Where-Object -Property Message -Match 'completed'

    if($events.count -eq 0) {
        $msg = "Veeam Backup, No recent completed backups found."
        write-Output $msg
        Rmm-Alert -Category $alertCategory -Body $msg
    }
    else {
        write-host "Veeam Backup, Recent success event(s) found."
    }
}

Catch { 
    # Let Syncro know there was a script error
    Exit 1
}

# We may as well also check that all the expected Veeam services are running
# List of Veeam 11 services to check
$VeeamServices = @('Veeam.Archiver.Proxy','Veeam.Archiver.Service','VeeamAWSSvc','VeeamAzureSvc','VeeamBackupCdpSvc','VeeamBackupRESTSvc','VeeamBackupSvc','VeeamBrokerSvc','VeeamCatalogSvc','VeeamCloudSvc','VeeamDeploySvc','VeeamDistributionSvc','VeeamEnterpriseManagerSvc','VeeamExplorersRecoverySvc','VeeamFilesysVssSvc','VeeamMountSvc','VeeamNFSSvc','VeeamRESTSvc','VeeamTapeSvc','VeeamTransportSvc','VeeamVssProviderSvc')

$ServiceStopped = 0
Foreach ($Service in $VeeamServices){
    if((Get-Service -Name $Service).Status -ne "Running") {
        Write-Output "Service $Service stopped."
		$ServiceStopped++
	}
}

If ($ServiceStopped -ne 0) {
    $msg = "$ServiceStopped Veeam services are stopped."
	Write-Output $msg
	Rmm-Alert -Category $alertCategory -Body $msg
} else {
    Write-Output "All Veeam services are running"
}

Leave a Comment

Call Now Button