Fournisseur de reconnaissance du serveur sous licence Lenovo Windows

IBM.LicenseServer.Discovery.Provider (DataSourceModuleType)

Fournisseur de reconnaissance du serveur sous licence Lenovo Windows

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.Discovery.Data

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.Windows.TimedScript.DiscoveryProvider Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Fournisseur de reconnaissance du serveur sous licence Lenovo Windows - Intervalle en secondes
SyncTimestring$Config/SyncTime$Fournisseur de reconnaissance du serveur sous licence Lenovo Windows - Durée de synchronisation
TimeoutSecondsstring$Config/TimeoutSeconds$Fournisseur de reconnaissance du serveur sous licence Lenovo Windows - Délai d'attente en secondes

Source Code:

<DataSourceModuleType ID="IBM.LicenseServer.Discovery.Provider" Accessibility="Internal">
<Configuration>
<xsd:element name="IntervalSeconds" type="xsd:integer"/>
<xsd:element name="SyncTime" type="xsd:string"/>
<xsd:element name="ComputerID" type="xsd:string"/>
<xsd:element name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" ParameterType="int" Selector="$Config/IntervalSeconds$"/>
<OverrideableParameter ID="SyncTime" ParameterType="string" Selector="$Config/SyncTime$"/>
<OverrideableParameter ID="TimeoutSeconds" ParameterType="string" Selector="$Config/TimeoutSeconds$"/>
</OverrideableParameters>
<ModuleImplementation>
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedScript.DiscoveryProvider">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime>$Config/SyncTime$</SyncTime>
<ScriptName>IBMLicenseServerDiscovery.vbs</ScriptName>
<Arguments>"$MPElement$" "$Target/Id$" "$Config/ComputerID$"</Arguments>
<ScriptBody><Script>

Option Explicit
'Command executed: "C:\Windows\system32\cscript.exe" /nologo "detectLicenseServer.vbs" "{6AB98AFF-00AE-7B4A-3478-2C4E13B82FB8}" "{E4E8B894-0CF2-9F5C-50B4-BB5CC78C3694}" "WIN-GOTUO98BF4M.SCOMR2X64.NET"
Dim oArgs
Set oArgs = WScript.Arguments
If oArgs.Count &lt; 3 Then
WScript.Quit -1
End If

Dim sourceID, managedEntityID, computerID

sourceID = oArgs(0)
managedEntityID = oArgs(1)
computerID = oArgs(2)
Call LogDebugString("sourceID:" &amp; sourceID, INFO_LEVEL_FUNCTION)
Call LogDebugString("managedEntityID:" &amp; managedEntityID, INFO_LEVEL_FUNCTION)
Call LogDebugString("computerID:" &amp; computerID, INFO_LEVEL_FUNCTION)
Dim Regdebug, oAPI, oDiscoveryData, oReg

'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 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.
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

Const RMS_KEY_Lenovo = "SOFTWARE\Lenovo\Systems Management Integrations\Lenovo HW Mgmt Pack for OpsMgr"
Const RMS_KEY_IBM = "SOFTWARE\IBM\Systems Management Integrations\IBM HW Mgmt Pack for OpsMgr"
Const RMS_Name = "RMSName"
'Const RMS_MPVER = "Version"

SetLocale("en-us")

Call IBMLicenseServerDiscovery()

Sub IBMLicenseServerDiscovery()

