Professional Documents
Culture Documents
Veeam Check For Failed Backups With Nagios
Veeam Check For Failed Backups With Nagios
ps1
asnp "VeeamPSSnapIn" -ErrorAction SilentlyContinue
####################################################################
# Configuration
# vCenter server
$vcenter = "vcenter.yourdomain.com"
# To Exclude VMs from report add VM names to be excluded as follows
$excludevms=@("")
# Get a list of all VMs from vCenter and add to hash table, assume Unprotected
$vms=@{}
# only monitor those VMs on Production. To monitor all VMs registered on vCenter,
just remove the and -match
foreach ($vm in (Find-VBRObject -Server $vcenterobj -WarningAction
"SilentlyContinue" | Where-Object {$_.Type -eq "VirtualMachine" -and
$_.Datastores -match "DATASTORE_PRODUCTION" })) {
if (!($excludedvms.ContainsKey($vm.Name) -or $vms.ContainsKey($vm.Name))) {
$vms.Add($vm.Name, "Unprotected")
}
}
# Find all backup job sessions that have ended in the last 24 hours
# Find all successfully backed up VMs in selected sessions (i.e. VMs not ending in
failure) and update status to "Protected"
foreach ($session in $vbrsessions) {
foreach ($vm in ($session.gettasksessions() | Where-Object {$_.Status -ne
"Failed"} | ForEach-Object { $_ })) {
if($vms.ContainsKey($vm.Name)) {
$vms[$vm.Name]="Protected"
}
}
}
#$failedbackups=""
#$number_of_backups_with_errors = 0
# Output VMs in color coded format based on status.
foreach ($vm in $vms.Keys)
{
if ($vms[$vm] -eq "Protected") {
#write-host -foregroundcolor green "$vm is backed up"
} else {
#write-host -foregroundcolor red "$vm is NOT backed up"
$backups_with_errors = $true
$failedbackups=$failedbackups+":"+$vm
$number_of_backups_with_errors = $number_of_backups_with_errors+1
}
}
} else {
if ($number_of_backups_with_errors -eq $nul)
{Write-Host "No failed backups on DATASTORE_PRODUCTION."
exit 0
} else {
Write-Host "$number_of_backups_with_errors missing Veeam Backups $failedbackups"
}
exit 1
}