Monitoring Exchange 2010 DAG Status with Nagios



This one is nice and simple and allows you to monitor the health of your Exchange 2010 DAG via Nagios. For this, you will need:

Configure Nagios
Make sure you’ve got the Check_NRPE plugin in your libexec folder then add a new command definition to the commands.cfg like so:

define command{
	command_name    check_exrep
	command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -u -t 120 -p 5666 -c check_exch
	}

Then setup service definitions and hosts/hostgroups as you would normally.

Configure NSClient++
In your [NSClient++ Folder]\Scripts folder, create a new powershell script file (.ps1) called “exrep.ps1” and put the following code inside (Replacing the two sections in [] to match your environment):

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
 
$Status = Get-MailboxDatabaseCopyStatus -server [Servername]
 
$flag = 0
 
foreach($State in $Status){
 
	if(($state.status -eq "Mounted") -or ($state.status -eq "Healthy")){
		$content = $($state.name)+": "+$($state.status)
		$output += $content+" - "
	}else{
		$content = $($state.name)+": "+$($state.status)
		$output += $content+" - "
		$flag = 1
	}
 
}
 
$output = $output.trimend(" - ")
$output = $output.replace("\[Servername]","")
 
write-host $output
 
if($flag -eq 0){
	exit 0
}else{
	exit 2
}

Next, open up your NSC.ini file and uncomment the “CheckExternalScripts.dll” line. In the [External Scripts] section, create a new entry for “check_exch” like this:

check_exch=cmd /c echo scripts\exrep.ps1 | powershell.exe -noprofile -nologo -command -

Note the trailing “-” which tells Powershell to read the -command value from stdin.

Finally, restart the NSClient++ service on the client machine and restart Nagios on the server. When your check next runs, if any of your storage groups are not in a Healthy or Mounted state your should get an output that looks like: [Database Name]: [Status]. Repeat the above for each server that is part of the DAG.

7 Replies to “Monitoring Exchange 2010 DAG Status with Nagios”

  1. Hello,

    Thanks for thoses infos, very usefull.
    I have a question about Nagios website status information for those alerts with powershell script.

    I have test with this parameter and i have :
    -‘ was specified with the -Command parameter: no other arguments to -Command are permitted.

    I have test with your commandline and i have :
    Missing expression after unary operator ‘-‘

    What’s the status information you get in nagios console for this alert ?

    1. It looks like there’s some problem with the syntax you’re using. You should have something like this in the nsclient.in file:

      check_exrep=cmd /c echo scripts\exrep.ps1 | powershell.exe -noprofile -nologo -command –

      Did you add any other switches after the “-command -” at the end of the string? Because that won’t work. Equally, if you don’t have the “echo scripts\exrep.ps1 |” then powershell won’t know what command to execute as it’s expecting it from stdin.

      It’s hard to suggest anything further without knowing the details of how you’re running things.

  2. Hi,
    Thanks for your answer.
    I had an issue with the version of NRPE, it was 32bits and that’s why it doesn’t work.
    Now it’s fine 🙂

    Thanks

  3. If we used to have more than one mail database, don’t you think we should check if one of the database is failed instead of check if one database is mounted or healthy ?

    I supposed if only one of the database is OK, the check will return : Passed instead of CRITICAL.

    1. The way the script logic is written if any of the checked databases are not either “Mounted” or “Healthy” then it will flag in Nagios as Critical. Only if every database is either Mounted or Healthy will it show as OK.

      The reason I wrote it that way was so that if future updates to Exchange introduced new failure states, the script would still flag them as Critical rather than needing to be modified to check for them.

      You could, of course, add Warning states if you wanted to.

  4. For me it is showing OK even when one of the databases is dismounted. I have changed -match to -eq and it works fine now.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.