Advertisement
Guest User

Exchange DAG Monitoring

a guest
May 26th, 2015
771
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. ##############
  2. #defined variables
  3. $sendemailalertto="exchangeteam@companyx.com"
  4. $YourSMTPServer="exchange.fqdn.com"
  5.  
  6. ##############
  7. #Define email for DAG notifciation
  8. function send_DAG_email {
  9. $EmailFrom = "exchange_server@companyx.com"
  10. $EmailTo = $sendemailalertto
  11. $EmailSubject = "Exchange Replication Is Unhealthy"
  12. $SMTPServer = $YourSMTPServer
  13. $emailbody = "Please see attached"
  14. $emailattachment = "c:\DatabaseCopyStatus.csv"
  15. $mailmessage = New-Object system.net.mail.mailmessage
  16. $mailmessage.from = ($emailfrom)
  17. $mailmessage.To.add($emailto)
  18. $mailmessage.Subject = $emailsubject
  19. $mailmessage.Body = $emailbody
  20. $attachment = New-Object System.Net.Mail.Attachment($emailattachment, 'text/plain')
  21. $mailmessage.Attachments.Add($attachment)
  22. $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)
  23. $SMTPClient.Send($mailmessage)
  24. }
  25. ##############
  26. #Define email for INDEX notification
  27. function send_INDEX_email {
  28. $EmailFrom = "exchange_server@companyx.com"
  29. $EmailTo = $sendemailalertto
  30. $EmailSubject = "Exchange Replication Failed"
  31. $SMTPServer = $YourSMTPServer
  32. $emailbody = "Please take action. Database Content Index is not healthy `n
  33. Run below cmdlet to repair the index database.`n
  34. Update-MailboxDatabaseCopy $mailboxdatabase -CatalogOnly`n
  35. `n
  36. For more information, see:`n
  37.  
  38. http://technet.microsoft.com/en-us/library/dd335201.aspx
  39.  
  40. "
  41. $emailattachment = "c:\Bad_ContentIndexState_DBs.csv"
  42. $mailmessage = New-Object system.net.mail.mailmessage
  43. $mailmessage.from = ($emailfrom)
  44. $mailmessage.To.add($emailto)
  45. $mailmessage.Subject = $emailsubject
  46. $mailmessage.Body = $emailbody
  47. $attachment = New-Object System.Net.Mail.Attachment($emailattachment, 'text/plain')
  48. $mailmessage.Attachments.Add($attachment)
  49. $mailmessage.IsBodyHTML = $true
  50. $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)
  51. $SMTPClient.Send($mailmessage)
  52. }
  53. ##############
  54. # Import Exchange related powershell modules
  55. # Connect to Exchange RBAC session
  56. ##############
  57.  
  58. $s = New-PSSession -ConfigurationName Microsoft.Exchange.Management.PowerShell.2010 -ConnectionUri http://exchange.fqdn.com/powershell
  59. Import-PSSession -Session $s
  60. sleep -seconds 10
  61.  
  62. ##############
  63. # get-mailboxdatabase and copystatus:
  64. # these appear to return objects.
  65. # each object has multiple fields we are interested in
  66. # specifically we are comparing "Status'
  67. ##############
  68.  
  69. $alert1=0
  70. $alert2=0
  71.  
  72. # Array to store db entries that are not healthy or mounted
  73. $error1=@()
  74. $error2=@()
  75.  
  76. # get the db of mailbox info
  77. Get-mailboxdatabase | Get-MailboxDatabaseCopyStatus | foreach {
  78.  
  79. # Cycle through db entries, one line at a time
  80.  
  81. # If status is _not_ healthy
  82. if ($_.Status -ne "Healthy") {
  83.  
  84. # If status is _not_ mounted
  85. if ($_.Status -ne "Mounted") {
  86.  
  87. # If status is _not_ disconnectedandhealthy
  88. if ($_.Status -ne "DisconnectedAndHealthy") {
  89.  
  90. # We have an alert condition
  91. $alert1=1
  92.  
  93. # Store alerting device details
  94. $error1+=[Array] $_
  95. }
  96. }
  97. }
  98.  
  99.  
  100. # If index is not healthy
  101. if ($_.contentindexstate -ne "Healthy"){
  102. # set 2nd alert flag to 1
  103. $alert2=1
  104. # add the current entry to your error2 array
  105. $error2+[Array] $_
  106. }
  107. }
  108.  
  109. # if status alert on DAG health, write results to csv, then send the alert email.
  110. if ($alert1 -ne 0) {
  111. $error1 | select Name,DatabaseName,Status,MailboxServer,ActiveDatabaseCopy,ActivationSuspended | export-csv -Path c:\DatabaseCopyStatus.csv -NoTypeInformation
  112. send_DAG_email
  113. Write-Host "DatabaseFailure"
  114. }
  115.  
  116. # if status alert on INDEX health, write results to csv, then send the alert email.
  117. if ($alert2 -ne 0) {
  118. $error2 | select Name,DatabaseName,Status,MailboxServer,ActiveDatabaseCopy,ActivationSuspended | export-csv -Path c:\Bad_ContentIndexState_DBs.csv -NoTypeInformation
  119. send_INDEX_email
  120. Write-Host "IndexFailure"
  121. }
  122.  
  123. # for testing purposes, created a condition to test monitoring integration.
  124. # else {
  125. # Write-Host "TESTFailure"
  126. # }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement