June 6, 2020

PowerShell :: checking VEEAM backups are running for Nagios

PowerShell ISE logo
(Last Updated On: 3rd October 2016)

This is my second PowerShell script to check VEEAM is happy (the first one is here)and focuses on making sure jobs are still running.  Whilst its rare the job engine will freeze, I used to get this problem all the time with other products and so got used to writing checks for it.  The script is super simple and a good demonstration of how we use a little logic to provide those exit codes back through NsClient and into Nagios.  If you need a guide to get this up and running with NsClient, take a look here.

All this script is doing is grabbing the a list of all the backup jobs, filtering out all the none backup jobs,  sort the jobs by the time they were created and then select the first job of the resulting array.  We then use time they were created to get a PowerShell date object so we can compare it with local computer time.  If the last backup creation time was before yesterday (local computer time – 1 day) it exits with a 2 (Nagios critical), if it was before 12 hours ago it exits with a 1 (Nagios WARNING).  If it doesn’t match either of these, it will exit with a 0 (Nagios OK).

It also uses echo to return a message string to Nagios which doesn’t change and simply gives some information about the last backup.

There is nothing to change in this script, you should be able to simply copy it and save it.

Add-PSSnapin VeeamPSSnapIn
$LastBackup = Get-VBRBackup | ? TypeToString -match "(VMware Backup$|Hyper-V Backup$)" | sort [datetime]LastPointCreationTime -Descending | select -First 1
$LastBackupName = $LastBackup.Name
$LatestBackupTimeStamp = get-date ($LastBackup).LastPointCreationTime
echo "Last backup :: $LastBackupName :: $LatestBackupTimeStamp"
if ($LatestBackupTimeStamp -lt (Get-Date).AddDays(-1))
exit 1
elseif ($LatestBackupTimeStamp -lt (Get-Date).AddHours(-12))
exit 2
exit 0

UPDATE: Annoyingly the LastPointCreationTime property is a string, so the sort fails unless you recast as datetime.

Previous «
Next »

Simon is a sysadmin for a global financial organisation and specialises in Windows, security and automation.

1 Comment

  1. Pingback: PowerShell :: checking VEEAM backups for Nagios – Synack

Leave a Reply

Subscribe to SYNACK via Email

%d bloggers like this: