Using PowerShell to monitor Backups

We are using a RMM that has integrated BackupExec monitoring. I’ve found that this integrated monitoring was somewhat lacking. It gave us the current job status and that’s about it, Meaning there was not really a way to resolve issues pre-preemptively.

To resolve this we’ve created the following monitoring PowerShell script and integrated it into our RMM solution. For your convenience we’ll dissect the script so you can re-use this in your own solution or set it as scheduled job ­čÖé

We’ll start by importing the BEMCLI module which is included in BackupExec 2012 and up.

#Setting default CLI
import-module bemcli 

After importing the BEMCLI We’ll be able to use the cmdlets that get us the info we want, in this case “get-BEAlert” which gives us the current Alerts that have not been acknowledged within BackupExec

#Getting Alerts
$Alerts = Get-BEAlert

Now that we have the Alerts stored in a variable we wil loop through the contents of the alerts to find what we require;

#Looping through the alerts and writing the message to the console
foreach($Alert in $Alerts){
write-host $Alert.message
}

Now that we see that the messages are posted in the console we’d of course like a better overview.

#Looping through the alerts and setting them.
foreach($Alert in $Alerts){

switch ($Alert.Category)
{
JobWarning{$JobWarning = "TRUE - $($Alert.Message)" }
JobFailure{$JobFailure = "TRUE - $($Alert.Message)"}
JobCancellation{$JobCancellation = "TRUE - $($Alert.Message)" }
CatalogError{$CatalogError = "TRUE - $($Alert.Message)"}
SoftwareUpdateWarning{$SoftwareUpdateWarning = "TRUE - $($Alert.Message)"}
SoftwareUpdateError{$SoftwareUpdateError = "TRUE - $($Alert.Message)" }
DatabaseMaintenanceFailure{$DatabaseMaintenanceFailure = "TRUE - $($Alert.Message)"}
IdrCopyFailed{$IdrCopyFailed = "TRUE - $($Alert.Message)"}
BackupJobContainsNoData{$BackupJobContainsNoData = "TRUE - $($Alert.Message)" }
JobCompletedWithExceptions{$JobCompletedWithExceptions = "TRUE - $($Alert.Message)"}
JobStart{$JobStart = "TRUE - $($Alert.Message)"}
ServiceStart{$ServiceStart = "TRUE - $($Alert.Message)"}
ServiceStop{$ServiceStop = "TRUE - $($Alert.Message)"}
DeviceError{$DeviceError = "TRUE - $($Alert.Message)"}
DeviceWarning{$DeviceWarning = "TRUE - $($Alert.Message)"}
DeviceIntervention{$DeviceIntervention = "TRUE - $($Alert.Message)"}
MediaError{$MediaError = "TRUE - $($Alert.Message)"}
MediaWarning{$MediaWarning = "TRUE - $($Alert.Message)" }
MediaIntervention{$MediaIntervention = "TRUE - $($Alert.Message)"}
MediaInsert{$MediaInsert = "TRUE - $($Alert.Message)"}
MediaOverwrite{$MediaOverwrite = "TRUE - $($Alert.Message)"}
MediaRemove{$MediaRemove = "TRUE - $($Alert.Message)"}
LibraryInsert{$LibraryInsert = "TRUE - $($Alert.Message)"}
TapeAlertWarning{$TapeAlertWarning = "TRUE - $($Alert.Message)"}
TapeAlertError{$TapeAlertError = "TRUE - $($Alert.Message)" }
IdrFullBackupSuccessWarning{$IdrFullBackupSuccessWarning = "TRUE - $($Alert.Message)"}
LicenseAndMaintenanceWarning{$LicenseAndMaintenanceWarning = "TRUE - $($Alert.Message)"}
default{$OtherErr = "TRUE - $($Alert.Message)" }
}
}

Now if we put this all together the result would be;

