# # ///// check_nbu_backstat.ps1 v1.1 2011-06-01 ///// # # Ver. 1.0 - New creation # Ver. 1.1 - Add the NetBackup return code in Nagios message # # Check Symantec NetBackup - Backup Job Status # # Author: Ryosuke Matsui # Mailto: ryosuke.matsui@x-edges.com # # This PowerShell script works with NSClient++ on MS-Windows environment. # #--------------------------------------------------------------------------- # << Distribution Files >> # 1. check_nbu_backstat.ps1 <-- this script # 2. nbuerror.csv <-- CSV file described the NBU status codes # #--------------------------------------------------------------------------- # << How To Install >> # [check_nbu_backstat.ps1 Settings] # 1. Copy "check_nbu_backstat.ps1" and "nbuerror.csv" # into the scripts folder of NSClient++ # (C:\Program Files\NSClient++\scripts). # 2. Modify / Check the values of $nbuBin and $statFile # if you need. # 3. Modify / Add the "RETURN CODE TABLE SETTING" # in the "searchRtnStat" function if you need. # # [NSClient++ Settings] # 4. Add the following setting in the [Wrapped Scripts] # section in the "NSC.ini". # 5. Enable the following settings in the "NSC.ini". # - port=5666 # - command_timeout=60 # - allow_arguments=1 # - allow_nasty_meta_chars=1 # - script_dir=scripts\ # - socket_timeout=30 # - allowed_hosts=xxx.xxx.xxx.xxx/xx # 6. Restart the "NSClient++" service. # # [Nagios Settings] # 7. Add the following setting to Nagios "commands". # $USER1$/check_nrpe -H $HOSTADDRESS$ -c check_nbu_backup -a $ARG1$ # 8. Add new Nagios "service" to check status of the backup job. # * The backup client name that you want to check the latest backup # status have to be set to $ARG1$ in the "service" setting. # #--------------------------------------------------------------------------- # param( [string]$nbuClient ) # RETURN STATUS VALUES FOR Nagios $stateOk = 0 $stateWarning = 1 $stateCritical = 2 $stateUnknown = 3 # FUNCTION BLOCK function searchRtnStat([int] $x) { $rtnStatTab = @{} # RETURN CODE TABLE SETTING # - Key --> NetBackup return code # - Value --> Nagios retrun code (0,1,2,3) # * "Values" should be # $stateOK, $stateWarning and $stateUnknow only. # * Default key-value is set to $stateCritical. $rtnStatTab[0] = $stateOk $rtnStatTab[1] = $stateWarning return ($rtnStatTab[$x]) } # ARGUMENT VALIDATION CHECK if ($nbuClient -eq "") { $scriptName = $MyInvocation.MyCommand.Name $msg = "Usage: $scriptName -nbuClient [NetBackup Client]" echo $msg exit $stateCritical } # NetBackup ADMIN COMMAND PATH (Modify if you need) $nbuBin = "D:\Veritas\NetBackup\bin\admincmd" # NetBackup ERROR STATUS DEFINITION FILE (Modify if you need) $statFile = "C:\'Program Files'\NSClient++\scripts\nbuerror.csv" $cmd1 = "$nbuBin\" + "bperror -t BACKSTAT -hoursago 24 -client $nbuClient" $cmd2 = "Import-Csv -path $statFile" $cmdOutput = Invoke-Expression $cmd1 | Select-Object -Last 1 $msg = "" $exitCode = 0 if ($cmdOutput -eq $null) { echo $msg exit $stateCritical } $outArray = $cmdOutput.Split(" ") $jobID = $outArray[6] $rtn = $outArray[21] # NetBackup ERROR STATUS TABLE BUILD $errtab = @{} foreach ($item in Invoke-Expression $cmd2) { $errtab[$item.Status] = $item.Description } # Nagios NOTIFICATION MESSAGE $msg = "[$jobID] (RC=$rtn) " + $errtab[$rtn] # Nagios RETURN STATUS $nagiosStatCode = searchRtnStat($rtn) if ($nagiosStatCode -ne $null) { $exitCode = $nagiosStatCode } else { $exitCode = $stateCritical } echo $msg exit $exitCode