IBM.HardwareMgmtPack.xSystems.PowerReadingData (Rule)

Element properties:

TargetIBM.WinComputer
CategoryPerformanceCollection
EnabledTrue
Alert GenerateFalse
RemotableTrue

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.Windows.TimedScript.PerformanceProvider Default
WriteToDB WriteAction Microsoft.SystemCenter.CollectPerformanceData Default
WriteToDW WriteAction Microsoft.SystemCenter.DataWarehouse.PublishPerformanceData Default

Source Code:

<Rule ID="IBM.HardwareMgmtPack.xSystems.PowerReadingData" Enabled="true" Target="IBM.WinComputer" ConfirmDelivery="false" Remotable="true" Priority="Normal" DiscardLevel="100">
<Category>PerformanceCollection</Category>
<DataSources>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedScript.PerformanceProvider">
<IntervalSeconds>1800</IntervalSeconds>
<SyncTime/>
<ScriptName>PowerReadingData.vbs</ScriptName>
<Arguments/>
<ScriptBody><Script>
SetLocale("en-us")
Const DEBUG_INFO_KEY = "SOFTWARE\Lenovo\Lenovo SCOM MP\Debug"
Const DEBUG_LEVEL_NAME = "Level"
Const HKEY_LOCAL_MACHINE = &amp;H80000002
Const ERROR_LEVEL = 1
Const WARNING_LEVEL = 2
Const WARNING_LEVEL_DEV = 3
Const INFO_LEVEL = 4
Const INFO_LEVEL_FUNCTION = 5
Const INFO_LEVEL_DETAIL = 6


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


Dim oAPI, oDiscoveryData, machineType

Dim debug, oReg,RC_Code, ScriptName, EventID

ScriptName = "PowerReadingData.vbs"

debug = -1
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)
End If
Set oAPI = SCOMCreateObject("MOM.ScriptAPI")

Sub LogDebugString(debugString, debugLevel)

If (Int(debug) &gt;= Int(debugLevel)) Then
Call oAPI.LogScriptEvent(ScriptName, 105, 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

Dim oObjectItem, oSystemInstanceCollection, iResult
Const IBMSD_NAMESPACE = "root/ibmsd"

Dim oPthresholdCollection, oPthresholdInstance,oPthresholdCurReading


iResult = GetWMIObjectCollection(IBMSD_NAMESPACE, "IBMPSG_AveragePowerUsageSensor", oPthresholdCollection)



If (iResult &gt; 0) Then

' Only one set of property in the collection.
For Each oPthresholdInstance in oPthresholdCollection
oPthresholdCurReading = oPthresholdInstance.CurrentReading
Next

Call LogDebugString("oPthresholdCurReading=" &amp; oPthresholdCurReading, INFO_LEVEL_FUNCTION)
'WScript.Echo "=========================================="
'WScript.Echo oPthresholdCurReading
Dim oBag
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()
Call oBag.AddValue("PowerReading",oPthresholdCurReading)
Call oAPI.Return(oBag)
else
'WScript.Echo "iResult&lt;=0"
Call LogDebugString("Failed to get the object of IBMPSG_AveragePowerUsageSensor.", INFO_LEVEL_FUNCTION)
End If

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

Call LogDebugString("Entering GetWMIObjectCollection(" + oNameSpace + ":" + oClassName + ")", INFO_LEVEL_FUNCTION)
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", INFO_LEVEL_DETAIL)
WScript.Echo "No " + oClassName + " class in the namespace"
Exit Function
End If

If (oObjectCollection.Count = 0) Then 'Try to count system instances...
Call LogDebugString("No instance on " + oClassName, INFO_LEVEL_DETAIL)
WScript.Echo "No instance on " + oClassName
GetWMIObjectCollection = 0
Exit Function
Else
If (Err.number &lt;&gt; 0) Then
Call LogDebugString("Error on accessing " + oClassName, ERROR_LEVEL)
WScript.Echo "Error on accessing " + oClassName
Exit Function
Else
GetWMIObjectCollection = 1
End If
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>
<TimeoutSeconds>30</TimeoutSeconds>
<ObjectName>PowerReading</ObjectName>
<CounterName>Power_Reading</CounterName>
<InstanceName>All Instances</InstanceName>
<Value>$Data/Property[@Name='PowerReading']$</Value>
</DataSource>
</DataSources>
<WriteActions>
<WriteAction ID="WriteToDB" TypeID="SC!Microsoft.SystemCenter.CollectPerformanceData"/>
<WriteAction ID="WriteToDW" TypeID="SCDW!Microsoft.SystemCenter.DataWarehouse.PublishPerformanceData"/>
</WriteActions>
</Rule>