beardmann

Nagios SnapManager Check

Apr 22nd, 2015
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Check Status of SnapManager for Exchange Backups
  2. #
  3. # This script parses the current days Snap Manager for Exchange backup logs to check for failures
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. #
  19. #
  20. # Revision History
  21. # 2013-09-03    Barry Mulholland [[email protected]]   1.0
  22. #                                                           * Initial script created
  23. #
  24. # To execute from within NSClient++
  25. #
  26. #[NRPE Handlers]
  27. # Check_SnapMirror_Exchange_Backup=cmd /c echo Scripts\Check_SnapMirror_Exchange_Backup.ps1; exit($lastexitcode) | PowerShell.exe -Command -
  28. #
  29. # On the check_nrpe command include the -t 20, since it takes some time to load the cmdlet's.
  30.  
  31.  
  32. $NagiosStatus = "0"
  33. $NagiosDescription = ""
  34. $TodYest = "today"
  35.  
  36.  
  37. #Create todays date in a format to match current logfile
  38. $DateStr = Get-Date -Format "MM\-dd\-yyyy"
  39.  
  40. #Create yesterdays date in a format to match yesterdays logfile
  41. $YestDateStr = ((Get-Date).AddDays(-1)).ToString("MM\-dd\-yyyy")
  42.  
  43.  
  44. #Change below to match your SnapManager installation directory
  45. $LogPath = 'C:\Program Files\NetApp\SnapManager for Exchange\Report\Backup*\'
  46. cd $LogPath
  47. $FileFilter = $DateStr + '*.txt'
  48. $FileName = Get-ChildItem -Filter $FileFilter
  49.  
  50. #Check to make sure a log file exists for today, and if it doesn't display yesterdays results.
  51. #Handy if the backup has not yet run for the day
  52. If ($FileName -eq $null)
  53. {
  54.     $FileFilter = $YestDateStr + '*.txt'
  55.     $FileName = Get-ChildItem -Filter $FileFilter
  56.     $TodYest = "yesterday"
  57.    
  58.     # If yesterdays log file doesn't exist either, return CRITICAL status and exit
  59.     If ($FileName -eq $null)
  60.     {
  61.         $NagiosDescription = "CRITICAL: No log file for today or yesterday exists!"
  62.         $NagiosStatus = "2"
  63.         Write-Host $NagiosDescription
  64.         exit $NagiosStatus
  65.     }
  66. }
  67.  
  68.  
  69. #Read log file and parse for results
  70. $BackupResults = Get-Content -Path $FileName | Select-String -pattern "Backup SG" -AllMatches -SimpleMatch
  71. ForEach ($Line in $BackupResults)
  72. {
  73.     if ($Line -like "*Error*")
  74.     {
  75.     #Look for backup problems
  76.        
  77.         #Format output for Nagios
  78.         if ($NagiosDescription -ne "")
  79.         {
  80.             $NagiosDescription = $NagiosDescription + ", "
  81.         }
  82.        
  83.         $NagiosDescription = $NagiosDescription + $Line
  84.        
  85.         #Set the status to failed
  86.         $NagiosStatus = "2"
  87.     }
  88.     elseif ($Line -like "*OK*")
  89.     {
  90.     #Look for passed backups
  91.    
  92.         #Format output for Nagios
  93.         if ($NagiosDescription -ne "")
  94.         {
  95.             $NagiosDescription = $NagiosDescription + ", "
  96.         }
  97.        
  98.         $NagiosDescription = $NagiosDescription + $Line
  99.        
  100.         if ($NagiosStatus -ne "2")
  101.         {
  102.             #Don't lower the status level if we already have a failed backup
  103.             $NagiosStatus = "0"
  104.         }
  105.     }
  106. }
  107.  
  108. # Output to return to Nagios
  109. if ($NagiosStatus -eq "2")
  110. {
  111.     $Response = "CRITICAL: Problem with backup from " + $TodYest + " : " + $NagiosDescription
  112.     Write-Host $Response
  113. }
  114. elseif ($NagiosStatus -eq "0")
  115. {
  116.     $Response = "OK: All backups for " + $TodYest + " showing as passed!"
  117.     Write-Host $Response
  118. }
  119.  
  120. exit $NagiosStatus
Advertisement
Add Comment
Please, Sign In to add comment