Mssql/wmi/powershell (v) SQL Server Mirror state change real-time alarm

Source: Internet
Author: User
Tags failover mssql

This article describes the SQL Server mirror status change real-time alarm, using WMI monitor to monitoring the image status in real time, capturing relevant information when the state changes, and sending information through PowerShell to achieve the purpose of real-time alarm.


1. Create WMI Monitoring

Database_mirroring_state_change for the Mirror State change information table, through the WQL statement can obtain the relevant mirror state change details, refer to the Mssql/wmi/powershell (ii) Create WMI monitoring


Core Code Snippet

EventFilter

${query}= "SELECT * from Database_mirroring_state_change";


Consumer

${text} = "Database Mirroring alarm ' nservername:=%computername% ' ninstance:=%sqlinstance% ' ndatabase:=%databasename% ' nState:="

$Text 2= "%state%"


2. PowerShell Remote Call

When the mirroring state changes, consumer triggers the PowerShell script action to invoke the send script of the external network server in the triggered script, referring to the Mssql/wmi/powershell (iii) Execute PowerShell remote script



3. PowerShell sends information

Send information in real time, refer to "Mssql/wmi/powershell (iv) PowerShell send Information"


Core Code Snippet

Mirroring status

$Mirror _state=$ (Switch ($Text 2)

{0 {"mirroring-session-is-started ' n"}

1 {"Synchronized-principal-with-witness ' n"}

2 {"Synchronized-principal-without-witness ' n"}

3 {"Synchronized-mirror-with-witness ' n"}

4 {"Synchronized-mirror-without-witness ' n"}

5 {"Connection-with-principal-lost ' n"}

6 {"Connection-with-mirror-lost ' n"}

7 {"Manual-failover ' n"}

8 {"Automatic-failover ' n"}

9 {"Mirroring-suspended ' n"}

{"No-quorum ' n"}

{"Synchronizing-mirror ' n"}

{"Principal-running-exposed ' n"}

{"Synchronizing-principal ' n"}});



Warning Example:

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M00/07/F6/wKiom1nXNonDkTnsAABwnyARYp0943.png-wh_500x0-wm_ 3-wmp_4-s_3934524960.png "title=" SQL Server Mirroring state Change Alarm "width=" "height=" 816 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:500px;height:816px; "alt=" Wkiom1nxnondktnsaabwnyaryp0943.png-wh_50 "/>


This article is from the "Aimax" blog, make sure to keep this source http://aimax.blog.51cto.com/11610508/1970526

Mssql/wmi/powershell (v) SQL Server Mirror state change real-time alarm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.