Lenovo Windows WmiEventProvider EventProvider3

IBM.Windows.WmiEventProvider.EventProvider3 (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
OutputTypeSystem.Event.Data

Member Modules:

ID Module Type TypeId RunAs 
DataSource DataSource Microsoft.Windows.TimedScript.PropertyBagProvider Default
Mapper ConditionDetection System.Event.GenericDataMapper Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Lenovo Windows WmiEventProvider EventProvider3 Interval Seconds
TimeoutSecondsint$Config/TimeoutSeconds$Lenovo Windows WmiEventProvider EventProvider3 Timeout Seconds

Source Code:

<DataSourceModuleType ID="IBM.Windows.WmiEventProvider.EventProvider3" Accessibility="Public" Batching="false">
<Configuration>
<IncludeSchemaTypes>
<SchemaType>System!System.ExpressionEvaluatorSchema</SchemaType>
</IncludeSchemaTypes>
<xsd:element name="IntervalSeconds" type="xsd:int"/>
<xsd:element name="TimeoutSeconds" type="xsd:integer"/>
<!--<xsd:element name="EventLevel" type="xsd:integer" />-->
<!--<xsd:element name="Expression" type="ExpressionType" />-->
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DataSource" TypeID="Windows!Microsoft.Windows.TimedScript.PropertyBagProvider">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime/>
<ScriptName>HwComponentsHealth3.vbs</ScriptName>
<Arguments/>
<ScriptBody><Script>


SetLocale("en-us")

'Debug Log Definition
Const HKEY_LOCAL_MACHINE = &amp;H80000002
Const DEBUG_INFO_KEY = "SOFTWARE\Lenovo\Lenovo SCOM MP\Debug"
Const DEBUG_LEVEL_NAME = "Level"
Const ERROR_LEVEL = 1
Const WARNING_LEVEL = 2
Const INFO_LEVEL = 4

Const DEVICEID1 = "Tag="""
Const DEVICEID2 = "DeviceId="""
Const DEVICEID3 = "DeviceID="""
Const DEVICEID4 = "deviceID="""
Const STORAGEID = "AllStorage"

'For Director Core Service
Const IBMSD_NAMESPACE = "root/ibmsd"
Const COMPONENTHEALTH_IBMSD_CALSS = "IBMPSG_ComponentHealth"
Dim debug, oAPI, oBag, swFlag
Dim ComponentId


Call GetComponentHealthStatus()


Sub GetComponentHealthStatus()

Dim oReg, RC_Code

debug = -1

Set oAPI = SCOMCreateObject("MOM.ScriptAPI")
Set oReg = GetObject("winmgmts://localhost/root/default:StdRegProv")
If (not(oReg is nothing)) Then
RC_Code = oReg.GetStringValue(HKEY_LOCAL_MACHINE, DEBUG_INFO_KEY, DEBUG_LEVEL_NAME, debug)
If ( RC_Code&lt;&gt;0) Then
debug = -1
End If
End If
Call LogDebugString("Entering GetComponentHealthStatus", INFO_LEVEL)
'Set oBag= oAPI.CreateTypedPropertyBag(1)
Call AddComponentHealthBag(oBag)
Call LogDebugString("Ending GetComponentHealthStatus", INFO_LEVEL)
'Call oAPI.Return(oBag)'
Call oAPI.ReturnItems

End Sub

Function AddComponentHealthBag(ByRef oBag)
Call LogDebugString("Entering AddComponentHealthBag", INFO_LEVEL)
Dim iResult, oCollection, oObjectItem, iComponentHealth, oDeviceID, oStorageHealth, oStorageHealthDes
AddComponentHealthBag = -1
iComponentHealth = -1
oStorageHealth = 0
oStorageHealthDes = ""

iResult = GetWMIObjectCollection(IBMSD_NAMESPACE, COMPONENTHEALTH_IBMSD_CALSS, oCollection)
If (iResult &gt; 0) Then
'There is at least one instance of IBMPSG_ComponentHealth showed under the root/ibmsd namespace
For Each oObjectItem in oCollection
If IsStorageDevice(oObjectItem) Then
oDeviceID = STORAGEID
Else
If IsNull(oObjectItem.AlertingManagedElement) Then
oDeviceID = GetDeviceID(oObjectItem.EventID)
Else
oDeviceID = GetDeviceID(oObjectItem.AlertingManagedElement)
End If
End If
If (oDeviceID &lt;&gt; STORAGEID) then
Set oBag= oAPI.CreateTypedPropertyBag(1)
End If
'Got the relative instance in collection
If oObjectItem.PerceivedSeverity &gt;= 5 Then
'Error - Severity's value is 5+
Call LogDebugString(oDeviceID + " Error added into property bag", INFO_LEVEL)
If oDeviceID = STORAGEID Then
'oStorageHealth = "Error"
oStorageHealth = 2
oStorageHealthDes = oStorageHealthDes + oObjectItem.Description &amp; vbCrLf
Else
Call oBag.AddValue("ComponentID",oDeviceID)
Call oBag.AddValue("AlertSeverity",2)
Call oBag.AddValue("EventLevel",1)'error
Call oBag.AddValue("EventDescription",oObjectItem.Description)
End If
iComponentHealth = 1
ElseIf oObjectItem.PerceivedSeverity &gt;= 3 Then

Call LogDebugString(oDeviceID + " Warning added into property bag", INFO_LEVEL)
If oDeviceID = STORAGEID Then
If oStorageHealth &lt;&gt; 2 Then
'oStoragehealth = "Warning"
oStoragehealth = 1
oStorageHealthDes = oStorageHealthDes + oObjectItem.Description &amp; vbCrLf
End If
Else
Call oBag.AddValue("ComponentID",oDeviceID)
Call oBag.AddValue("AlertSeverity",1)
Call oBag.AddValue("EventLevel",2)
Call oBag.AddValue("EventDescription",oObjectItem.Description)
End If
iComponentHealth = 1
ElseIf oObjectItem.PerceivedSeverity &gt;= 0 Then
Call LogDebugString(oDeviceID + " Healthy added into property bag", INFO_LEVEL)
If oDeviceID = STORAGEID Then
If (oStorageHealth &lt;&gt; 1) and (oStorageHealth &lt;&gt; 2) Then
oStoragehealth = 0
End if
oStorageHealthDes = oStorageHealthDes + oObjectItem.Description &amp; vbCrLf
Else
Call oBag.AddValue("ComponentID",oDeviceID)
Call oBag.AddValue("AlertSeverity",0)
Call oBag.AddValue("EventLevel",0)
Call oBag.AddValue("EventDescription",oObjectItem.Description)
End If
iComponentHealth = 1
End If 'PreceivedSeverity
oAPI.AddItem oBag

Next'Foreach

Set oBag= oAPI.CreateTypedPropertyBag(1)
Call oBag.AddValue("ComponentID",STORAGEID)
Call oBag.AddValue("AlertSeverity",oStorageHealth)
If oStorageHealth = 2 then
Call oBag.AddValue("EventLevel",1)
ElseIF oStorageHealth = 1 then
Call oBag.AddValue("EventLevel",2)
Else
Call oBag.AddValue("EventLevel",0)
End If
Call oBag.AddValue("EventDescription",oStorageHealthDes)
oAPI.AddItem oBag

If iComponentHealth &lt; 0 Then
'Healthy - no relative instances exist in the collection, default value is Healthy
Call LogDebugString(" No instance in component health", WARNING_LEVEL)
iComponentHealth = 1
End If
Else
Set oBag= oAPI.CreateTypedPropertyBag(1)

Call oBag.AddValue("ComponentID","No Instance in IBMPSG_ComponentHealth")
Call oBag.AddValue("AlertSeverity",1)
Call oBag.AddValue("EventLevel",2)
Call oBag.AddValue("EventDescription","No Instance in IBMPSG_ComponentHealth")
oAPI.AddItem oBag
'No root/ibmsd namespace or instances of IBMPSG_ComponentHealth available
Call LogDebugString("Can not get Component Health instances", WARNING_LEVEL)
End If'iResult
End Function

'@\\KKR004\root\ibmsd:IBMPSG_PhysicalMemory.CreationClassName="IBMPSG_PhysicalMemory",Tag="Physical Memory 2f2801f4601f201f45"
'\\KKR004\root\ibmsd:IBMPSG_PowerSupply.CreationClassName="IBMPSG_PowerSupply",DeviceID="PS 1 Status:3f3201f201f450",SystemCreationClassName="IBMSD_ComputerSystem",SystemName="KKR004"
Function GetDeviceID(oEventID)
Dim iBeginPos, iEndPos, sTemp, searchChar
searchChar = DEVICEID1
iBeginPos = 0
iEndPos = 0
GetDeviceID = ""
iBeginPos = Instr(oEventID, searchChar)
If iBeginPos &lt;&gt; 0 Then
iBeginPos = iBeginPos + Len(searchChar)
searchChar = """"
iEndPos = Instr(iBeginPos, oEventID, searchChar)
If iEndPos &lt;&gt;0 Then
sTemp = Mid(oEventID, iBeginPos, iEndPos-iBeginPos)

sTemp = Replace(sTemp, "/", " ")
sTemp = Replace(sTemp, ".", " ")
GetDeviceID = LTrim(RTrim(sTemp))
End If
Else
searchChar = DEVICEID2
iBeginPos = Instr(oEventID, searchChar)

If iBeginPos &lt;&gt; 0 Then
iBeginPos = iBeginPos + Len(searchChar)
searchChar = """"
iEndPos = Instr(iBeginPos, oEventID, searchChar)
If iEndPos &lt;&gt;0 Then
sTemp = Mid(oEventID, iBeginPos, iEndPos-iBeginPos)
sTemp = Replace(sTemp, "/", " ")
sTemp = Replace(sTemp, ".", " ")
GetDeviceID = LTrim(RTrim(sTemp))
End If
Else
searchChar = DEVICEID3
iBeginPos = Instr(oEventID, searchChar)
If iBeginPos &lt;&gt; 0 Then
iBeginPos = iBeginPos + Len(searchChar)
searchChar = """"
iEndPos = Instr(iBeginPos, oEventID, searchChar)
If iEndPos &lt;&gt;0 Then
sTemp = Mid(oEventID, iBeginPos, iEndPos-iBeginPos)
sTemp = Replace(sTemp, "/", " ")
sTemp = Replace(sTemp, ".", " ")
GetDeviceID = LTrim(RTrim(sTemp))
End If
Else
searchChar = DEVICEID4
iBeginPos = Instr(oEventID, searchChar)

If iBeginPos &lt;&gt; 0 Then
iBeginPos = iBeginPos + Len(searchChar)
searchChar = """"
iEndPos = Instr(iBeginPos, oEventID, searchChar)
If iEndPos &lt;&gt;0 Then
sTemp = Mid(oEventID, iBeginPos, iEndPos-iBeginPos)
sTemp = Replace(sTemp, "/", " ")
sTemp = Replace(sTemp, ".", " ")
GetDeviceID = LTrim(RTrim(sTemp))
End If
End If
End If
End If
End If
End Function

Function IsStorageDevice(oObjectItem)

'find the key words for the storage device
'We have CIM_DiskDrive, IBMPSG_LogicalDisk, IBMPSG_DiskDrive now

IsStorageDevice = 0
Dim oIndicationString
oIndicationString = Null
oIndicationString = oObjectItem.AlertingManagedElement
If IsNull(oIndicationString) Then
oIndicationString = oObjectItem.EventID
End If
IsStorageDevice = IsStorageDeviceEx(oIndicationString)

End Function

Function IsStorageDeviceEx(oIndicationString)

'find the key words for the storage device
'We have CIM_DiskDrive, IBMPSG_LogicalDisk, IBMPSG_DiskDrive, ADPT_, IBMPSG_Storage, IBMPSG_ServeRAID now

IsStorageDeviceEx = 0
Dim iPos
iPos = Instr(oIndicationString, "CIM_DiskDrive")
If iPos &lt;&gt; 0 Then
IsStorageDeviceEx = 1
Exit Function
Else
iPos = Instr(oIndicationString, "IBMPSG_LogicalDisk")
End If

If iPos &lt;&gt; 0 Then
IsStorageDeviceEx = 1
Exit Function
Else
iPos = Instr(oIndicationString, "IBMPSG_DiskDrive")
End If

If iPos &lt;&gt; 0 Then
IsStorageDeviceEx = 1
Exit Function
Else
iPos = Instr(oIndicationString, "ADPT_")
End If

If iPos &lt;&gt; 0 Then
IsStorageDeviceEx = 1
Exit Function
Else
iPos = Instr(oIndicationString, "IBMPSG_Storage")
End If

If iPos &lt;&gt; 0 Then
IsStorageDeviceEx = 1
Exit Function
Else
iPos = Instr(oIndicationString, "IBMPSG_ServeRAID")
End If

If iPos &lt;&gt; 0 Then
IsStorageDeviceEx = 1
Exit Function
End If

End Function


Sub LogDebugString(debugString, debugLevel)

If (Int(debug) &gt;= Int(debugLevel)) Then
Call oAPI.LogScriptEvent("HwComponentsHealth3.vbs", 411, DebugLevelToLogLevel(debugLevel), debugString)
End If

End Sub

Function DebugLevelToLogLevel(debugLevel)
DebugLevelToLogLevel = 4
If debugLevel &lt;= 1 then
DebugLevelToLogLevel = 1
ElseIF debugLevel &lt;= 3 then
DebugLevelToLogLevel = 2
Else
DebugLevelToLogLevel = 4
End If
End Function

Function GetWMIObjectCollection(ByVal oNameSpace, ByVal oClassName, ByRef oObjectCollection)

Call LogDebugString("Entering GetWMIObjectCollection", INFO_LEVEL)
GetWMIObjectCollection = -1
Dim e
Set e = New Error
On Error Resume Next
Set oObjectCollection = GetObject("winmgmts:{impersonationLevel=impersonate}//" &amp; _
"." &amp; "/" &amp; oNameSpace &amp; ":" &amp; oClassName).Instances_

'Check WMI communications...
If (oObjectCollection is nothing) Then
Call LogDebugString("No " + oClassName + " class in the namespace", WARNING_LEVEL)
Exit Function
End If

If (oObjectCollection.Count = 0) Then 'Try to count system instances...
Call LogDebugString("No instance on " + oClassName, WARNING_LEVEL)
GetWMIObjectCollection = 0
Exit Function
Else
If (Err.number &lt;&gt; 0) Then
Call LogDebugString("Error on accessing " + oClassName, ERROR_LEVEL)
Exit Function
Else
GetWMIObjectCollection = 1
End If
End If
End Function

Function QueryWMIObjectCollection(ByVal oNameSpace, ByVal oWQL, ByRef oObjectCollection)

Call LogDebugString("Entering QueryWMIObjectCollection", INFO_LEVEL)
QueryWMIObjectCollection = -1
Dim e
Set e = New Error
On Error Resume Next

Set oObjectCollection = GetObject("winmgmts:{impersonationLevel=impersonate}//./" &amp; oNameSpace ).ExecQuery(oWQL)

WScript.Echo "oObjectCollection.Count" + CStr(oObjectCollection.Count)
Call LogDebugString("oObjectCollection.Count" + CStr(oObjectCollection.Count), INFO_LEVEL)
'Check WMI communications...
If (oObjectCollection is nothing) Then
Call LogDebugString("No " + oClassName + " class in the namespace", WARNING_LEVEL)
Exit Function
End If

If (oObjectCollection.Count = 0) Then 'Try to count system instances...
Call LogDebugString("No instance on " + oClassName, WARNING_LEVEL)
QueryWMIObjectCollection = 0
Exit Function
Else
If (Err.number &lt;&gt; 0) Then
Call LogDebugString("Error on accessing " + oClassName, ERROR_LEVEL)
Exit Function
Else
QueryWMIObjectCollection = 1
End If
End If
End Function

Function SCOMCreateObject(ByVal sProgramId)

Dim oError
Set oError = New Error

On Error Resume Next
Set SCOMCreateObject = CreateObject(sProgramId)
oError.Save
On Error Goto 0

If (oError.Number &lt;&gt; 0) Then
Call LogDebugString("Error to create object", ERROR_LEVEL)
WScript.Quit
End If

End Function

Class Error
Private lNumber
Private sSource
Private sDescription
Private sHelpContext
Private sHelpFile
Public Sub Save()
lNumber = Err.number
sSource = Err.Source
sDescription = Err.Description
sHelpContext = Err.HelpContext
sHelpFile = Err.helpfile
End Sub
Public Sub Raise()
Err.Raise lNumber, sSource, sDescription, sHelpFile, sHelpContext
End Sub
Public Sub Clear()
lNumber = 0
sSource = ""
sDescription = ""
sHelpContext = ""
sHelpFile = ""
End Sub
Public Default Property Get Number()
Number = lNumber
End Property
Public Property Get Source()
Source = sSource
End Property
Public Property Get Description()
Description = sDescription
End Property
Public Property Get HelpContext()
HelpContext = sHelpContext
End Property
Public Property Get HelpFile()
HelpFile = sHelpFile
End Property
End Class

</Script></ScriptBody>
<SecureInput/>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<EventPolicy/>
</DataSource>
<!--<ConditionDetection ID="Filter" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="UnsignedInteger">Property[@Name="AlertSeverity"]</XPathQuery>
</ValueExpression>
<Operator>GreaterEqual</Operator>
<ValueExpression>
<Value Type="UnsignedInteger">0</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>-->
<ConditionDetection ID="Mapper" TypeID="System!System.Event.GenericDataMapper">
<EventOriginId>$Target/Id$</EventOriginId>
<PublisherId>$MPElement$</PublisherId>
<PublisherName>WmiEventProvider</PublisherName>
<Channel>WmiEventProvider</Channel>
<LoggingComputer/>
<EventNumber>0</EventNumber>
<EventCategory>1</EventCategory>
<EventLevel>0</EventLevel>
<UserName/>
<Description/>
<Params>
<Param>$Data/Property[@Name='ComponentID']$</Param>
<Param>$Data/Property[@Name="AlertSeverity"]$</Param>
<Param>$Data/Property[@Name="EventDescription"]$</Param>
<Param>$Data/Property[@Name="EventLevel"]$</Param>
</Params>
</ConditionDetection>
</MemberModules>
<Composition>
<Node ID="Mapper">
<!--<Node ID="Filter">-->
<Node ID="DataSource"/>
<!--</Node>-->
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Event.Data</OutputType>
</DataSourceModuleType>