Dim IPAddress, CommunityString, Version, Timeout, Interval, LogLevel
Dim SNMPSuccess, strErrorCode, logMessage, DeviceKey, UID
Dim oAPI, oDiscoveryData, oInstance, oInstance1, oInstance2, oRelationship
Dim SourceId, ManagedEntityId, regHostName
Dim Classifier, DRACType
Dim AttrMap, ValueMap
Dim oArgs
Dim fileSize, strOutFile, objLogFSO, objLogTextFile, strFileName
Set oArgs = WScript.Arguments
InitLookups()
GetArguments()
MOMDebugLog 1,"Display the Content in HashMaps for Debugging."
MOMDebugLog 1,"--------------------Attribute MAP------------------"
DisplayMap(AttrMap)
MOMDebugLog 1,"--------------------Value Map-----------------------"
DisplayMap(ValueMap)
Classifier = DRACClassifier()
MOMDebugLog 1, "DRACClassifier:" & Classifier
DRACType = DRACTypeClassifier()
MOMDebugLog 1, "DRACTypeClassifier:" & DRACType
MOMDebugLog 1, "Creating oDiscoveryData(" & ValueMap.Item("SourceId") & "," & ValueMap.Item("ManagedEntityId") & ")"
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oDiscoveryData = oAPI.CreateDiscoveryData(0,ValueMap.Item("SourceId"),ValueMap.Item("ManagedEntityId"))
'Do not discover other than DRAC
If StrComp(Classifier, "Dell.RemoteAccess.RAC") = 0 Then
MOMDebugLog 1, "it is RAC device"
Else
MOMDebugLog 1, "it is not a RAC device. quit the program"
EmptyDiscovery()
Wscript.Quit(0)
End If
'Do not discover empty ServiceTag/ChassisTag
Dim rmEmptyUID
rmEmptyUID = ValueMap.Item("ServiceTag")
If (StrComp(rmEmptyUID, "") = 0) OR (StrComp(rmEmptyUID, "Not Available") = 0) Then
MOMDebugLog 1, "UID Can not be null. Hence, can not discover:" & ValueMap.Item("IPAddress")
EmptyDiscovery()
Wscript.Quit(0)
End If
MOMDebugLog 1, "Getting Health Service hosted"
'Get Principal Name
regHostName = GetRegistryValue("HKEY_LOCAL_MACHINE\Software\Dell Computer Corporation\Dell Management Pack Suites\MSHostname")
if StrComp(DRACType, "Dell.RemoteAccess.DRAC5") = 0 Then
CreateDRAC5()
Elseif StrComp(DRACType, "Dell.RemoteAccess.iDRAC6Modular") = 0 Then
CreateIDRAC6Modular()
Elseif StrComp(DRACType, "Dell.RemoteAccess.iDRAC6Monolithic") = 0 Then
CreateIDRAC6Monolithic()
Elseif StrComp(DRACType, "Dell.RemoteAccess.iDRAC7Monolithic") = 0 Then
CreateIDRAC7Monolithic()
Elseif StrComp(DRACType, "Dell.RemoteAccess.iDRAC7Modular") = 0 Then
CreateIDRAC7Modular()
Elseif StrComp(DRACType, "Dell.RemoteAccess.iDRAC8Monolithic") = 0 Then
CreateIDRAC8Monolithic()
Elseif StrComp(DRACType, "Dell.RemoteAccess.iDRAC8Modular") = 0 Then
CreateIDRAC8Modular()
Else
MOMDebugLog 1, "The given ip in a different discovery block. Hence quit."
EmptyDiscovery()
Wscript.Quit(0)
End If
Call oAPI.Return(oDiscoveryData)
Set oDiscoveryData = Nothing
Set oAPI = Nothing
'#######################################################
Function InitLog()
If logLevel <> 0 Then
strFileName = "Dell_" & "Discovery_" & ValueMap.Item("IPAddress") & ".log"
Const ForAppending = 8
Const ForWriting = 2
Const MaxFileSize = 524288 'File Size is limited to 512 KB
dim wsShell : Set wsShell = Createobject("WScript.Shell")
dim wshSysEnv : Set wshSysEnv = wsShell.Environment
dim tFolder : tFolder = wshSysEnv("TEMP")
dim wshPrcEnv : Set wshPrcEnv = wsShell.Environment("Process")
tFolder = Replace(tFolder, "%SystemRoot%", wshPrcEnv("SYSTEMROOT"), 1, -1, vbTextCompare)
Set objLogFSO = CreateObject("Scripting.FileSystemObject")
If Not objLogFSO.FolderExists(tFolder) Then
objLogFSO.CreateFolder(tFolder)
End If
tFolder = tFolder & "\DRACLogs"
If Not objLogFSO.FolderExists(tFolder) Then
objLogFSO.CreateFolder(tFolder)
End If
strOutFile = tFolder & "\" & strFileName
If Not objLogFSO.FileExists(strOutFile) Then
Set objLogTextFile = objLogFSO.CreateTextFile(strOutFile)
objLogTextFile.Close()
End If
fileSize = objLogFSO.GetFile(strOutFile).Size
If (fileSize > MaxFileSize) Then
Dim dateStr, datesuffix, timesuffix, subStrLoc, newFilename
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,".log")
newFilename = Mid(strOutFile,1,(subStrLoc-1))
newFilename = newFilename &"-"& datesuffix &"-"&timesuffix&".log"
objLogFSO.MoveFile strOutFile, newFilename
Set objLogTextFile = objLogFSO.OpentextFile(strOutFile, ForWriting, True)
Else
Set objLogTextFile = objLogFSO.OpentextFile(strOutFile, ForAppending, True)
End If
logMessage = "INFO: Script - DellDRACDiscovery : Start()"
MOMDebugLog 1, logMessage
Err.Clear
End If
End Function
Sub MOMDebugLog (ByVal debugLevel, ByVal Message)
On Error Resume Next
If (debugLevel > 0) and (debugLevel <= logLevel) Then
objLogTextFile.WriteLine(Now() & "-" & IPAddress & " ---- " & Message)
Err.Clear
End If
End Sub
' End of Logheader
'############################
'Get the DRACType
Function DRACTypeClassifier
Dim ProductType
ProductType = ValueMap.Item("ProductType")
Select Case ProductType
case "6": DRACTypeClassifier = "Dell.RemoteAccess.DRAC5"
case "9": DRACTypeClassifier = "Dell.RemoteAccess.iDRAC6Modular"
case "10" DRACTypeClassifier = "Dell.RemoteAccess.iDRAC6Monolithic"
case "13": DRACTypeClassifier = "Dell.RemoteAccess.iDRAC6Monolithic"
case "16": DRACTypeClassifier = "Dell.RemoteAccess.iDRAC7Monolithic"
case "17": DRACTypeClassifier = "Dell.RemoteAccess.iDRAC7Modular"
case "32": DRACTypeClassifier = "Dell.RemoteAccess.iDRAC8Monolithic"
case "33": DRACTypeClassifier = "Dell.RemoteAccess.iDRAC8Modular"
case "34": DRACTypeClassifier = "Dell.RemoteAccess.iDRAC8Monolithic"
case "1": DRACTypeClassifier = "Unknown":
case "2": DRACTypeClassifier = "Unknown":
case else: DRACTypeClassifier = "Unknown":
end Select
End Function
'##############################################
'Classify the network devices and the classifier name is the class name
Function DRACClassifier
If InStr(ValueMap.Item("ShortProductName"), "PowerEdge") > 0 Then
DRACClassifier = "Dell.RemoteAccess.CMC"
elseif StrComp(ValueMap.Item("ShortProductName"), "DRAC/MC") = 0 Then
DRACClassifier = "Dell.RemoteAccess.DRACMC"
elseif InStr(ValueMap.Item("ShortProductName"), "DRAC") > 0 Then
DRACClassifier = "Dell.RemoteAccess.RAC"
end if
End Function
'##################################################
'Create Sink object and return discovery data
Function EmptyDiscovery()
Set oInstance = oDiscoveryData.CreateClassInstance("$MPElement[Name='DAD!Dell.RemoteAccess.DiscoverySink']$")
call oInstance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "Dell RemoteAccess Discovery Sink")
call oInstance.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.DiscoverySink']/Name$", "DONTCARE")
oDiscoveryData.AddInstance oInstance
Call oAPI.Return(oDiscoveryData)
Set oDiscoveryData = Nothing
Set oAPI = Nothing
End Function
'##############################################
Function GetMSName
Dim StrRegKeyCompName, StrRegKeyTCPIP, WSHShell, StrHostname, StrDomainName, StrFQDN
StrRegKeyCompName = "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\"
StrRegKeyTCPIP = "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\"
Set WSHShell = CreateObject("WScript.Shell")
StrHostname = WSHShell.RegRead (StrRegKeyTCPIP & "Hostname")
StrDomainName = WSHShell.RegRead (StrRegKeyTCPIP & "Domain")
StrFQDN = StrHostName & "." & StrDomainName
GetMSName = StrFQDN
End Function
'##################################################
Function GetRegistryValue (strRegistryKey )
Dim WSHShell, value
On Error Resume Next
Set WSHShell = CreateObject("WScript.Shell")
value = WSHShell.RegRead( strRegistryKey )
If(strcomp(value,"") = 0) Then
value = GetMSName()
end if
set WSHShell = nothing
GetRegistryValue = value
End Function
'##################################################
Function PopulateAttrMap()
End Function
'##############################################
Function GetArguments()
MOMDebugLog 1, "Entered GetArguments"
Dim ArgumentIterator, ArgumentCounter, ArgumentBuffer , ArgumentTemp
ArgumentIterator = 0
ArgumentCounter = 0
ArgumentBuffer = "Not Available"
Dim key, value
Do
ArgumentTemp = oArgs(ArgumentIterator)
if ((StrComp(ArgumentTemp,"#*#") = 0 ) or (StrComp(argumentTemp,"###") = 0 )) Then
if ((ArgumentCounter mod 2) = 0) Then
key = trim(ArgumentBuffer)
else
value = trim(ArgumentBuffer)
AddToValueMap key, value
end if
ArgumentBuffer = ""
ArgumentCounter = ArgumentCounter + 1
elseif (StrComp(ArgumentBuffer,"Not Available") = 0 ) Then
ArgumentBuffer = ArgumentTemp
else
ArgumentBuffer = ArgumentBuffer & " " & ArgumentTemp
end if
ArgumentIterator = ArgumentIterator + 1
Loop while Not(StrComp(argumentTemp,"###") = 0)
PopulateValueMap(AttrMap)
End Function
'##################################
Function InitLookups
Set AttrMap = CreateObject("Scripting.Dictionary")
PopulateAttrMap()
Set ValueMap = CreateObject("Scripting.Dictionary")
End Function
'###########################################
Function AddToValueMap(key, value)
Dim attrName
if(StrComp(Left(key, 3), "1.3") = 0 )Then
'It is an OIDS
key = "." & key
End if
if StrComp(key, "") = 0 OR StrComp(key, "\n") = 0 Then
Exit Function
end if
if AttrMap.Exists(key) Then
attrName = AttrMap.Item(key)
if StrComp(value, "") = 0 Then
value = "Not Available"
end if
if ValueMap.Exists(attrName) Then
if StrComp(value,"") = 0 Then
else
ValueMap.Item(attrName) = value
end if
else
ValueMap.Add attrName, value
end if
else
attrName = AttrMap.Item(key)
end If
End Function
'#####################################################
Function DisplayMap(ByRef map)
Dim i, cnt
cnt = 0
For each i in map.Keys
MOMDebugLog 1, cnt & ":" & i
cnt = cnt + 1
Next
cnt = 0
For each i in map.Items
MOMDebugLog 1, cnt & ":" & i
cnt = cnt + 1
Next
End Function
'#####################################################
Function PopulateValueMap(ByRef map)
Dim value, cnt, key1
cnt = 0
value = "Not Available"
For each key1 in map.Items
If(ValueMap.Exists(key1) = false) Then
ValueMap.Add key1, value
End If
Next
End Function
'##############################################################
Function GetFormFactor(ByVal formfactorVal)
Select Case formfactorVal
case "3": GetFormFactor = "1U Monolithic"
case "4": GetFormFactor = "2U Monolithic"
case "5": GetFormFactor = "4U Monolithic"
case "12": GetFormFactor = "5U Monolithic"
case "6": GetFormFactor = "7U Monolithic"
case "7": GetFormFactor = "Single width, half height Modular"
case "8": GetFormFactor = "Dual width, half height Modular"
case "9": GetFormFactor = "Single width, full height Modular"
case "10": GetFormFactor = "Dual width, full height Modular"
case "11": GetFormFactor = "Single width, quarter height Modular"
case "13": GetFormFactor = "1U, half width Modular"
case "14": GetFormFactor = "1U, quarter width Modular"
case "15": GetFormFactor = "1U, full width Modular"
case "2": GetFormFactor = "Not Available"
case else: GetFormFactor = "Not Available"
End Select
End Function
'Get the ProductType
Function getProductType(ByVal ProductType)
Select Case ProductType
case "6": getProductType = "DRAC 5"
case "9": getProductType = "iDRAC 6 Modular"
case "10" getProductType = "iDRAC 6 Monolithic"
case "13": getProductType = "iDRAC 6 Monolithic"
case "16": getProductType = "iDRAC 7 Monolithic"
case "17": getProductType = "iDRAC 7 Modular"
case "32": getProductType = "iDRAC 8 Monolithic"
case "33": getProductType = "iDRAC 8 Modular"
case "34": getProductType = "iDRAC 8 Monolithic"
case else: getProductType = "Unknown"
End Select
End Function
'##############################################################
Function PopulateRACAttributes(ByRef oInstance1)
MOMDebugLog 1,"Entered PopulateRACAttributes()"
MOMDebugLog 1,"Add PrincipalName:" & regHostName
call oInstance1.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", regHostName)
MOMDebugLog 1,"Add DisplayName:" & ValueMap.Item("IPAddress")
call oInstance1.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", ValueMap.Item("IPAddress"))
'NodeID/Service Tag as UID
Dim UIDValue, NodeID, ProductType
NodeID = ValueMap.Item("NodeID")
If (StrComp(NodeID, "") = 0) OR (StrComp(NodeID, "Not Available") = 0) OR (StrComp(ValueMap.Item("ServiceTag"), NodeID) = 0) Then
UIDValue = ValueMap.Item("ServiceTag")
Else
UIDValue = NodeID
End If
MOMDebugLog 1,"Add UID:" & UIDValue
call oInstance1.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.RAC']/UID$", UIDValue)
MOMDebugLog 1,"Add DeviceKey:" & ValueMap.Item("IPAddress")
call oInstance1.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.RAC']/DeviceKey$", ValueMap.Item("IPAddress"))
MOMDebugLog 1,"Add IPAddress:" & ValueMap.Item("IPAddress")
call oInstance1.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.RAC']/IPAddress$", ValueMap.Item("IPAddress"))
MOMDebugLog 1, "add CommunityString:" & ValueMap.Item("CommunityString")
call oInstance1.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.RAC']/CommunityString$", ValueMap.Item("CommunityString"))
MOMDebugLog 1,"Add ServiceTag:" & ValueMap.Item("ServiceTag")
call oInstance1.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.RAC']/ServiceTag$", ValueMap.Item("ServiceTag"))
MOMDebugLog 1,"Add ProdName:" & ValueMap.Item("ProdName")
call oInstance1.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.RAC']/ProdName$", ValueMap.Item("ProdName"))
MOMDebugLog 1,"Add ShortProductName:" & ValueMap.Item("ShortProductName")
call oInstance1.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.RAC']/ShortProductName$", ValueMap.Item("ShortProductName"))
MOMDebugLog 1,"Add Description:" & ValueMap.Item("Description")
call oInstance1.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.RAC']/Description$", ValueMap.Item("Description"))
MOMDebugLog 1,"Add Manufacturer:" & ValueMap.Item("Manufacturer")
call oInstance1.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.RAC']/Manufacturer$", ValueMap.Item("Manufacturer"))
MOMDebugLog 1,"Add Version:" & ValueMap.Item("Version")
call oInstance1.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.RAC']/Version$", ValueMap.Item("Version"))
MOMDebugLog 1,"Add OOBURL:" & ValueMap.Item("OOBURL")
call oInstance1.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.RAC']/OOBURL$", ValueMap.Item("OOBURL"))
MOMDebugLog 1,"Add Firmware:" & ValueMap.Item("Firmware")
call oInstance1.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.RAC']/Firmware$", ValueMap.Item("Firmware"))
ProductType = getProductType(ValueMap.Item("ProductType"))
MOMDebugLog 1,"Add ProductType:" & ProductType
call oInstance1.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.RAC']/ProductType$", ProductType)
AddEnrichedAttributes(oInstance1)
MOMDebugLog 1,"Exiting PopulateRACAttributes()"
End Function
'##############################################################
Function AddEnrichedAttributes(ByRef oInstance1)
MOMDebugLog 1,"Add AssetTag:" & ValueMap.Item("AssetTag")
call oInstance1.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.RAC']/AssetTag$", ValueMap.Item("AssetTag"))
MOMDebugLog 1,"Add ExpressServiceCode:" & ValueMap.Item("ExpressServiceCode")
call oInstance1.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.RAC']/ExpressServiceCode$", ValueMap.Item("ExpressServiceCode"))
Dim formfactor
formfactor = GetFormFactor(ValueMap.Item("FormFactor"))
MOMDebugLog 1,"Add FormFactor:" & formfactor
call oInstance1.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.RAC']/FormFactor$", formfactor)
MOMDebugLog 1,"Add ServerHostName:" & ValueMap.Item("ServerHostName")
call oInstance1.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.RAC']/ServerHostName$", ValueMap.Item("ServerHostName"))
MOMDebugLog 1,"Add DataCenterName:" & ValueMap.Item("DataCenterName")
call oInstance1.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.RAC']/DataCenterName$", ValueMap.Item("DataCenterName"))
Dim Location
Location = ""
Location = "AISLE:" & ValueMap.Item("AISLE") & ", RACK:" & ValueMap.Item("RACK") & ", Slot on Rack:" & ValueMap.Item("SLOT")
MOMDebugLog 1,"Aisle:" & ValueMap.Item("AISLE") & "RACK:" & ValueMap.Item("RACK") & "Slot:" & ValueMap.Item("SLOT")
MOMDebugLog 1,"Add Location:" & Location
call oInstance1.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.RAC']/Location$", Location)
End Function
'##############################################################
Function CreateDRAC5()
MOMDebugLog 1,"Creating CreateDRAC5"
Set oInstance1 = oDiscoveryData.CreateClassInstance("$MPElement[Name='DAD!Dell.RemoteAccess.DRAC5']$")
PopulateRACAttributes(oInstance1)
Set oRelationship = oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='DellRemoteAccessiDRAC7Modular.Contains.DelliDRAC7ModularNetworkDevice']$")
oRelationship.Source = oInstance1
oRelationship.Target = oInstance2
oDiscoveryData.AddInstance oRelationship
End Function
'#######################################################
'6-iDRAC8Monolithic
'#############################################################
Function CreateiDRAC8Monolithic()
MOMDebugLog 1,"Creating CreateiDRAC8Monolithic"
Set oInstance1 = oDiscoveryData.CreateClassInstance("$MPElement[Name='DAD!Dell.RemoteAccess.iDRAC8Monolithic']$")
PopulateRACAttributes(oInstance1)
MOMDebugLog 1,"Add ChassisName:" & ValueMap.Item("ChassisName")
call oInstance1.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.RAC']/ChassisName$", "Not Applicable")
MOMDebugLog 1,"Add ChassisTag:" & ValueMap.Item("ChassisTag")
call oInstance1.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.RAC']/ChassisTag$", "Not Applicable")
MOMDebugLog 1,"Add System Model:" & ValueMap.Item("SystemModel")
call oInstance1.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.RAC']/SystemModel$", ValueMap.Item("SystemModel"))
MOMDebugLog 1,"Add Operating System Name:" & ValueMap.Item("OperatingSystemName")
call oInstance1.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.RAC']/OperatingSystemName$", ValueMap.Item("OperatingSystemName"))
MOMDebugLog 1,"Add Operating System Version:" & ValueMap.Item("OperatingSystemVersion")
call oInstance1.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.RAC']/OperatingSystemVersion$", ValueMap.Item("OperatingSystemVersion"))
MOMDebugLog 1,"Add System Room Name:" & ValueMap.Item("SystemRoomName")
call oInstance1.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.RAC']/SystemRoomName$", ValueMap.Item("SystemRoomName"))
MOMDebugLog 1,"Add Blade Slot Number:" & ValueMap.Item("BladeSlotNumber")
call oInstance1.AddProperty("$MPElement[Name='DAD!Dell.RemoteAccess.RAC']/BladeSlotNumber$", ValueMap.Item("BladeSlotNumber"))
Set oRelationship = oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='DellRemoteAccessiDRAC8Modular.Contains.DelliDRAC8ModularNetworkDevice']$")
oRelationship.Source = oInstance1
oRelationship.Target = oInstance2
oDiscoveryData.AddInstance oRelationship
End Function