# Test DAG Replication Health # # This script will execute the Test-ReplicationHealth command and look for warnings for failed replications inside a Exchange 2010 DAG via powershell and nsclient++ # # 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 # 2011-01-02 Bastian W. [Bastian@gmx-ist-cool.de] 1.0 # 2011-09-19 Bastian W. [Bastian@gmx-ist-cool.de] 1.1 code adjusted: # * checked if PSSnapin is loaded # 2012-07-03 Bastian W. [Bastian@gmx-ist-cool.de] 1.2 code adjusted: # * fixed a small spelling issue # # To execute from within NSClient++ # #[NRPE Handlers] #check_exchange_dag_replication_health=cmd /c echo C:\Scripts\Nagios\NagiosMonitoring_ExchangeDAGReplicationHealth.ps1 | PowerShell.exe -Command - # # On the check_nrpe command include the -t 20, since it takes some time to load the Exchange cmdlet's. 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 Test-ReplicationHealth -Identity $env:computername) { if ($Type.Result -like "*FAILED*") { # Look for failed replications # Format the output for Nagios if ($NagiosDescription -ne "") { $NagiosDescription = $NagiosDescription + ", " } #$NagiosDescription = $NagiosDescription + $Type.Check +" "+ $Type.Result +" "+ $Type.Error $NagiosDescription = $NagiosDescription + $Type.Check +" "+ $Type.Result # Set the status to failed $NagiosStatus = "2" } elseif ($Type.Check -like "*Warn*") { # Look for warnings in replication if ($NagiosDescription -ne "") { # Format the output for Nagios $NagiosDescription = $NagiosDescription + ", " } #$NagiosDescription = $NagiosDescription + $Type.Check +" "+ $Type.Result +" "+ $Type.Error $NagiosDescription = $NagiosDescription + $Type.Check +" "+ $Type.Result if ($NagiosStatus -ne "2") { # Don't lower the status level if we already have a failed attempt $NagiosStatus = "1" } } } # Output, when should we push out a notification to nagios? if ($NagiosStatus -eq "2") { Write-Host "CRITICAL:" $NagiosDescription } elseif ($NagiosStatus -eq "1") { Write-Host "WARNING:" $NagiosDescription } else { Write-Host "OK: All replication tests passed." } exit $NagiosStatus