在企業實際監控需求中,我們需要監控SQL數據庫特定的表值,如果該表值超出了預期的鍵值,將觸發SCOM報警機制立即以郵件或短信的方式通知SQL數據庫管理員。我們知道,該需求在SCOM監控系統中,無法通過SCOM本身自帶的功能實現,而SCOM默認也沒有MP包可以實現對SQL某個數據庫的字段表進行監控。那我們該如何實現該監控需求呢?
Dim objConn
Dim objRS
Dim strSQL
'' Create the required SCOM objects
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()
'' Set SQL Connection Parameters
Set objConn = CreateObject("ADODB.Connection")
strDbConnection = "Provider=SQLOLEDB;Data Source=192.168.0.55;Database=dntest;User ID=sa;Password=1qaz@WSX;"
objConn.Open(strDbConnection)
'' String to be executed, contained in SP
strSQL = "SELECT logmsg FROM FOR_IDS where logmsg='error'"
'' Create recordset and execute SP
Set objRS = CreateObject("ADODB.Recordset")
Set objRS = objConn.Execute(strSQL)
'' Determine health
If(objRS.EOF) Then
Call oBag.AddValue("State","GOOD")
Call oAPI.Return(oBag)
Else
Call oBag.AddValue("State","ERROR")
Call oAPI.Return(oBag)
End If
objRS.Close()
Set objRS = Nothing
objConn.Close()
Set objConn = Nothing