Rexxer

Some tips for me and other

Exchange 2010 + queue monitoring

Sometimes the network or other issues happen and cause queues growing.

So I need to monitor this incident.

This powershell script helps me:

$FromAddress = “postmaster@domain.com”
$ToAddress = “postmaster@domain.com”
$MessageSubject = “Queues Report”
$MessageBody = “Attached is the current queues.”
$SendingServer = “mail-server”

$queue = Get-Queue -Filter {MessageCount -gt 5} | fl
if ($queue)
{
write-output $queue

$MessageBody = echo $queue | Out-String
$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress,$ToAddress,$MessageSubject,$MessageBody

$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
$SMTPClient.Send($SMTPMessage)
c:\plink -ssh -batch -l user -pw password user@192.168.0.200 sendsms 380501000000 ‘Exchange-queue-problem’
}

It’s scheduled to start and repeat every 5 minutes.

If queue length is over 5 letters it sends message to e-mail and sms-gate(see my previous article) with command via  plink.

P.S.: command string to add this to scheduler:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command “. ‘C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1’; Connect-ExchangeServer -auto; c:\Scripts\QueueCheck.ps1

P.P.S.: new version of the script with ShadowRedundancy filtering:

$FromAddress = “reporter@domain.com”
$ToAddress = “admin@domain.com”
$MessageSubject = “Queues Report”
$MessageSubject2 = “Shadow Queues Report”

$MessageSubject3 = “Retry Queues Report”
$MessageBody = “Attached is the current queues.”
$SendingServer = “SERVER”

# Checking only current flow
$queue = Get-Queue -Filter {messagecount -gt 20 -and DeliveryType -ne “ShadowRedundancy”} | fl
if ($queue)
{
write-output $queue

$MessageBody = echo $queue | Out-String
$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress,$ToAddress,$MessageSubject,$MessageBody

$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
$SMTPClient.Send($SMTPMessage)
c:\backup\plink -ssh -batch -l user -pw pass user@192.168.0.200 sendsms 38050000000 ‘Exchange-queue-problem’
}

# Checking ShadowRedundancy only
$queue = Get-Queue -Filter {messagecount -gt 50 -and DeliveryType -eq “ShadowRedundancy”} | fl
if ($queue)
{
write-output $queue

$MessageBody = echo $queue | Out-String
$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress,$ToAddress,$MessageSubject2,$MessageBody

$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
$SMTPClient.Send($SMTPMessage)
c:\backup\plink -ssh -batch -l user -pw pass user@192.168.0.200 sendsms 38050000000 ‘Exchange-Shadowqueue-problem’
}

# Checking Retries
$queue = get-transportserver | get-queue -Filter { Status -eq “Retry” }
if ($queue)
{
write-output $queue

$MessageBody = echo $queue | Out-String
$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress,$ToAddress,$MessageSubject3,$MessageBody

$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
$SMTPClient.Send($SMTPMessage)
}

Leave a Reply