# Check Status of SnapManager for Exchange Backups # # This script parses the current days Snap Manager for Exchange backup logs to check for failures # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # # Revision History # 2013-09-03 Barry Mulholland [basra.mulholland@gmail.com] 1.0 # * Initial script created # # To execute from within NSClient++ # #[NRPE Handlers] # Check_SnapMirror_Exchange_Backup=cmd /c echo Scripts\Check_SnapMirror_Exchange_Backup.ps1; exit($lastexitcode) | PowerShell.exe -Command - # # On the check_nrpe command include the -t 20, since it takes some time to load the cmdlet's. $NagiosStatus = "0" $NagiosDescription = "" $TodYest = "today" #Create todays date in a format to match current logfile $DateStr = Get-Date -Format "MM\-dd\-yyyy" #Create yesterdays date in a format to match yesterdays logfile $YestDateStr = ((Get-Date).AddDays(-1)).ToString("MM\-dd\-yyyy") #Change below to match your SnapManager installation directory $LogPath = 'C:\Program Files\NetApp\SnapManager for Exchange\Report\Backup*\' cd $LogPath $FileFilter = $DateStr + '*.txt' $FileName = Get-ChildItem -Filter $FileFilter #Check to make sure a log file exists for today, and if it doesn't display yesterdays results. #Handy if the backup has not yet run for the day If ($FileName -eq $null) { $FileFilter = $YestDateStr + '*.txt' $FileName = Get-ChildItem -Filter $FileFilter $TodYest = "yesterday" # If yesterdays log file doesn't exist either, return CRITICAL status and exit If ($FileName -eq $null) { $NagiosDescription = "CRITICAL: No log file for today or yesterday exists!" $NagiosStatus = "2" Write-Host $NagiosDescription exit $NagiosStatus } } #Read log file and parse for results $BackupResults = Get-Content -Path $FileName | Select-String -pattern "Backup SG" -AllMatches -SimpleMatch ForEach ($Line in $BackupResults) { if ($Line -like "*Error*") { #Look for backup problems #Format output for Nagios if ($NagiosDescription -ne "") { $NagiosDescription = $NagiosDescription + ", " } $NagiosDescription = $NagiosDescription + $Line #Set the status to failed $NagiosStatus = "2" } elseif ($Line -like "*OK*") { #Look for passed backups #Format output for Nagios if ($NagiosDescription -ne "") { $NagiosDescription = $NagiosDescription + ", " } $NagiosDescription = $NagiosDescription + $Line if ($NagiosStatus -ne "2") { #Don't lower the status level if we already have a failed backup $NagiosStatus = "0" } } } # Output to return to Nagios if ($NagiosStatus -eq "2") { $Response = "CRITICAL: Problem with backup from " + $TodYest + " : " + $NagiosDescription Write-Host $Response } elseif ($NagiosStatus -eq "0") { $Response = "OK: All backups for " + $TodYest + " showing as passed!" Write-Host $Response } exit $NagiosStatus