Dim RC_Code, version
Regdebug = -1
Call LogDebugString("Entering IBM.LicenseServer", INFO_LEVEL_FUNCTION)
Set oAPI = SCOMCreateObject("MOM.ScriptAPI")
'Set oReg = GetObject("winmgmts://localhost/root/default:StdRegProv")
Set oReg = GetObject( "winmgmts:{impersonationLevel=impersonate}!" &amp; _
"//./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 &lt;&gt; 0) Then
Regdebug = -1
End If
Call LogDebugString("oReg is not nothing, Regdebug="&amp;Regdebug, INFO_LEVEL_FUNCTION)
End If


Set oDiscoveryData = oAPI.CreateDiscoveryData(0, sourceID, managedEntityID)

If (CreateIBMLicenseServerInstance(version) &gt; 0) Then
Call LogDebugString("Created IBM.LicenseServer instance", INFO_LEVEL_DETAIL)
End If

Call oAPI.Return(oDiscoveryData)

End Sub

Function CreateIBMLicenseServerInstance(ByVal version)

Call LogDebugString("Entering CreateIBMLicenseServerInstance", INFO_LEVEL_FUNCTION)
Dim oIBMIBMLicenseServerInstance, RC_Code, RMS, licenseLevel, licenseToken, SCOMServer, generateLicense

generateLicense = 0

RMS = Null
If (Not(oReg Is Nothing)) Then
RC_Code = oReg.GetStringValue(HKEY_LOCAL_MACHINE, RMS_KEY_Lenovo, RMS_Name, RMS)
If IsNull(RMS) Then
RC_Code = oReg.GetStringValue(HKEY_LOCAL_MACHINE, RMS_KEY_IBM, RMS_Name, RMS)
End If
End If

If IsNull(RMS) Then
''' twoffer: Ignore all non-RMS systems
Call LogDebugString("This system is not a license managing server", INFO_LEVEL)
CreateIBMLicenseServerInstance = -1
Else
'Linlin GetLicenseLevel function should be supported by licenseMgmt tool, Tony should supply it.
'Or just to check whether the license Mgmt tool was installed on it. Check the registry key.
'Here the "LicenseLevel" property just tell whether it is our Licnese Server. if we could find the real license level, will be better.
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 = ""
'CreateIBMLicenseServerInstance = -1
'ElseIf IsNull(version) Or IsEmpty(version) Or version = "" Then
' Call LogDebugString("No entitlements found to verify this Lenovo License server", INFO_LEVEL)
' CreateIBMLicenseServerInstance = -1
'Else
' CreateIBMLicenseServerInstance = 1
Else
generateLicense = 1
End If

''' twoffer: always create IBM.LicenseServer discovery class
Set oIBMIBMLicenseServerInstance = oDiscoveryData.CreateClassInstance("$MPElement[Name='IBM.LicenseServer']$")
Call oIBMIBMLicenseServerInstance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", computerID)
Call oIBMIBMLicenseServerInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", computerID)
Call oIBMIBMLicenseServerInstance.AddProperty("$MPElement[Name='IBM.LicenseServer']/LicenseLevel$", licenseLevel)
Call oIBMIBMLicenseServerInstance.AddProperty("$MPElement[Name='IBM.LicenseServer']/LicenseToken$", licenseToken)

Call oDiscoveryData.AddInstance(oIBMIBMLicenseServerInstance)
CreateIBMLicenseServerInstance = 1
If generateLicense = 1 Then
Call LogDebugString("generateLicense", INFO_LEVEL)
Set SCOMServer = WScript.CreateObject("IBM.SystemsManagement.SCOMHelper.SCOMServer")
Call SCOMServer.GenerateLicense(LicenseLevel, LicenseToken)
End If
End If

End Function

Function GetLicenseLevel(ByRef sLicLevel, ByRef sLicTok)

sLicLevel = Null
sLicTok = Null
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 Lenovo License Server", WARNING_LEVEL)
End If
Else
Call LogDebugString("No feature levels activated on this Lenovo License Server", WARNING_LEVEL)
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

Sub LogDebugString(debugString, debugLevel)

If (Int(Regdebug) &gt;= Int(debugLevel)) Then
Call oAPI.LogScriptEvent("IBMLicenseServerDiscovery.vbs", 116, 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


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

Public Sub LoadFromRegistry()

Dim nLevelsLoaded, licenseFlag
nLevelsLoaded = 0
m_aLevelERs = Null
m_sLicToken = ""
licenseFlag = 1

Dim aKeyEntryNames, aKeyEntryTypes
Call LogDebugString(".. LicManager: loading from registry key '" + _
LenovoHWMP_LICENSE_KEY + "'", INFO_LEVEL_FUNCTION)
Call oReg.EnumValues( HKEY_LOCAL_MACHINE, LenovoHWMP_LICENSE_KEY, _
aKeyEntryNames, aKeyEntryTypes )

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) &gt;= 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 &lt;= 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("&gt;&gt; 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) &gt;= 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 &gt; oBestLevelER.LevelMajor) Or _
(oLevelER.LevelMajor = oBestLevelER.LevelMajor And _
oLevelER.LevelMinor &gt; 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) &lt;&gt; 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.
' &lt;twoffer&gt; Can this be referenced instead of copied? &lt;/twoffer&gt;
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 &lt;&gt; 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") &amp; iGroup
sPreliminaryOutString = Chr(CByte("&amp;H" &amp; Mid(iGroup, 1, 2))) &amp; Chr(CByte("&amp;H" &amp; Mid(iGroup, 3, 2))) &amp; Chr(CByte("&amp;H" &amp; Mid(iGroup, 5, 2)))
sOutputString = sOutputString &amp; Left(sPreliminaryOutString, iDataByteCount)
Next
fDecode = sOutputString
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>$Config/TimeoutSeconds$</TimeoutSeconds>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>