Hi There
I have written a PowerShell script which you can use for the extended script sensor. You only need to specify the '%host' variable in the sensor settings. The sensor extracts the backup events and the time since last backup has run. The script is tested on a Windows Server 2012R2 using the built-in backup tool.
param([string]$hostname = "N/A")
Invoke-Command -ComputerName $hostname{
$today=(Get-Date)
$dateshift=(Get-Date).AddHours(-24)
$EventError=Get-WinEvent -LogName Microsoft-Windows-Backup| Where-Object {$_.TimeCreated -gt $dateshift} | Where-Object {$_.LevelDisplayName -eq "Error"}
$EventWarning=Get-WinEvent -LogName Microsoft-Windows-Backup| Where-Object {$_.TimeCreated -gt $dateshift} | Where-Object {$_.LevelDisplayName -eq "Warning"}
$EventOK=Get-WinEvent -LogName Microsoft-Windows-Backup| Where-Object {$_.TimeCreated -gt $dateshift} | Where-Object {$_.LevelDisplayName -eq "Information"}
$backupsets=Get-WBBackupSet
$lastbackup=(Get-Date)-($backupsets.BackupTime |Measure-Object -Maximum |Select-Object -ExpandProperty Maximum)
$lastbkround=[math]::Floor($lastbackup.TotalHours)
Write-Host '<?xml version="1.0" encoding="Windows-1252" ?>'
Write-Host '<prtg>'
Write-Host '<result>'
Write-Host '<channel>Error Events</channel>'
Write-Host '<value>'$EventError.Count'</value>'
Write-Host '</result>'
Write-Host '<result>'
Write-Host '<channel>Warning Events</channel>'
Write-Host '<value>'$EventWarning.Count'</value>'
Write-Host '</result>'
Write-Host '<result>'
Write-Host '<channel>Information Events</channel>'
Write-Host '<value>'$EventOK.Count'</value>'
Write-Host '</result>'
Write-Host '<result>'
Write-Host '<channel>Hours Since Last Backup</channel>'
Write-Host '<value>'$lastbkround'</value>'
Write-Host '</result>'
Write-Host '</prtg>'
Add comment