# Test Content Index State Health # # This script will execute the "Get-MailboxDatabaseCopyStatus" command # and look for an failed Content Index State # # Example: # Name : MAILBOX1\EXCHANGESERVER1 # ContentIndexState : Failed # # Name : MAILBOX2\EXCHANGESERVER1 # ContentIndexState : Healthy # # # 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. # # # Revision History # 2012-06-28 Bastian W. [Bastian@gmx-ist-cool.de] 1.0 code initial created # 2016-07-18 Bastian W. [Bastian@gmx-ist-cool.de] 2.0 # - Script will now try to resume a DB copy if you wish # # # To execute from within NSClient++ # #[NRPE Handlers] #check_exchange_dag_indexstate_health=cmd /c echo C:\Scripts\NagiosMonitoring_Exchange2010ContentIndexStateHealth.ps1 | PowerShell.exe -Command - # # On the check_nrpe command include the -t 20, since it takes some time to load # the Exchange cmdlet's. # CONFIGURATION # -------------- # change so that it fits your needs! $AutoResumeDBCopy = 0 # if enabled the script will try to auto resume the DB if a failed state was detected. # ------------------------ do not change anything behind that line !!! ----------------------------- # =================================================================================================== $sDebugScript = 1 #if (get-pssnapin $snapin -registered -ea "silentlycontinue") if ( (Get-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction:SilentlyContinue) -eq $null) { Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 } $NagiosStatus = "0" $NagiosDescription = "" ForEach ($Type in Get-MailboxDatabaseCopyStatus -Server $env:computername) { # Look for failed Index state if ($Type.ContentIndexState -notlike "*Healthy*") { # Format the output for Nagios if ($NagiosDescription -ne "") { $NagiosDescription = $NagiosDescription + ", " } $NagiosDescription = $NagiosDescription + $Type.Name + " = " + $Type.ContentIndexState # Set the status to failed. $NagiosStatus = "2" if ($Type.Status -eq "FailedAndSuspended") { if ($sDebugScript -eq 1){Write-Host " Debug:: DB"$Type.Name"is suspended" -foregroundcolor magenta} if ($AutoResumeDBCopy -eq 1) { if ($sDebugScript -eq 1){Write-Host " Debug:: Will auto resume DB"$Type.Name -foregroundcolor magenta} resume-mailboxdatabasecopy $Type.Name } } } } # Output, what level should we tell our caller? if ($NagiosStatus -eq "2") { Write-Host "CRITICAL:"$NagiosDescription } else { Write-Host "OK: All content index states are healthy!" } exit $NagiosStatus