Using PRTG to monitor Windows Server backup

by Jesse Rink

SHARE

Home » Articles and insights » Using PRTG to monitor Windows Server backup

While PRTG (available at http://www.paessler.com) has many cool sensors available out-of-box for monitoring valuable network and server related data, unfortunately, it doesn’t have an easy way to monitor the Windows Server Backup service on Windows 2008 R2 and Windows 2012 R2 servers. Today, many small and medium businesses, and even remote branch offices in larger corporate environments, rely on Windows Server Backup to effectively backup their critical server data, having this sensor available in PRTG to report on the status of success/failures of those Windows Server Backups can be very helpful – especially if you tie them to email alerts when those backups actually fail.

Setting up this PRTG sensor requires a custom Powershell script and some preliminary configuration on the servers that are being monitored. I managed to cook something up in Powershell using the built-in Microsoft Windows Server Backup Cmdlets that does the trick and is very easy to use.  I plan on making use of this sensor pretty much everywhere where customers utilize Windows Server Backups and already have PRTG in place as a network/server performance monitoring solution.

The script took me about 8 hours to figure out and test, but would probably have taken much less for someone with basic Powershell scripting knowledge (my knowledge with Powershell is very minimal, at best). One thing I learned during the process is: We could make PRTG report on just about ANYTHING – so long as the data or information could be gathered via Windows Powershell (and these days, it seems like just about anything can be gotten via Windows Powershell commands).  Just food for thought…

This Powershell script and PRTG sensor is easily going to save me countless hours every month – no longer will have I have to manually check 20+ servers at various customers to see if their Windows Server Backups are successfully running or not. As with any PRTG sensor, you can specify down/fail conditions when you want an email notification sent, alerting you of a given backup failure.   Furthermore, it will also report to you how many days since the last Successful backup was taken.

CASE STUDY

This Wisconsin manufacturer needed to modernize its IT infrastructure to support rapid business growth.

Discover what they did
windows server backup

Take a look at Figure 1 and you will see how PRTG reports this information.
Note – a  backup status of 0 (in the primary channel) is equal to a successful backup.

Here’s the Powershell script you need…. Instructions on how to use the Powershell script with PRTG are below.

# Windows Server Backup status sensors for PRTG
# Jesse Rink / Source One Technology
#
#
# This Powershell script will provide the following data as a PRTG sensor:
# Channel 1 – If the Windows Server Backup last taken Succeeded or Failed
# Channel 2 – Number of days since the last Successful Windows Server Backup was last taken
#
#
# — Windows 2008 R2 Prerequisites — (on the remote server that will be monitored)
# Install the Windows Server Backup feature *with* the Command-line Tools option.
#
# Enable Windows Remoting (WinRM)
# Open an elevated Powershell console and type: Enable-PSRemoting
#
#
# Set Execution Policy in 32bit Powershell
# PRTG runs Powershell commands under a 32bit Execution Policy.
# This script will not execute in PRTG until the 32bit Execution Policy
# is changed from the default “Restricted” policy to a “RemoteSigned” policy.
#
# ALERT: You need to run these commands in 32Bit PowerShell via the path to
# Powershell.exe provided.
#
# Use the following commands to change the 32bit Execution Policy
# Start powershell using the following command (note the different from normal path)
# %SystemRoot%SysWOW64WindowsPowerShellv1.0powershell.exe
# Then run Get-ExecutionPolicy to see the current 32-bit execution policy.
# Change the ExecutionPolicy by the following command
# PS C:> Set-ExecutionPolicy RemoteSigned
# Verify again with Get-ExecutionPolicy to see that it now reports RemoteSigned
# PS C:> Get-ExecutionPolicy
# RemoteSigned
# PS C:>
# If you see multiple execution policies listed, you're modifying the 64bit policies.
#
#
#
# — Windows 2012 R2 Prerequisites — (on the remote server that will be monitored)
# Install the Windows Server Backup feature
#
# Set Execution Policy in 32bit Powershell
# PRTG runs Powershell commands under a 32bit Execution Policy.
# This script will not execute in PRTG until the 32bit Execution Policy
# is changed from the default “Restricted” policy to a “RemoteSigned” policy.
#
# ALERT: You need to run these commands in 32Bit PowerShell via the path to
# Powershell.exe provided.
#
# Use the following command to change the 32bit Execution Policy:
# Start PowerShell using the following command (note the different from normal path)
# %SystemRoot%SysWOW64WindowsPowerShellv1.0powershell.exe
# Then run Get-ExecutionPolicy to see the current 32-bit execution policy.
# Change the ExecutionPolicy by the following command
# PS C:> Set-ExecutionPolicy RemoteSigned
# Verify again with Get-ExecutionPolicy to see that it now reports RemoteSigned
# PS C:> Get-ExecutionPolicy
# RemoteSigned
# PS C:>
# If you see multiple execution policies listed, you're modifying the 64bit policies.
#
#
#
#
# — PRTG Prerequisites —
# You will likely need to change your PRTG Probe service from
# running under the Local System account to a domain account
# that has administrative privileges on the remote systems.
#
#
# — Miscellaneous Notes —
#
# Channel #1
# The BackupStatus sensor will report 0 if the last backup was Successful. Any other
# integer other than 0 likely means the last backup has Failed.
# As a result, the BackupStatus sensor’s channel limit for error/down is set
# to report an error/down condition for any response of 1 or higher.
#
# Channel #2
# The “X Days Since Last Successful Backup” sensor’s channel limit for error/down
# is set to report an error/down condition for any response of 3 days or higher.
# Please adjust this to your own preference based on the frequency of your backups.
#
#
#
# Save this Powershell script file WSB-Sensor.ps1 to the PRTG Network MonitorCustom SensorsEXEXML directory
#
# To use this PRTG Sensor, find your device and select Add Sensor.
# In the search box that appears, type “exe” and select the EXE/Script Advanced sensor.
# Change the sensor name to “Windows Server Backups – Status”
# Set the EXE/Script as WSB-Sensor.ps1
# Set the Parameter as “Servername.domain.com”
#
# Once the sensor has been added, please remember…
# ..There are 2 different channels for this sensor that provide different data.
# ..Recommend setting the interval time for this sensor to 10 minutes or higher.
# ..Recommend setting the Notifications to automatically trigger email alerts when WSB backups fail.

$DEVICE=$args[0]

$BackupStatus = Invoke-Command -Computername $DEVICE -ScriptBlock {add-Pssnapin Windows.serverbackup -ErrorAction SilentlyContinue; Get-WBSummary}
$LastDate = $BackupStatus.LastSuccessfulBackupTime
$LastBackupStatus = echo $BackupStatus|Select-Object -ExpandProperty LastBackupResultHR
$CurrentDate = Get-Date
$LastBackupDays = echo ($CurrentDate-$LastDate).Days

“<prtg>”
“  <result>”
“    <channel>BackupStatus</channel>”
“    <value>$LastBackupStatus</value>”
“    <LimitMaxError>1</LimitMaxError>”
“    <LimitMode>1</LimitMode>”
“  </result>”
“  <result>”
“    <channel>X Days Since Last Successful Backup</channel>”
“    <value>$LastBackupDays</value>”
“    <LimitMaxError>3</LimitMaxError>”
“    <LimitMode>1</LimitMode>”
“  </result>”
“</prtg>”

Jesse Rink

Jesse Rink

Jesse is the owner of Source One Technology and has been providing IT consulting services to Enterprises, SMBs, schools, and nonprofits in Waukesha, Milwaukee, Dane, Washington , Jefferson, Ozaukee, Kenosha, Racine counties and across Wisconsin for over 18 years.

Tired of wasting time and money on frustrating IT issues and vendors?
We're hiring!  Take a look at our engineering roles in Wisconsin.
View jobs