<# .SYNOPSIS Gets BackupExec information and reports on Running Alerts - Only works on BackupExec 2012 and higher. .DESCRIPTION Using BEMCLI we retrieve data from BACKUPEXEC, including multiple types of alerts, LastRunTime, etc. Currently Alerts are generated for the following catagories: JobWarning JobFailure JobCancellation CatalogError SoftwareUpdateInformation SoftwareUpdateWarning SoftwareUpdateError DatabaseMaintenanceFailure IdrCopyFailed IdrFullBackupSuccess BackupJobContainsNoData JobCompletedWithExceptions JobStart ServiceStart ServiceStop DeviceError DeviceWarning DeviceIntervention MediaError MediaWarning MediaIntervention MediaInsert MediaOverwrite MediaRemove LibraryInsert TapeAlertWarning TapeAlertError IdrFullBackupSuccessWarning LicenseAndMaintenanceWarning .LINK http://www.cyberdrain.com #>

#Setting default CLI
i#Setting default CLI
import-module bemcli 
#Getting Alerts
$Alerts = Get-BEAlert

#Looping through the alerts and setting them.
foreach($Alert in $Alerts){

switch ($Alert.Category)
{
JobWarning{$JobWarning = "TRUE - $($Alert.Message)" }
JobFailure{$JobFailure = "TRUE - $($Alert.Message)"}
JobCancellation{$JobCancellation = "TRUE - $($Alert.Message)" }
CatalogError{$CatalogError = "TRUE - $($Alert.Message)"}
SoftwareUpdateWarning{$SoftwareUpdateWarning = "TRUE - $($Alert.Message)"}
SoftwareUpdateError{$SoftwareUpdateError = "TRUE - $($Alert.Message)" }
DatabaseMaintenanceFailure{$DatabaseMaintenanceFailure = "TRUE - $($Alert.Message)"}
IdrCopyFailed{$IdrCopyFailed = "TRUE - $($Alert.Message)"}
BackupJobContainsNoData{$BackupJobContainsNoData = "TRUE - $($Alert.Message)" }
JobCompletedWithExceptions{$JobCompletedWithExceptions = "TRUE - $($Alert.Message)"}
JobStart{$JobStart = "TRUE - $($Alert.Message)"}
ServiceStart{$ServiceStart = "TRUE - $($Alert.Message)"}
ServiceStop{$ServiceStop = "TRUE - $($Alert.Message)"}
DeviceError{$DeviceError = "TRUE - $($Alert.Message)"}
DeviceWarning{$DeviceWarning = "TRUE - $($Alert.Message)"}
DeviceIntervention{$DeviceIntervention = "TRUE - $($Alert.Message)"}
MediaError{$MediaError = "TRUE - $($Alert.Message)"}
MediaWarning{$MediaWarning = "TRUE - $($Alert.Message)" }
MediaIntervention{$MediaIntervention = "TRUE - $($Alert.Message)"}
MediaInsert{$MediaInsert = "TRUE - $($Alert.Message)"}
MediaOverwrite{$MediaOverwrite = "TRUE - $($Alert.Message)"}
MediaRemove{$MediaRemove = "TRUE - $($Alert.Message)"}
LibraryInsert{$LibraryInsert = "TRUE - $($Alert.Message)"}
TapeAlertWarning{$TapeAlertWarning = "TRUE - $($Alert.Message)"}
TapeAlertError{$TapeAlertError = "TRUE - $($Alert.Message)" }
IdrFullBackupSuccessWarning{$IdrFullBackupSuccessWarning = "TRUE - $($Alert.Message)"}
LicenseAndMaintenanceWarning{$LicenseAndMaintenanceWarning = "TRUE - $($Alert.Message)"}
default{$OtherErr = "TRUE - $($Alert.Message)" }
}
}

Now you can schedulde this script in your own RMM or sent e-mails based on the result.:) Happy Scripting!

Kelvin Tegelaar Author

I am a Microsoft Certified System Engineer working for the Managed Services Provider Lime Networks B.V. in the Netherlands. I mostly enjoy automating business processes by deploying PowerShell solutions, but just have a large passion for Microsoft Technology in general. If you want to contact me directly you can find me on twitter here, or via email: Kelvin {at} limenetworks.nl

Comments

    Henk

    (September 11, 2016 - 11:06 am)

    Nice! thanks, not using together with e-mail script to monitor backupexec.

    Tip: the title does not contain backupexec but only backup. maybe chance it?

Leave a Reply

Your email address will not be published. Required fields are marked *