how to execute query from VBScript in script two state monitor SCOM

here is code :

'define and create objects for passing values in 2 state to SCOM
Dim oAPI, oBag
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()


StrConnect = "PROVIDER=SQLOLEDB.1;Integrated Security=SSPI;INITIAL CATALOG=DBName;DATA SOURCE=ServerName"
Set cnt = CreateObject("ADODB.Connection")
cnt.Open StrConnect

set recordSet = CreateObject("ADODB.Recordset")
SQLStr = " select * from .... "

recordSet.Open SQLStr, cnt,1,1

TotalRecords = recordSet.RecordCount

recordSet.Close : set recordSet = nothing
cnt.Close : set cnt = nothing

'We have to handle Status value from SCOM and create rule for each state
If TotalRecords >= 0 Then
Call oBag.AddValue("Status","ERROR")
Else
Call oBag.AddValue("Status","OK")
End If

Call oAPI.Return(oBag)

Comments

Post a Comment

Popular posts from this blog

Complex Query in QueryExpression in Microsoft CRM 2011

Exception caught instantiating TERADATA report server extension SQL Reporting Services

Microsoft Power Apps Portal integration with Dynamics 365 CE On-Premise - Step By Step Guide