So far ive been using a script to give out alerts (by either giving a certain text in the powershell output or write it in the event logs) when backups have failed in the last 24 hours.
However now a colleague of mine made a smart remark .. what if for some weird reason or error, the backup hasnt run in the last 24 hours. And i honestly came to the conclusion that we wouldnt notice if that was the case.
Now hereby the question. Does someone have a script or a start up to a script that takes the date from the PC/Server and looks if there are jobs that have NOT ran in the last 24 hours (or x hours/days for that matter) so that the script may give me the option to output a certain code or write into an eventlog when this is the case.
I kinda would prefer it to be totally seperate from the already used script but just to be sure i will simply post the script we run atm here to.
Code: Select all
#Datamex Remote Monitoring als source aanmaken in application eventlog:
New-EventLog -LogName Application -Source "Datamex Remote Monitoring" > $null
#requires -Version 1
Function Get-VeeamHistory
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $true, Position = 0)]
[System.Int32]
$Days
)
Add-PSSnapin -Name VeeamPSSnapin
$colJobHistory = @()
$JobHistory = Get-VBRBackupSession |
Where-Object -FilterScript {
$_.CreationTime -ge (Get-Date).AddDays(-$Days)
} |
Sort-Object -Property CreationTime -Descending
ForEach ($Job In $JobHistory)
{
$objJobHistory = New-Object -TypeName System.Object
$objJobHistory | Add-Member -MemberType NoteProperty -Name Name -Value $Job.JobName
$objJobHistory | Add-Member -MemberType NoteProperty -Name StartTime -Value ($Job.CreationTime -f [datetime])
$objJobHistory | Add-Member -MemberType NoteProperty -Name EndTime -Value ($Job.EndTime -f [datetime])
$Duration = New-TimeSpan -Start $Job.CreationTime -End $Job.EndTime
$Duration = '{0:00}:{1:00}:{2:00}' -f $Duration.Hours, $Duration.Minutes, $Duration.Seconds
$objJobHistory | Add-Member -MemberType NoteProperty -Name Duration -Value $Duration
$AuxData = [xml] $Job.AuxData
$DataSizeB = $AuxData.AuxData.CBackupStats.BackupSize
$DataSizeGB = [math]::round($DataSizeB / 1GB,2)
$objJobHistory | Add-Member -MemberType NoteProperty -Name DataSizeGB -Value $DataSizeGB
$objJobHistory | Add-Member -MemberType NoteProperty -Name Result -Value $Job.Result
#$objJobHistory | Add-Member -MemberType NoteProperty -Name ErrorMessage -Value $Job.ErrorMessage
Switch ($Job.Result)
{
'Success'
{
$AEMResult = 0
Break
}
'Warning'
{
$AEMResult = 1
Break
}
'Failed'
{
$AEMResult = 2
Break
}
default
{
$AEMResult = 1
Break
}
}
$objJobHistory | Add-Member -MemberType NoteProperty -Name AEMResult -Value $AEMResult
$colJobHistory += $objJobHistory
}
Return $colJobHistory
}
Function Exit-AEMResult
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.Object]
$AEMResult
)
Begin
{
$AEMResultCode = 0
}
Process
{
Write-Output -InputObject $AEMResult | Select-Object -Property * -ExcludeProperty AEMResult
If ($AEMResult.AEMResult -gt $AEMResultCode)
{
$AEMResultCode = $AEMResult.AEMResult
}
}
End
{
Write-Host -NoNewline -Object 'Backup Check Result: '
Switch ( $AEMResultCode )
{
0
{
Write-Host -Object 'Success'
Write-EventLog -logname Application -Source "Datamex Remote Monitoring" -EntryType Information -EventId 7777 -Message "Veeam backups afgelopen 24 uur gelukt."
Exit 0
}
1
{
Write-Host -Object 'Warning'
Write-EventLog -logname Application -Source "Datamex Remote Monitoring" -EntryType Error -EventId 6666 -Message "Veeam warnings gedetecteerd!"
Exit 0
}
2
{
Write-Host -Object 'Failure'
Write-EventLog -logname Application -Source "Datamex Remote Monitoring" -EntryType Error -EventId 6666 -Message "Veeam Failure(s) gedetecteerd!"
Exit 1
}
}
}
}
Get-VeeamHistory -Days $env:Days | Exit-AEMResult