Helper Utility Probe (Property Bag)

Dell.HelperUtilityProbe (ProbeActionModuleType)

Element properties:

TypeProbeActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
InputTypeSystem.BaseData
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
SCR ProbeAction Microsoft.Windows.ScriptPropertyBagProbe Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
LogLevelint$Config/LogLevel$Log LevelDell Helper Utility Probe LogLevel
Timeoutint$Config/TimeoutSeconds$TimeoutDell Helper Utility Probe Timeout

Source Code:

<ProbeActionModuleType ID="Dell.HelperUtilityProbe" Accessibility="Internal" Batching="false" PassThrough="false">
<Configuration>
<xsd:element minOccurs="1" name="LogLevel" type="xsd:integer"/>
<xsd:element minOccurs="1" name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element minOccurs="1" name="HelperUtilityCode" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="LogLevel" Selector="$Config/LogLevel$" ParameterType="int"/>
<OverrideableParameter ID="Timeout" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<ProbeAction ID="SCR" TypeID="Windows!Microsoft.Windows.ScriptPropertyBagProbe">
<ScriptName>HelperUtilityProbeScript.vbs</ScriptName>
<Arguments>$Config/LogLevel$</Arguments>
<ScriptBody><Script>
'**********************************************************************************
' Script Name - HelperUtility_Discovery
' Author: Vaidees, Sriram Venkatesh
'
' Description:
' Discovers HelperUtility under Management server
'
' (c) Copyright Dell Inc. 2011 - All rights reserved
'**********************************************************************************
Option Explicit
SetLocale("en-us")

Const DebugScript = False
Dim scriptArgs
Set scriptArgs = WScript.Arguments
Dim logLevel
logLevel = scriptArgs(0)
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

Class HelperUtility
private m_helperName
private m_helperInterface
private m_helperVersion
private m_helperDLLName
private m_hObject
private m_getLastError
private m_32BitDllRegistryKey
private m_64BitDllRegistryKey

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 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 &amp; " found"
IsPresent = False
Select Case Err.Number
Case 429: m_getLastError = m_helperInterface &amp; " 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

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 = "Not Present"
end if

End Property

Public Property Get ReqVersion
ReqVersion = "5.0.1"
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 LicenseConfigurationManager
private m_helperInterface
private m_hObject
private m_licenseWebServerURL
private m_licenseUsageStatistics
private m_productName
private m_productVersion
private m_featureName
private m_licenseAvailabilityStatus
private m_inUseLicensePercentage

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 Computer Corporation\Dell Server Management Pack Suites\LicenseWebServerURL")

log.MOMDebugLog 1, "licenseWebServerURLFromRegistry is: " &amp; 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-: " &amp; licenseResponseCode
If licenseResponseCode = 0 Then
LicenseAvailabilityStatus = "good"
IsLicenseServerReachable = True

licenseHealth = m_licenseUsageStatistics.getLicenseHealth()
log.MOMDebugLog 1, "licenseHealth-: " &amp; 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 &lt;&gt; 0 Then
m_inUseLicensePercentage = Round((licenseInUse/totalNodeLicenses) * 100)
End If
log.MOMDebugLog 1, "InUseLicensePercentage = " &amp; m_inUseLicensePercentage
Else

errorCode = m_licenseUsageStatistics.getErrorCode()
log.MOMDebugLog 1, "errorCode-: " &amp; 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 &lt;&gt; 0 Then
m_inUseLicensePercentage = Round((licenseInUse/totalNodeLicenses) * 100)
End If
log.MOMDebugLog 1, "InUseLicensePercentage = " &amp; 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 &lt;&gt; 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 = "DellOOBServer_Logs"
dim wshPrcEnv : Set wshPrcEnv = wsShell.Environment("Process")
tFolder = Replace(tFolder, "%SystemRoot%", wshPrcEnv("SYSTEMROOT"), 1, -1, vbTextCompare)
GetMDFileGUID guidLOG
strFileName = "Health_HelperUtility_" &amp; guidLOG &amp; ".log"

If Not FileSystemObject.FolderExists(tFolder) Then
FileSystemObject.CreateFolder(tFolder)
End If
If Not FileSystemObject.FolderExists(tFolder &amp; "\" &amp; oobLogsFolder) Then
FileSystemObject.CreateFolder(tFolder &amp; "\" &amp; oobLogsFolder)
End If
strOutFile = tFolder &amp; "\" &amp; oobLogsFolder &amp; "\" &amp; strFileName

DebugOut "Logging to " &amp; strOutFile
If Not FileSystemObject.FileExists(strOutFile) Then
Set objLogTextFile = FileSystemObject.CreateTextFile(strOutFile)
objLogTextFile.Close()
End If
fileSize = FileSystemObject.GetFile(strOutFile).Size
If (fileSize &gt; 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 &amp; "-" &amp; datesuffix &amp; "-" &amp; timesuffix &amp; ".log"
DebugOut "MoveFile " &amp; strOutFile &amp; " to " &amp; 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 &lt;&gt; 0 Then
If (debugLevel &gt; 0) and (debugLevel &lt;= logLevel) Then
objLogTextFile.WriteLine(Now() &amp; " ---- " &amp; Message)
Err.Clear
End If
End If
End Sub

Function CloseLog()
If logLevel &lt;&gt; 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$

'#################################################################################################################################

'#################################################################################################################################
'**************************************************************************************************
'Resource Clean up statements goes here
'**************************************************************************************************
Call log.CloseLog()
'#################################################################################################################################

</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="SCR"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
<InputType>System!System.BaseData</InputType>
</ProbeActionModuleType>