Link to home
Start Free TrialLog in
Avatar of Member_2_6474242
Member_2_6474242Flag for Fiji

asked on

Ms exchange 2010 high queue alert

Ms exchange 2010 high queue alert. What can i do on exchange 2010 so that i can get alerts when it reaches more then 10 messages in queue

What is the best practice?
Avatar of M A
M A
Flag of United States of America image

Hi Member_2_6474242,
Please find below script to send email when it reaches threshold of 10.

# Script:    Exch2010QueueMonitor.ps1 
# Purpose:  This script can be set as a scheduled task to run every 30minutes and will monitor all exchange 2010 queue's. If a threshold of 10 is met an  
#            output file with the queue details will be e-mailed to all intended admins listed in the e-mail settings 
# Author:    
# Email:    youremail@email.com
# Date:     May 2011 
# Comments: Lines 27, 31-35 should be populated with your own e-mail settings 
# Notes:     
#            - tested with Exchange 2010 SP1 
#            - The log report output file will be created under "c:\temp\qu.txt" 
 
$s = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://YourCASServerFQDN/PowerShell/ -Authentication Kerberos 
Import-PSSession $s 
 
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 
. $env:ExchangeInstallPath\bin\RemoteExchange.ps1 
Connect-ExchangeServer -auto 
 
$filename = “c:\temp\qu.txt” 
Start-Sleep -s 10 
if (Get-ExchangeServer | Where { $_.isHubTransportServer -eq $true } | get-queue | Where-Object { $_.MessageCount -gt 10 }) 
 
{ 
 
Get-ExchangeServer | Where { $_.isHubTransportServer -eq $true } | get-queue | Where-Object { $_.MessageCount -gt 10 } | Format-Table -Wrap -AutoSize | out-file -filepath c:\temp\qu.txt 
Start-Sleep -s 10 
 
$smtpServer = “xxx.xxx.xxx.xxx” 
$msg = new-object Net.Mail.MailMessage 
$att = new-object Net.Mail.Attachment($filename) 
$smtp = new-object Net.Mail.SmtpClient($smtpServer) 
$msg.From = “Monitor@contoso.com” 
$msg.To.Add("admin1@mycompany.com") 
#$msg.To.Add("admin2@mycompany.com") 
#$msg.To.Add("admin3@mycompany.com") 
#$msg.To.Add("admin4@mycompany.com") 
$msg.Subject = “CAS SERVER QUEUE THRESHOLD REACHED - PLEASE CHECK EXCHANGE QUEUES” 
$msg.Body = “Please see attached queue log file for queue information” 
$msg.Attachments.Add($att) 
$smtp.Send($msg) 
 
}

Open in new window

Avatar of Member_2_6474242

ASKER

Thanks MAS EE MVE

Can you please clarify. It is only connecting VERBOSE. Is that ok. This will only work when there is a queue right.

give a warning. the names of some imported commands from the module 'tmp_npo44qgd.154' include unapproved verbs that might make them less discover-able. to find the commands with unimproved verbs, run the import module command again with the verbose parameter. for a list of approved verbs, type Get-verb

i have attached error message

Please note i am a beginner in powershell
erroronqueuestats.txt
You can try to use the below script which you can also customize it yourself:

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://YourExchangeServer.domain.com/PowerShell/ -Authentication Kerberos
Import-PSSession $Session -AllowClobber
Import-Module ActiveDirectory -ErrorAction STOP

While ($true) {
	$Queue = Get-TransportServer |
		ForEach-Object {Get-Queue -Server $_} |
		Where-Object {($_.MessageCount -gt 0) -and ($_.Identity -notlike "*\Poison") -and ($_.Identity -notlike"*\Shadow\*")} |
		Select-Object Identity, Status, MessageCount, NextHopDomain
	$QueueLength = $Queue | Measure-Object MessageCount -Sum | Select-Object -ExpandProperty Sum
	"[$(Get-Date -Format 'yyyy-MM-dd hh:mm:ss')] Queues found: $($Queue.Count); messages: $($QueueLength)." | Write-Host -ForegroundColor White
	$Subject = ''
	If ($QueueLength -gt 200) {
		$Subject = "Attention Critical Exchange Queue Alert Total Message Queue $QueueLength"
		$Color = 'Red'
	} ElseIf ($QueueLength -gt 100) {
		$Subject = "Attention Warning Exchange Queue Alert Total Message Queue $QueueLength"
		$Color = 'Yellow'
	} ElseIf ($QueueLength -gt 10) {
		$Subject = "Attention Informational Exchange Queue Alert Total Message Queue $QueueLength"
		$Color = 'White'
	}
	If ([string]::IsNullOrEmpty($Subject)) {
		"[$(Get-Date -Format 'yyyy-MM-dd hh:mm:ss')] Exchange is pretty much idle ..." | Write-Host -ForegroundColor Green
	} Else {
		"[$(Get-Date -Format 'yyyy-MM-dd hh:mm:ss')] $($Subject)" | Write-Host -ForegroundColor $Color
		Send-MailMessage `
			-Subject $Subject `
			-Body $($Queue | ConvertTo-HTML | Out-String) `
			-From "Powershell@domain.com" `
			-To "Admin@domain.com" `
			-SmtpServer "smtp.domain.com" `
			-BodyAsHtml 
	}
	Start-Sleep -Seconds 120
}

Open in new window

I advise you to review your threshold requirement. 10 mails is too low for any mail server. I will set alert, if anything goes about 150-200. Rest, you have tons of script or tools to get the alert. However, remember, if your Exchange server itself having issues, you won't get the alert. Better to use 3rd party tool to monitor your server.
what are some of the tools that can be used for this purpose?
ASKER CERTIFIED SOLUTION
Avatar of Amit
Amit
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks