Const DebugScript = False
Dim scriptArgs
Set scriptArgs = WScript.Arguments
Dim logLevel
logLevel = scriptArgs(0)
Dim HelperDLLVersion
HelperDLLVersion = scriptArgs(1)
Dim log: Set log = New Logger
Call log.CreateLog("")
Function GetLicenseUrlFromRegistry (strRegistryKey )
Dim WSHShell, value
On Error Resume Next
Set WSHShell = CreateObject("WScript.Shell")
value = WSHShell.RegRead( strRegistryKey )
set WSHShell = nothing
GetLicenseUrlFromRegistry = value
End Function
Public Property Let Name(hlpName)
m_helperName = hlpName
End Property
Public Property Let HelperInterface(hlpInterfaceObj)
m_helperInterface = hlpInterfaceObj
End Property
Public Property Let Version(hlpVersion)
m_helperVersion = hlpVersion
End Property
Public Property Let HelperDLLName(hlpDLLNameObj)
m_helperDLLName = hlpDLLNameObj
End Property
Public Property Let Helper32BitRegistryKey(hlpRegistryKeyObj)
m_32BitDllRegistryKey = hlpRegistryKeyObj
End Property
Public Property Let Helper501RegistryKey(hlpRegistryKeyObj)
m_Helper501RegistryKey = hlpRegistryKeyObj
End Property
Public Property Let Helper64BitRegistryKey(hlpRegistryKeyObj)
m_64BitDllRegistryKey = hlpRegistryKeyObj
End Property
Public Property Get Name
Name = m_helperName
End Property
Public Property Get IsPresent
On Error Resume Next
Err.Clear
Set m_hObject = CreateObject(m_helperInterface)
m_getLastError = m_helperInterface & " found"
IsPresent = False
Select Case Err.Number
Case 429: m_getLastError = m_helperInterface & " not found or not supplied"
Case 462: m_getLastError = "Server is not available"
case 53: m_getLastError = "File not found"
Case Else: IsPresent = True
End Select
End Property
Public Property Get Version
On Error Resume Next
Dim oShell
Set oShell = CreateObject ("WScript.Shell")
Version = oShell.RegRead(m_32BitDllRegistryKey)
if Version="" Then
Version = oShell.RegRead(m_64BitDllRegistryKey)
end if
if version = "" Then
Version = oShell.RegRead(m_Helper501RegistryKey)
end if
if Version="" Then
Version = "Not Present"
end if
End Property
Public Property Get ReqVersion
ReqVersion = "5.2.0"
End Property
Public Property Get IsCompatible
IsCompatible = (Version = ReqVersion)
End Property
Public Property Get LastError
'On Error Resume Next
LastError = m_getLastError
End Property
End Class
Class CrentialsEnteredCheck
private m_appname
private m_UserName
public m_501HelperDLLPresence
Public Property Let SetApplicationName(applicationName)
m_appname = applicationName
End Property
Public Property Get UserName
UserName = m_UserName
End Property
Public Function CheckCredentialsConfigured()
Dim m_catalog, m_applications, m_application, status, temp
Set m_catalog = CreateObject("COMAdmin.COMAdminCatalog")
Set m_applications = m_catalog.GetCollection("Applications")
m_applications.Populate
For each m_application in m_applications
if m_application.Name = m_appname then
m_UserName = m_application.Value("Identity")
temp = LCase(m_UserName)
Wscript.echo "username is" & temp
Select Case temp
Case "nt authority\localservice"
status = "Not Configured"
Case "nt authority\networkservice"
status = "Not Configured"
Case "interactive user"
status = "Not Configured"
Case else
status = "Configured"
End Select
end if
Next
CheckCredentialsConfigured = status
End Function
Public Function CheckUserNameInRegistry()
On Error Resume Next
Dim oRegistry, m_user
Set oRegistry = CreateObject("WScript.Shell")
m_user = oRegistry.RegRead("HKEY_LOCAL_MACHINE\Software\Dell\Dell Server Management Pack Suites\UserName")
CheckUserNameInRegistry = m_user
End Function
Public Function UpdateRegistryUserName()
Dim oReg
Set oReg = CreateObject("WScript.Shell")
Call oReg.RegWrite("HKEY_LOCAL_MACHINE\Software\Dell\Dell Server Management Pack Suites\UserName", m_UserName)
End Function
End Class
Public Sub Class_Initialize
m_hObject = null
m_inUseLicensePercentage = 0
End sub
Public Property Let HelperInterface(hlpInterfaceObj)
m_helperInterface = hlpInterfaceObj
End Property
Public Function LoadLicenseConfiguration()
Set m_hObject = CreateObject(m_helperInterface)
End Function
Public Function SetProductName(productName)
m_productName = productName
End Function
Public Function SetProductVersion(productVersion)
m_productVersion = productVersion
End Function
Public Function SetFeatureName(featureName)
m_featureName = featureName
End Function
Public Property Get IsLicenseServerConfigured
' Read the license web server url from the registry
Dim licenseWebServerURLFromRegistry
licenseWebServerURLFromRegistry = GetLicenseUrlFromRegistry("HKEY_LOCAL_MACHINE\Software\Dell\Dell Server Management Pack Suites\LicenseWebServerURL")
log.MOMDebugLog 1, "licenseWebServerURLFromRegistry is: " & licenseWebServerURLFromRegistry
m_licenseWebServerURL = licenseWebServerURLFromRegistry
If m_licenseWebServerURL = "" Then
IsLicenseServerConfigured = False
ElseIf m_licenseWebServerURL = "http://licensewebserver.company.com:8543/" Then
IsLicenseServerConfigured = False
Else
IsLicenseServerConfigured = True
End If
End Property
Public Property Get IsLicenseServerReachable
Dim licenseResponseCode, errorCode, licenseHealth, licenseInUse, totalNodeLicenses
IsLicenseServerReachable = True
Set m_licenseUsageStatistics = m_hObject.GetLicenseUsageMetricsForFeature(m_productName, m_productVersion, m_featureName)
licenseResponseCode = m_licenseUsageStatistics.getResponseCode()
log.MOMDebugLog 1, "licenseResponseCode-: " & licenseResponseCode
If licenseResponseCode = 0 Then
LicenseAvailabilityStatus = "good"
IsLicenseServerReachable = True
licenseHealth = m_licenseUsageStatistics.getLicenseHealth()
log.MOMDebugLog 1, "licenseHealth-: " & licenseHealth
If licenseHealth = 0 Then
' License health is GREEN
log.MOMDebugLog 1, "License health is GREEN "
LicenseAvailabilityStatus = "good"
ElseIf licenseHealth = 1 Then
' License health is YELLOW
log.MOMDebugLog 1, "License health is YELLOW "
LicenseAvailabilityStatus = "bad"
ElseIf licenseHealth = 2 Then
' License health is RED
log.MOMDebugLog 1, "License health is RED "
LicenseAvailabilityStatus = "ugly"
Else
' Other error conditions
' License health is RED
log.MOMDebugLog 1, "License health is RED "
LicenseAvailabilityStatus = "ugly"
End If
licenseInUse = m_licenseUsageStatistics.getNumOfInUseLicensesForFeature()
totalNodeLicenses = m_licenseUsageStatistics.getTotalNodeLicensesForFeature()
If totalNodeLicenses <> 0 Then
m_inUseLicensePercentage = Round((licenseInUse/totalNodeLicenses) * 100)
End If
log.MOMDebugLog 1, "InUseLicensePercentage = " & m_inUseLicensePercentage
Else
errorCode = m_licenseUsageStatistics.getErrorCode()
log.MOMDebugLog 1, "errorCode-: " & errorCode
If errorCode = 1 Then
' No license data found
LicenseAvailabilityStatus = "worse"
ElseIf errorCode = 2 Then
' License server is down (ConnectionFailed)
IsLicenseServerReachable = False
ElseIf errorCode = 3 Then
' CredentialsNotSet
IsLicenseServerReachable = False
ElseIf errorCode = 4 Then
' AccessDenied
IsLicenseServerReachable = False
ElseIf errorCode = 5 Then
' NotEnoughPriviliges
IsLicenseServerReachable = False
ElseIf errorCode = 7 Then
' No sufficient licenses (usage above 120%)
LicenseAvailabilityStatus = "ugly"
licenseInUse = m_licenseUsageStatistics.getNumOfInUseLicensesForFeature()
totalNodeLicenses = m_licenseUsageStatistics.getTotalNodeLicensesForFeature()
If totalNodeLicenses <> 0 Then
m_inUseLicensePercentage = Round((licenseInUse/totalNodeLicenses) * 100)
End If
log.MOMDebugLog 1, "InUseLicensePercentage = " & m_inUseLicensePercentage
Else
' Other error conditions
LicenseAvailabilityStatus = "other"
End If
End If
End Property
Public Function getInUseLicensePercentage()
getInUseLicensePercentage = m_inUseLicensePercentage
End Function
Public Property Get LicenseAvailabilityStatus
LicenseAvailabilityStatus = m_licenseAvailabilityStatus
End Property
Public Property Let LicenseAvailabilityStatus(licenseAvailabilityStatusObj)
m_licenseAvailabilityStatus = licenseAvailabilityStatusObj
End Property
End Class
'**************************************************************************************************
'MOMAPIHelper class
'This class provides wrapper functions for calls made to MOM API functions
'**************************************************************************************************
Class MOMAPIHelper
Private oAPI
Private oBag
Public Function CreateMOMScriptAPI
If DebugScript = False Then
Set oAPI = CreateObject("MOM.ScriptAPI")
Else
log.DebugOut "Creating MOM Script API"
Set oAPI = New RegExp
End If
End Function
Public Function CreatePropertyBag
If DebugScript = False Then
set oBag = oAPI.CreatePropertyBag()
Else
Set oBag = New RegExp
End If
End Function
Public Sub AddInstValue(prop, val)
If DebugScript = False Then
Call oBag.AddValue(prop, val)
End If
End Sub
Public Sub AddDataItem()
If DebugScript = False Then
Call oAPI.AddItem(oBag)
End If
End Sub
Public Sub ReturnDataItems
If DebugScript = False Then
Call oAPI.ReturnItems
End If
End Sub
End Class
'*****************************************************************
'Logger class
'Used for generating debug logs
'*****************************************************************
Class Logger
Private objLogTextFile
Private Sub Class_Initialize
End Sub
Function DebugOut(message)
If DebugScript Then WScript.Echo message
End Function
'*****************************************************************
'GetMDFileGUID
'Routine to generate unique GUIDs for the LOG files
'*****************************************************************
Function GetMDFileGUID(ByRef o_guid)
Dim TypeLib, NewGUID
Set TypeLib = CreateObject("Scriptlet.TypeLib")
NewGUID = TypeLib.Guid
o_guid = (left(NewGUID, len(NewGUID)-2))
Set TypeLib = Nothing
End Function
Function CreateLog(myIP)
Dim FileSystemObject
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
' Begin Logheader
If logLevel <> 0 Then
Dim fileSize, strOutFile, newFilename, dateStr, datesuffix, timesuffix, subStrLoc
Const ForAppending = 8
Const ForWriting = 2
Const MaxFileSize = 524288 'File Size is limited to 512 KB
Dim strFileName, guidLOG
dim wsShell : Set wsShell = Createobject("WScript.Shell")
dim wshSysEnv : Set wshSysEnv = wsShell.Environment
dim tFolder : tFolder = wshSysEnv("TEMP")
dim oobLogsFolder : oobLogsFolder = "DellDeviceHelper_Logs"
dim wshPrcEnv : Set wshPrcEnv = wsShell.Environment("Process")
tFolder = Replace(tFolder, "%SystemRoot%", wshPrcEnv("SYSTEMROOT"), 1, -1, vbTextCompare)
GetMDFileGUID guidLOG
strFileName = "Health_HelperUtility_" & guidLOG & ".log"
If Not FileSystemObject.FolderExists(tFolder) Then
FileSystemObject.CreateFolder(tFolder)
End If
If Not FileSystemObject.FolderExists(tFolder & "\" & oobLogsFolder) Then
FileSystemObject.CreateFolder(tFolder & "\" & oobLogsFolder)
End If
strOutFile = tFolder & "\" & oobLogsFolder & "\" & strFileName
DebugOut "Logging to " & strOutFile
If Not FileSystemObject.FileExists(strOutFile) Then
Set objLogTextFile = FileSystemObject.CreateTextFile(strOutFile)
objLogTextFile.Close()
End If
fileSize = FileSystemObject.GetFile(strOutFile).Size
If (fileSize > MaxFileSize) Then
dateStr = CDate(Now())
datesuffix = ( Year(dateStr)*100 + Month(dateStr) )*100 + Day(dateStr)
timesuffix = Right((Hour(dateStr)*100+Minute(dateStr))*100+Second(dateStr)+1e7, 6)
subStrLoc = Instr(1, strOutFile,".")
newFilename = Mid(strOutFile,1,(subStrLoc-1))
newFilename = newFilename & "-" & datesuffix & "-" & timesuffix & ".log"
DebugOut "MoveFile " & strOutFile & " to " & newFilename
FileSystemObject.MoveFile strOutFile, newFilename
Set objLogTextFile = FileSystemObject.OpentextFile(strOutFile, ForWriting, True)
Else
Set objLogTextFile = FileSystemObject.OpentextFile(strOutFile, ForAppending, True)
End If
Err.Clear
End If
End Function
Sub MOMDebugLog (ByVal debugLevel, ByVal Message)
DebugOut Message
If logLevel <> 0 Then
If (debugLevel > 0) and (debugLevel <= logLevel) Then
objLogTextFile.WriteLine(Now() & " ---- " & Message)
Err.Clear
End If
End If
End Sub
Function CloseLog()
If logLevel <> 0 Then
objLogTextFile.Close
Set objLogTextFile = Nothing
End If
End Function
End Class
'#################################################################################################################################
'**************************************************************************************************
'Template method inclusion mechanism
'The following lines will expand the variables holding the VBScript classes and methods
'**************************************************************************************************
$Config/HelperUtilityCode$