Nagios – check_veeam



This script will leverage the Veeam Powershell modules in conjunction with Nagios’ check_nrpe plugin (or similar passive checking plugin) to check the status of Veeam backup jobs. You will probably need to have run the Install-VeeamToolkit.ps1 script in “C:\Program Files\Veeam\Backup and Replication” on any server you’re running these checks on otherwise it will be unable to load the Veeam snapin, unless you have Powershell 3 installed and have your fingers crossed.

You will also need to ensure that your agent allows NRPE arguments and don’t strip special characters (it needs to keep the “” quotes around the job name).

If your Veeam SQL database is off-box then your agent service will need to be running under an account that has access to the DB on the remote SQL server otherwise the lookups will fail.

Check command syntax for NSClient++ is something like the below, other agents may differ:
check_veeam = cmd /c echo scripts\check_veeam.ps1 "$ARG1$"; exit($lastexitcode) | powershell.exe -noninteractive -noprofile -command -

Check command syntax for the Nagios commands.cfg is something like the below:
$USER1$/check_nrpe -H $HOSTADDRESS$ -c check_veeam -a $ARG1$

<#
Copyright (c) 2013, Adam Beardwood
All rights reserved.
 
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: 
 
1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer. 
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution. 
 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#>
 
#Check Veeam Backups
#Adam Beardwood 10/07/2013
#Based on a script by by Tytus Kurek
#v1.0 - Initial Release
 
$error.clear()
 
$snaps = Get-PSSnapin
foreach($snap in $snaps){if($snap.name -eq "VeeamPSSnapin"){$exflag = 1}}
if($exflag -ne 1){
	Add-PSSnapin -name VeeamPSSnapin -erroraction silentlycontinue
	if($error[0] -ne $null){write-host "CRITICAL - Could not load Veeam snapin";exit 2}
}
 
$name = $args[0]
 
if($args[0] -eq $null){write-host "CRITICAL - You must provide a job name.";exit 2}
 
$job = Get-VBRJob -Name $name
$name = $job.name
 
if ($job -eq $null){
	Write-Host "UNKNOWN - Could Not Find Job: $name."
	exit 3
}
 
$status = $job.GetLastResult()
$time = $($job.findlastsession()).EndTime
if($($job.findlastsession()).State -eq "Working"){
	Write-Host "OK - Job: $name is currently in progress."
	exit 0
}elseif($status -eq "Failed"){
	Write-Host "CRITICAL - Job: $name failed at $time."
	exit 2
}elseif ($status -ne "Success"){
	Write-Host "WARNING - Job: $name completed with warnings at $time."
	exit 1
}else{
	Write-Host "OK - Job: $name completed successfully at $time."
	exit 0
}
#End

Hope you find it helpful.

5 Replies to “Nagios – check_veeam”

  1. Any chance you post the entire nsclient.ini?

    I’ve been trying for a few hours to pass arguments using NRPE to a Powershell script but I keep getting “Arguments not allowed” even though “allow arguments” is set to true.

  2. Great script, simple tutorial. I tried other sources and scripts for 3 days. This finally worked! Good woork and Thumbs up.

  3. Hi! I am trying to configure this on opsview and nsclient (win2012 r2 powershell 4) and I am having problems. Script cant get job name. Here is my logfile:

    016-01-19 12:29:19: debug:NSClient++.cpp:1143: Injecting: check_veeam: $
    2016-01-19 12:29:20: debug:NSClient++.cpp:1179: Injected Result: WARNING ‘UNKNOWN – Could Not Find Job: .’
    2016-01-19 12:29:20: debug:NSClient++.cpp:1180: Injected Performance Result: ”

    I added this line to my opsview.ini:
    check_veeam = cmd /c echo scripts\check_veeam.ps1 “$ARG1$”; exit($lastexitcode) | powershell.exe -noninteractive -noprofile -command –

    allow_arguments=1
    allow_nasty_meta_chars=1

    Also if I run PS script localy it returns: “Provide job name” or “Could not find job: .”

    Did anyone have same problem? Thanks!

  4. I have the same problem, but I have one job. So I put job name in powershell script:

    $name = "JobName"

    It works fine !

Leave a Reply

Your e-mail address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.