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()

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")
Call oBag.AddValue("Status","OK")
End If

Call oAPI.Return(oBag)


Post a comment

Popular posts from this blog

Assembly Microsoft.Dynamics.Service.Plugins.dll can not be loaded. Dynamics CRM 365 Engine version 9 - CRM User creation error

Exception caught instantiating TERADATA report server extension SQL Reporting Services

Could not load file or assembly 'System.ServiceModel, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified at Configuration class initiation in