#Script to check HP Dataprotector backup routines through Nagios, using check_nrpe #Written by Vitor Paiva - 18/10/2016 # #This script was made for MSSQL and file backup routines, bt it may be extended for other backup types. # #The command should be included in the NSC.ini configuration from your NSCLient installation - check_nrpe must be allowed #NSC.ini configuration: #check_hpdataprotector=cmd /c echo scripts\check_hpdataprotector.ps1; exit $LastExitCode | powershell.exe -command - # #Nagios server: #check_nrpe -p -H -c check_hpdataprotector # ####################################################################################################################################### #Path of the HP Dataprotector Omniback bin files cd "C:\Program Files\OmniBack\bin" #Check routines started by "Backup", except those ended by "_OLD". Put those routines in a file omnicellinfo.exe -schinfo | where-object {$_ -like "BACKUP*"} | where-object {$_ -notlike "*_OLD"} > "C:\Program Files\OmniBack\bin\rotinasDeBackupAtivas.txt" #Create variables $status="" $retorno=0 #Put file created by omnicellinfo into a variable, and then run it line by line $content = Get-Content "C:\Program Files\OmniBack\bin\rotinasDeBackupAtivas.txt" foreach ($line in $content) { #Check if it is a MSSQL backup routine - it is necessary to create one loop for every type of backup if ($line -like 'BACKUP_MSSQL*') { #Create temporary file for the last session of the defined routine, then put it into a variable and run it line by line omnidb -session -datalist "MSSQL $line" -latest > "C:\Program Files\OmniBack\bin\rotina.txt" $session = get-content "C:\Program Files\OmniBack\bin\rotina.txt" foreach ($linha in $session) { #check if the session has failed if ($linha -like '*Failed*') { #Get the name of the failed session $sessionname = Get-Content "rotina.txt" | select -Last 1 $sessionname=$sessionname.substring(0,13) #Get detailed information of the failed session omnidb.exe -rpt $sessionname -detail > "C:\Program Files\OmniBack\bin\verificaFalhasRotina.txt" #Get the name of session and name of backup routine and put it on variable to be returned to Nagios $part1 = get-content "verificaFalhasRotina.txt" | select -index 1 $part2 = get-content "verificaFalhasRotina.txt" | select -index 2 $verifica=$part1 + $part2 $retorno=2 $status=$status + $verifica } } } #Check if it is a File backup routine - it is necessary to create one loop for every type of backup if ($line -notlike 'BACKUP_MSSQL*') { #Create temporary file for the last session of the defined routine, then put it into a variable and run it line by line omnidb -session -datalist "$line" -latest > "C:\Program Files\OmniBack\bin\rotina.txt" $session = get-content "C:\Program Files\OmniBack\bin\rotina.txt" foreach ($linha in $session) { #check if the session has failed if ($linha -like '*Failed*') { #Get the name of the failed session $sessionname = Get-Content "rotina.txt" | select -Last 1 $sessionname=$sessionname.substring(0,13) #Get detailed information of the failed session omnidb.exe -rpt $sessionname -detail > "C:\Program Files\OmniBack\bin\verificaFalhasRotina.txt" #Get the name of session and name of backup routine and put it on variable to be returned to Nagios $part1 = get-content "verificaFalhasRotina.txt" | select -index 1 $part2 = get-content "verificaFalhasRotina.txt" | select -index 2 $verifica=$part1 + $part2 $retorno=2 $status=$status + $verifica } } } } #If any backup has failed, enter this loop and exit with CRITICAL status '2' if ($retorno -eq 2) { Write-Host "CRITICAL - Failed: " $status exit $retorno } #If none backup has failed, enter this loop and exit with OK status '1' write-host "OK - All backups ran successfully" exit $retorno