Const IBMHWMP_LICENSE_KEY = "Software\IBM\Systems Management Integrations\License"
Const LenovoHWMP_LICENSE_KEY = "Software\Lenovo\Systems Management Integrations\License"
'Const IBMHWMP_LICENSE_SETUP_VERSION ="Version" 'suppose it is 3.0.6, the license tool's version, I saw the server side and endpoint is different, so this is useless.
Const IBMHWMP_LICENSE_TOKEN_NAME = "v1-0002.A"
Const IBMHWMP_LICENSE_LEVEL = "Level" 'suppose it is 3.0 or it is useless if we could get the Level from the token.
Dim oArgs
Set oArgs = WScript.Arguments
Dim sourceID, managedEntityID
Dim IBName,BCCIP,OOBName,isDetected
Dim description
Dim oBag, oReg, RC_Code, debug
debug = -1
Set oAPI = CreateObject("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 IBMCMMOOBHeathyReflectionDiscovery " + vbCrLf + sourceID + vbCrLf +managedEntityID , INFO_LEVEL)
Dim list, licenseLevel, licenseToken
Set oDiscoveryData = oAPI.CreateDiscoveryData(0, sourceID, managedEntityID)
Call LogDebugString("after CreateDiscoveryData", INFO_LEVEL_DETAIL)
'Lin If no license, we just do not create the Reflection object.
'Check the server whether has a license
'same method with GetLicenseLevel(licenseLevel, licenseToken) in IBMLicenseServerDiscovery.vbs
'If no license then
'Call oAPI.Return(oDiscoveryData) 'create an empty return data and quit WScript
call GetLicenseLevel(licenseLevel, licenseToken)
If IsNull(licenseLevel) Or IsEmpty(licenseLevel) Or licenseLevel = "" Then
Call LogDebugString("No IBM license found on this server", INFO_LEVEL)
Call oAPI.Return(oDiscoveryData)
WScript.Quit 0
End If
Dim SCOMServer,blade
Set SCOMServer = WScript.CreateObject("IBM.SystemsManagement.SCOMHelper.SCOMServer")
Call SCOMServer.InitSCOMServerConnection()
isDetected = SCOMServer.GetIBDetectedCMM(BCCIP)
Call LogDebugString("after GetIBDetectedCMM", INFO_LEVEL_DETAIL)
dim index
index =0
'need to modify
for each item in isDetected
set blade= SCOMServer.GetFlexRelationInfor(item)
if (not(blade is nothing)) then
description = blade.OOBBladeName + "-"+ blade.MMIPAddress
'WSCript.echo blade.OOBBladeName + " " + blade.MMIPAddress+ " " + blade.OOBBladeBay + " " + blade.IBHostName + " "+blade.IBDetected
call CreateHealthReflectionObject(description, blade.IBHostName,BCCIP,blade.OOBBladeBay,blade.OOBBladeName)
end if
next
Call oAPI.Return(oDiscoveryData)
Call LogDebugString("Create Health Reflection Object completed.", INFO_LEVEL)
Function CreateHealthReflectionObject(description, hostID,ip,bay, oobName)
Dim oInst
Set oInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='IBM.SystemX.CMMOOBHeathyReflection']$")
Call oInst.AddProperty("$MPElement[Name='IBM.SystemX.CMMOOBHeathyReflection']/Name$", description)
Call oInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "OOB-IB Flex Info")
Call oInst.AddProperty("$MPElement[Name='IBM.SystemX.CMMOOBHeathyReflection']/FlexChassisIPAddress$", ip)
Call oInst.AddProperty("$MPElement[Name='IBM.SystemX.CMMOOBHeathyReflection']/FlexChassisBladeName$", description)
Call oInst.AddProperty("$MPElement[Name='IBM.SystemX.CMMOOBHeathyReflection']/IBName$", hostID)
Call oInst.AddProperty("$MPElement[Name='IBM.SystemX.CMMOOBHeathyReflection']/IBDetected$", "true")
Call oInst.AddProperty("$MPElement[Name='IBMxSystems!IBM.SystemX.Platform']/HostPrincipalName$", hostID)
Call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", hostID)
oDiscoveryData.AddInstance(oInst)
'{{{
'[Lin]Do not add the reference relationship, it will cause the repeate create blade instance. MOMScriptAPI do not support the update data.
'Dim oRelRef, oSourceInst
'Set oSourceInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='IBMBCC!IBM.FlexSystem.BladeModule']$")
If (Int(debug) >= Int(debugLevel)) Then
Call oAPI.LogScriptEvent("IBMCMMOOBHeathyReflectionDiscovery.vbs", 301, debugLevel, debugString)
End If
End Sub
Function GetLicenseLevel(ByRef sLicLevel, ByRef sLicTok)
'-------------------------------------------------------------------------------
'add for Trial License start
sLicLevel = null
sLicTok = null
Dim trialresult
trialresult = false
Set objtr=WScript.CreateObject("IBM.SystemsManagement.MMClassLibrary.LicenseControl")
trialresult=objtr.TrialLicenseOK()
If trialresult Then
sLicLevel="255"
sLicTok="My4Y"
Exit Function
Else
sLicLevel=""
Call LogDebugString(objtr.GetTrialLicenseInfomation(), INFO_LEVEL_DETAIL)
End If
'add for Trial License end
'-------------------------------------------------------------------------------
sLicLevel = null
sLicTok = null
If IsEmpty(oReg) Or IsNull(oReg) Then
Exit Function
End If
Dim oLicValidator, aLicLevelERs, oBestLevelER
Set oLicValidator = new LicManager
Call oLicValidator.LoadFromRegistry()
aLicLevelERs = oLicValidator.LevelERs
If IsArray(aLicLevelERs) Then
sLicTok = oLicValidator.LicenseToken
Call oLicValidator.FindBestFeatLevel(oBestLevelER)
If Not IsNull(oBestLevelER) Then
sLicLevel = oBestLevelER.ToString()
Else
Call LogDebugString("The best matched feature level could " + _
"not be obtained on this IBM License Server", WARNING_LEVEL)
End If
Else
Call LogDebugString("No feature levels activated on this IBM License Server", WARNING_LEVEL)
End If
End Function
class LicManager
private m_aLevelERs
public property get LevelERs
LevelERs = m_aLevelERs
end property
private m_sLicToken
public property get LicenseToken
LicenseToken = m_sLicToken
end property
private sub Class_Initialize()
m_aLevelERs = null
m_sLicToken = ""
end sub
if isNull( aKeyEntryNames ) or not(isArray( aKeyEntryNames )) then
Call LogDebugString(".. LicManager: loading from registry key '" + _
IBMHWMP_LICENSE_KEY + "'", INFO_LEVEL_FUNCTION)
Call oReg.EnumValues( HKEY_LOCAL_MACHINE, IBMHWMP_LICENSE_KEY, _
aKeyEntryNames, aKeyEntryTypes )
licenseFlag = 0
end if
if isNull( aKeyEntryNames ) or not(isArray( aKeyEntryNames )) then
exit sub
end if
Call LogDebugString(".. LicManager: # of registry value entries = " + _
CStr(UBound(aKeyEntryNames)+1), INFO_LEVEL_DETAIL)
dim ii
for ii=0 to UBound(aKeyEntryNames)
if 1 = aKeyEntryTypes( ii ) then ' 1 = REG_SZ
if IBMHWMP_LICENSE_TOKEN_NAME = aKeyEntryNames(ii) then
dim sLevelERsEncoded, sLevelERsDecoded, asSplitERs
if licenseFlag = 1 then
call oReg.GetStringValue( HKEY_LOCAL_MACHINE, LenovoHWMP_LICENSE_KEY, _
aKeyEntryNames(ii), sLevelERsEncoded )
else
call oReg.GetStringValue( HKEY_LOCAL_MACHINE, IBMHWMP_LICENSE_KEY, _
aKeyEntryNames(ii), sLevelERsEncoded )
end if
if IsNull(sLevelERsEncoded) Or IsEmpty(sLevelERsEncoded) then
call LogDebugString("!! LicManager: Registry value " + _
aKeyEntryNames(ii) + " null or empty", ERROR_LEVEL)
else
call LogDebugString(".. LicManager: " + aKeyEntryNames(ii) + _
"='" + sLevelERsEncoded + "'", INFO_LEVEL_DETAIL)
m_sLicToken = sLevelERsEncoded
sLevelERsDecoded = fDecode(sLevelERsEncoded)
call LogDebugString(".. LicManager: " + aKeyEntryNames(ii) + _
"='" + sLevelERsDecoded + "' [Decoded]", INFO_LEVEL_DETAIL)
asSplitERs = split(sLevelERsDecoded, vbTab)
if UBound(asSplitERs) >= 0 then
dim jj
for jj=0 to UBound(asSplitERs)
call LogDebugString(".. LicManager: Retrieved '" + _
asSplitERs(jj) + "'", INFO_LEVEL_DETAIL)
dim oLevelER
set oLevelER = new FeatLevelER
if 0 <= oLevelER.ParseLevelER( asSplitERs(jj) ) then
if 0 = nLevelsLoaded then
m_aLevelERs = array( 0 ) ' create a 1-element array of '0'
else
redim preserve m_aLevelERs( nLevelsLoaded )
end if
set m_aLevelERs( nLevelsLoaded ) = oLevelER
nLevelsLoaded = nLevelsLoaded + 1
call LogDebugString(">> LicManager: Parsed " + _
oLevelER.ToString(), INFO_LEVEL)
end if
next
end if
end if
end if
end if
next
end sub ' LoadFromRegistry
public sub FindBestFeatLevel( byRef oBestLevelER )
oBestLevelER = null
if not( isArray( m_aLevelERs ) ) then
exit sub
end if
if UBound(m_aLevelERs) >= 0 then
dim ii, oLevelER
set oBestLevelER = m_aLevelERs(0)
for ii=1 to UBound(m_aLevelERs)
set oLevelER = m_aLevelERs(ii)
if (oLevelER.LevelMajor > oBestLevelER.LevelMajor) Or _
(oLevelER.LevelMajor = oBestLevelER.LevelMajor And _
oLevelER.LevelMinor > oBestLevelER.LevelMinor) then
set oBestLevelER = oLevelER
end if
next
end if
end sub
end class
class FeatLevelER
private m_levelMajor
private m_levelMinor
public property get LevelMajor
LevelMajor = m_levelMajor
end property
public property get LevelMinor
LevelMinor = m_levelMinor
end property
private sub Class_Initialize()
end sub
public function ParseLevelER( byVal sEntryValue )
dim retCode
retCode = 0
on error resume next
dim asSplit
asSplit = split( sEntryValue, "." )
if UBound(asSplit) <> 1 then
call LogDebugString("!! FeatLevelER.ParseLevelER: unexpected number of items in " + _
"feature level record (" + UBound(asSplit) + ")", ERROR_LEVEL)
retCode = -1
else
m_levelMajor = CInt(asSplit(0))
m_levelMinor = CInt(asSplit(1))
call LogDebugString(".. FeatLevelER.ParseLevelER: MajorVersion = " + _
CStr(m_levelMajor) + ", MinorVersion = " + CStr(m_levelMinor), INFO_LEVEL_DETAIL)
end if
on error goto 0
ParseLevelER = retCode
end function
public function ToString()
ToString = CStr(m_levelMajor) + "." + CStr(m_levelMinor)
end function
end class
' N.B. fDecode() is a verbatim copy of the one in HW MP.
' <twoffer> Can this be referenced instead of copied? </twoffer>
Function fDecode(sStringToDecode)
'This function will decode a Base64 encoded string and returns the decoded string.
Const CharList = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
Dim iDataLength, sOutputString, iGroupInitialCharacter
sStringToDecode = Replace(Replace(Replace(sStringToDecode, vbCrLf, ""), vbTab, ""), " ", "")
iDataLength = Len(sStringToDecode)
If iDataLength Mod 4 <> 0 Then
fDecode = "Bad string passed to fDecode() function."
Exit Function
End If
For iGroupInitialCharacter = 1 To iDataLength Step 4
Dim iDataByteCount, iCharacterCounter, sCharacter, iData, iGroup, sPreliminaryOutString
iDataByteCount = 3
iGroup = 0
For iCharacterCounter = 0 To 3
sCharacter = Mid(sStringToDecode, iGroupInitialCharacter + iCharacterCounter, 1)
If sCharacter = "=" Then
iDataByteCount = iDataByteCount - 1
iData = 0
Else
iData = InStr(1, CharList, sCharacter, 0) - 1
If iData = -1 Then
fDecode = "Bad string passed to fDecode() function."
Exit Function
End If
End If
iGroup = 64 * iGroup + iData
Next
iGroup = Hex(iGroup)
iGroup = String(6 - Len(iGroup), "0") & iGroup
sPreliminaryOutString = Chr(CByte("&H" & Mid(iGroup, 1, 2))) & Chr(CByte("&H" & Mid(iGroup, 3, 2))) & Chr(CByte("&H" & Mid(iGroup, 5, 2)))
sOutputString = sOutputString & Left(sPreliminaryOutString, iDataByteCount)
Next
fDecode = sOutputString
End Function