Set oReg = GetObject( "winmgmts://localhost/root/default:StdRegProv")
bccInstalled = IsInstallBCCProject()
If bccInstalled = true Then
call GetLicenseLevel(licenseLevel, licenseToken)
If IsNull(licenseToken) Or IsEmpty(licenseToken) Or licenseToken = "" Then
Call LogDebugString("No entitlements found to verify the License Token", INFO_LEVEL)
licenseLevel = "None"
licenseToken = ""
End if
If licenseLevel <> "None" Then
If (Isnull(IPAddress)) then
Call LogDebugString("Error: Bad or missing ipaddress!", WARNING_LEVEL)
Else
Set bladeChassis = WScript.CreateObject("IBM.SystemsManagement.MMClassLibrary.BladeChassis")
Dim port
port = 0
Dim init
init = -1
' Don't forget to set SNMP in MM Web console, and "access type" should be "Set" value
init = bladeChassis.InitializeSocketConnection(IPAddress, CommunityString, port,"V1")
If init = 0 Then
Select Case ModuleType
case BLADE_TYPE
Call LogDebugString("IBM BladeCenter Blade Power On. Blade: " + primaryBayNumber(0), INFO_LEVEL_DETAIL)
init = bladeChassis.PowerOnBlade(primaryBayNumber(0))
If init <> 0 Then
Call LogDebugString("Cannot Power On Blade!", WARNING_LEVEL_DEV)
WScript.Echo("----------------------------------------" & vbcrlf & _
"--------------- Task failed ------------" & vbcrlf & _
"----------------------------------------" & vbcrlf & _
"Cannot Power On Blade! " & vbcrlf & _
"Return code from MMClassLibrary.BladeChassis.PowerOnBlade: " & init & vbcrlf & _
"----------------------------------------" )
End If
End Select
End If
bladeChassis.CloseSocketConnection()
End If
Else
WScript.Echo("----------------------------------------" & vbcrlf & _
"--------------- Task failed ------------" & vbcrlf & _
"----------------------------------------" & vbcrlf & _
"The necessary IBM License feature level is not installed on Windows Computer for Managing IBM BladeCenter. " & vbcrlf & _
"The feature you ran requires feature level 3.0 or higher. " & vbcrlf & _
"To take advantage of premium features, please contact your IBM representative." & vbcrlf & _
"----------------------------------------" )
End If
End If
Function GetModuleBayNumber(tempModBay)
Dim n
n = InStr(1,tempModBay," Bay ",1)
If n > 0 then
GetModuleBayNumber = Right(tempModBay, Len(tempModBay) - n - 4)
Else
GetModuleBayNumber = 0
End If
End Function
Function Chr2Unicode(byval str)
Dim st, t, i
For i = 1 To Len(str) Step 2
t = Mid(str, i, 1)
st = st + t
Next
Chr2Unicode = st
End Function
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
Sub GetDebugLevel()
Dim oReg,RC_Code
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, Regdebug)
If ( RC_Code<>0) Then
Regdebug = -1
End If
End If
End Sub
'-----------------------------------------------------------------------------
'start of IsInstallBCCProject()
'This Function judges whether the target machine installed or not
'IBM Assemblies For Systems Management Support.
'-----------------------------------------------------------------------------
Function IsInstallBCCProject()
Dim IsInstalled
IsInstalled = true
Dim obj
Set obj = WScript.CreateObject("WScript.Shell")
Dim regpath
regpath = "HKEY_LOCAL_MACHINE\SOFTWARE\IBM\Systems Management Integrations\IBM HW Mgmt Pack for OpsMgr\Path"
Dim InstallPath
InstallPath = obj.RegRead(regpath)
If not isNull(InstallPath) then
IsInstalled = true
Else
IsInstalled = false
WScript.Echo("!!!!!!!!!!Error: BCC Not Installed!!!!!!!!!!!!")
call LogDebugString("Error: BCC Not Installed!",ERROR_LEVEL)
End If
IsInstallBCCProject = IsInstalled
'WScript.Echo(IsInstalled)
End Function
'-------------------------------------------------------------------------------
'end of IsInstallBCCProject()
'-------------------------------------------------------------------------------
Function GetLicenseLevel(ByRef sLicLevel, ByRef sLicTok)
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
'-------------------------------------------------------------------------------
If IsEmpty(oReg) Or IsNull(oReg) Or (oReg is Nothing) 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
'-------------------------------------------------------------------------------
'start of LogDebugString()
'-------------------------------------------------------------------------------
Sub LogDebugString(debugString, debugLevel)
If (Int(Regdebug) >= Int(debugLevel)) Then
Call oAPI.LogScriptEvent("IBMBladeCenterPowerOnModule.vbs", 210, 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
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
dim aKeyEntryNames, aKeyEntryTypes
Call LogDebugString(".. LicManager: loading from registry key '" + _
IBMHWMP_LICENSE_KEY + "'", INFO_LEVEL_FUNCTION)
Call oReg.EnumValues( HKEY_LOCAL_MACHINE, IBMHWMP_LICENSE_KEY, _
aKeyEntryNames, aKeyEntryTypes )
if isArray( aKeyEntryNames ) then
Call LogDebugString(".. LicManager: # of registry value entries = " + _
CStr(UBound(aKeyEntryNames)+1), INFO_LEVEL_DETAIL)
end if
if isNull( aKeyEntryNames ) or not(isArray( aKeyEntryNames )) then
exit sub
end if
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
call oReg.GetStringValue( HKEY_LOCAL_MACHINE, IBMHWMP_LICENSE_KEY, _
aKeyEntryNames(ii), sLevelERsEncoded )
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