'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<>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
iResult = GetWMIObjectCollection(IBMSD_NAMESPACE, COMPONENTHEALTH_IBMSD_CALSS, oCollection)
If (iResult > 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 <> STORAGEID) then
Set oBag= oAPI.CreateTypedPropertyBag(1)
End If
'Got the relative instance in collection
If oObjectItem.PerceivedSeverity >= 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 & 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 >= 3 Then
Call LogDebugString(oDeviceID + " Warning added into property bag", INFO_LEVEL)
If oDeviceID = STORAGEID Then
If oStorageHealth <> 2 Then
'oStoragehealth = "Warning"
oStoragehealth = 1
oStorageHealthDes = oStorageHealthDes + oObjectItem.Description & 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 >= 0 Then
Call LogDebugString(oDeviceID + " Healthy added into property bag", INFO_LEVEL)
If oDeviceID = STORAGEID Then
If (oStorageHealth <> 1) and (oStorageHealth <> 2) Then
oStoragehealth = 0
End if
oStorageHealthDes = oStorageHealthDes + oObjectItem.Description & 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 < 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 <> 0 Then
iBeginPos = iBeginPos + Len(searchChar)
searchChar = """"
iEndPos = Instr(iBeginPos, oEventID, searchChar)
If iEndPos <>0 Then
sTemp = Mid(oEventID, iBeginPos, iEndPos-iBeginPos)
If iBeginPos <> 0 Then
iBeginPos = iBeginPos + Len(searchChar)
searchChar = """"
iEndPos = Instr(iBeginPos, oEventID, searchChar)
If iEndPos <>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 <> 0 Then
iBeginPos = iBeginPos + Len(searchChar)
searchChar = """"
iEndPos = Instr(iBeginPos, oEventID, searchChar)
If iEndPos <>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 <> 0 Then
iBeginPos = iBeginPos + Len(searchChar)
searchChar = """"
iEndPos = Instr(iBeginPos, oEventID, searchChar)
If iEndPos <>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 <> 0 Then
IsStorageDeviceEx = 1
Exit Function
Else
iPos = Instr(oIndicationString, "IBMPSG_LogicalDisk")
End If
If iPos <> 0 Then
IsStorageDeviceEx = 1
Exit Function
Else
iPos = Instr(oIndicationString, "IBMPSG_DiskDrive")
End If
If iPos <> 0 Then
IsStorageDeviceEx = 1
Exit Function
Else
iPos = Instr(oIndicationString, "ADPT_")
End If
If iPos <> 0 Then
IsStorageDeviceEx = 1
Exit Function
Else
iPos = Instr(oIndicationString, "IBMPSG_Storage")
End If
If iPos <> 0 Then
IsStorageDeviceEx = 1
Exit Function
Else
iPos = Instr(oIndicationString, "IBMPSG_ServeRAID")
End If
If iPos <> 0 Then
IsStorageDeviceEx = 1
Exit Function
End If
End Function
Sub LogDebugString(debugString, debugLevel)
If (Int(debug) >= Int(debugLevel)) Then
Call oAPI.LogScriptEvent("HwComponentsHealth3.vbs", 411, DebugLevelToLogLevel(debugLevel), debugString)
End If
End Sub
Function DebugLevelToLogLevel(debugLevel)
DebugLevelToLogLevel = 4
If debugLevel <= 1 then
DebugLevelToLogLevel = 1
ElseIF debugLevel <= 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}//" & _
"." & "/" & oNameSpace & ":" & 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 <> 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}//./" & 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 <> 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 <> 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