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