I'm trying to modify an existing Nagios plug-in in order to be able to monitor my tape backup job but I'd like for some validation since there seems to some differences between the available properties VBRJob and VBRTapeJob. Here's the original script:
Code: Select all
#################################################################################
#################################################################################
#################### Made by Tytus Kurek on September 2012 ####################
#################################################################################
#################################################################################
### This is a Nagios Plugin destined to check the last status and last run ###
### of Veeam Backup & Replication job passed as an argument. ###
#################################################################################
#################################################################################
# Adding required SnapIn
asnp VeeamPSSnapin
# Global variables
$name = $args[0]
$period = $args[1]
# Veeam Backup & Replication job status check
$job = Get-VBRJob -Name $name
$name = "'" + $name + "'"
if ($job -eq $null)
{
Write-Host "UNKNOWN! No such a job: $name."
exit 3
}
$status = $job.GetLastResult()
if($($job.findlastsession()).State -eq "Working"){
Write-Host "OK - Job: $name is currently in progress."
exit 0
}
if ($status -eq "Failed")
{
Write-Host "CRITICAL! Errors were encountered during the backup process of the following job: $name."
exit 2
}
if ($status -ne "Success")
{
Write-Host "WARNING! Job $name didn't fully succeed."
exit 1
}
# Veeam Backup & Replication job last run check
$now = (Get-Date).AddDays(-$period)
$now = $now.ToString("yyyy-MM-dd")
$last = $job.GetScheduleOptions()
$last = $last -replace '.*Latest run time: \[', ''
$last = $last -replace '\], Next run time: .*', ''
$last = $last.split(' ')[0]
#changed by DY on 11/04/2014 based on comment from cmot-weasel at http://exchange.nagios.org/directory/Plugins/Backup-and-Recovery/Others/check_veeam_backups/details
#if ($now -gt $last)
if((Get-Date $now) -gt (Get-Date $last))
{
Write-Host "CRITICAL! Last run of job: $name more than $period days ago."
exit 2
}
else
{
Write-Host "OK! Backup process of job $name completed successfully."
exit 0
}
Code: Select all
#Title:veeam_tape_backup.ps1
#Description:This is a Nagios plug-in that will check the last status and
#last run of a Veeam Backup & Replication tape job passed as
#an argument.
#Author:Laz Ravelo
#Date:2018-01-10
#Version:1.0
#Usage:veeam_tape_backup.ps1 $name $period
#Notes:Credit goes to Tytus Kurek for originally creating the script
#that would check the same info for non-tape jobs in Veeam.
#=================================================================================
#Add the Veeam SnapIn
asnp VeeamPSSnapin
#Global Variables
$name = $args[0]
$period = $args[1]
#Get Tape Backup Job info
$job = Get-VBRTapeJob -Name $name
$name = "'" + $name + "'"
#Check if job argument is missing
if ($job -eq $null)
{
Write-Host "No such tape job: $name"
exit 3
}
#Check if period argument is missing
if ($period -eq $null)
{
Write-Host "Missing the period argument!"
exit 3
}
#Assign last result of job to variable
$status = $job | select -ExpandProperty "LastResult"
#Nagios output depending on status of last tape backup session
if ($status -eq "Working")
{
Write-Host "OK - Tape backup job: $name is currently in progress."
exit 0
}
if ($status -eq "Failed")
{
Write-Host "CRITICAL! Errors were encountered during the backup process of the following tape backup job: $name."
exit 2
}
if ($status -ne "Success")
{
Write-Host "WARNING! Tape backup job $name didn't fully succeed."
exit 1
}
#Date comparison
$now = (Get-Date).AddDays(-$period)
$now = $now.ToString("yyyy-MM-dd")
$last = get-vbrsession -job $job -Last | select -ExpandProperty "CreationTime"
$last = $last.ToString("yyyy-MM-dd")
#Throw warning if last backup job ran more than x days ago (depends on value of $period)
if((Get-Date $now) -gt (Get-Date $last))
{
Write-Host "CRITICAL! Last run of job $name happened more than $period days ago."
exit 2
}
else
{
Write-Host "OK! Tape backup job $name has completed successfully."
exit 0
}