Add Azure Backup (MARS agent) collector

PowerShell script for servers running the MARS agent, run as a SYSTEM
scheduled task (hourly) under Windows PowerShell 5.1, which the
agent's MSOnlineBackup module targets. Each server is one dashboard job.

- Backup jobs from Get-OBJob (in progress and -Previous) within the
  lookback window; restores are ignored. Completed with failed bytes
  or an error reports as warning
- Next run computed from the backup and System State policy schedules;
  left empty for every-N-weeks schedules to avoid false Overdue alarms
- Property reads tolerate unknown names, since the agent's object
  model isn't documented; Get-MarsCollectorDiagnostics.ps1 dumps the
  real structure for checking
- Install-MarsCollector.ps1 mirrors the Veeam installer; tests/MockMars.ps1
  provides stand-in cmdlets

Not yet run against a real MARS agent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-07 15:23:46 -06:00
co-authored by Claude Opus 5.5
parent b4b703ceee
commit 10181e014b
6 changed files with 681 additions and 1 deletions
+56
View File
@@ -0,0 +1,56 @@
# Stand-ins for the MARS agent cmdlets, shaped like the properties the collector reads.
# Property names are best guesses until checked against Get-MarsCollectorDiagnostics.ps1 output.
#
# . ./tests/MockMars.ps1
# ./Send-MarsBackupStatus.ps1 -ConfigPath ./my-test-config.json -DryRun
# Fixed to the top of the hour, and IDs derived from times, so repeated runs see the same jobs
$now = Get-Date -Minute 0 -Second 0 -Millisecond 0
function New-StableGuid([string]$Seed) {
[guid]::new([Security.Cryptography.MD5]::Create().ComputeHash([Text.Encoding]::UTF8.GetBytes($Seed)))
}
function New-MockDatasource($Name, [long]$Done, [long]$Failed = 0, $ErrorInfo = $null) {
[pscustomobject]@{
Datasource = $Name
ByteProgress = [pscustomobject]@{ Total = $Done + $Failed; Progress = $Done; Failed = $Failed }
ErrorInfo = $ErrorInfo
}
}
function New-MockJob($Type, $Start, $End, $State, $Datasources = @(), $ErrorInfo = $null) {
[pscustomobject]@{
JobId = New-StableGuid "$Type|$($Start.Ticks)"
JobType = $Type
JobStatus = [pscustomobject]@{
JobState = $State; StartTime = $Start; EndTime = $End
DatasourceStatus = $Datasources; ErrorInfo = $ErrorInfo
}
}
}
$global:MockMarsRunning = @(
(New-MockJob 'Backup' $now.AddMinutes(-10) $null 'InProgress' @((New-MockDatasource 'D:\Shares' 2GB)))
)
$global:MockMarsPrevious = @(
(New-MockJob 'Backup' $now.AddHours(-12) $now.AddHours(-11) 'Completed' @(
(New-MockDatasource 'D:\Shares' 12GB), (New-MockDatasource 'System State' 8GB))),
(New-MockJob 'Backup' $now.AddHours(-36) $now.AddHours(-35) 'Completed' @(
(New-MockDatasource 'D:\Shares' 3GB 40MB))), # completed, but some files failed
(New-MockJob 'Backup' $now.AddHours(-30) $now.AddHours(-29.5) 'Failed' @() `
([pscustomobject]@{ ErrorCode = 100050; ErrorParamList = @([pscustomobject]@{ Name = 'Volume'; Value = 'D:' }) })),
(New-MockJob 'Recovery' $now.AddHours(-5) $now.AddHours(-4) 'Completed'), # a restore: must be ignored
(New-MockJob 'Backup' $now.AddDays(-5) $now.AddDays(-5).AddHours(1) 'Completed') # outside 48h lookback
)
# Daily at 21:00 and 03:00, weekdays only
$global:MockMarsPolicy = [pscustomobject]@{ PolicyName = 'Files' }
$global:MockMarsSchedule = [pscustomobject]@{
ScheduleRunDays = @([DayOfWeek]::Monday, [DayOfWeek]::Tuesday, [DayOfWeek]::Wednesday, [DayOfWeek]::Thursday, [DayOfWeek]::Friday)
ScheduleRunTimes = @($now.Date.AddHours(21), $now.Date.AddHours(3))
ScheduleWeeklyFrequency = 1
}
function Get-OBJob { param([int]$Previous) if ($PSBoundParameters.ContainsKey('Previous')) { $global:MockMarsPrevious } else { $global:MockMarsRunning } }
function Get-OBPolicy { $global:MockMarsPolicy }
function Get-OBSchedule { param($Policy) $global:MockMarsSchedule }