Check for Veeam Endpoint Backup

##################################################################################################
##### Icinga check for Veeam Enedpoint Backup. It does check of the last backup date. #####
##### Accepted arguments are: BackupJobName and period of days for backup e.g a > b = fail:) #####
##################################################################################################

asnp VeeamPSSnapin

$name = $args[0]
$period = $args[1]

$job = Get-VBRBackup -Name $name
$name = "'" + $name + "'"

$status = $job.LastPointCreationTime.Split()[0]
$date =(Get-Date -Format d)

$check_period=((Get-Date).AddDays(-$period).ToString('dd/MM/yyyy'))

if ($job -eq $null)
{
Write-Host "UNKNOWN! No such a job: $name."
exit 3
}

if ( $status -gt $check_period ){
Write-Host "Backp hasn't been run since" $status
exit 1
}
if ($status -lt $date){
Write-Host "Backup Successful for $name"
exit 0
}