'**********************************************************************************
' Script Name - Dell RBOD Discovery using IP Listing File
' Author: Vaideeswaran Ganesan, Sriram Venkatesh, Anirban Kundu
'
' Description:
' Discover all Dell RBOD Device using the IP Listing File
'
' (c) Copyright Dell Inc. 2014 - All rights reserved
'**********************************************************************************
Option Explicit
On Error Resume Next
SetLocale("en-us")
Const DebugScript = False
Function DebugOut(message)
If DebugScript Then WScript.Echo message
End Function
Dim FileSystemObject
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
Dim oArgs
Set oArgs = WScript.Arguments
if oArgs.Count < 6 Then
Wscript.Quit -1
End If
Dim SourceID, ManagedEntityId, TargetComputer, logLevel, apiVerCheck, ipCfgFilePath
Dim oAPI, oDiscoveryData, oInst, logMessage, index, objLogTextFile
Dim eventMessage
Dim RBOD_IP_ARR, UNIQUE_RBOD_IP_ARR, rbod_ip, hyphenIP
SourceId = oArgs(0)
ManagedEntityId = oArgs(1)
TargetComputer = oArgs(2)
logLevel=oArgs(3) + 0
apiVerCheck=oArgs(4)
ipCfgFilePath = ""
For index=5 to (oArgs.Count-1)
ipCfgFilePath = ipCfgFilePath & " " & oArgs(index)
Next
ipCfgFilePath = Trim(ipCfgFilePath)
'##################################################
Dim glb_registryEntryPresent
glb_registryEntryPresent = False
Function GetRegistryEntry (strRegistryKey )
Dim WSHShell
On Error Resume Next
Set WSHShell = CreateObject("WScript.Shell")
' Clear the global Err object so that we can capture error when registry entry not found
Err.clear
GetRegistryEntry = WSHShell.RegRead( strRegistryKey )
If Err.number <> 0 then
' This condition will be success only if registry entry itself is not present (Err gets populated when exception occurs).
' If registry entry is not found (can happen in case if suite is uninstalled, MDMP remains in SCOM), check the below boolean and generate Alert 300
glb_registryEntryPresent = False
Else
' No error during calling RegRead()
glb_registryEntryPresent = True
End If
Err.clear
'Clean up resources
set WSHShell = nothing
End Function
Function CreateABBOutputFolder
dim wsShell : Set wsShell = Createobject("WScript.Shell")
dim wshSysEnv : Set wshSysEnv = wsShell.Environment
dim tFolder : tFolder = wshSysEnv("TEMP")
dim abbOutputFolder : abbOutputFolder = "Dell_MDStorageArray_ABBOutput"
dim wshPrcEnv : Set wshPrcEnv = wsShell.Environment("Process")
tFolder = Replace(tFolder, "%SystemRoot%", wshPrcEnv("SYSTEMROOT"), 1, -1, vbTextCompare)
If Not FileSystemObject.FolderExists(tFolder) Then
FileSystemObject.CreateFolder(tFolder)
End If
If Not FileSystemObject.FolderExists(tFolder & "\" & abbOutputFolder) Then
FileSystemObject.CreateFolder(tFolder & "\" & abbOutputFolder)
End If
'Clean up resources
set wsShell = nothing
CreateABBOutputFolder = tFolder & "\" & abbOutputFolder
End Function
'##################################################
Dim ABB_OUTPUT_FOLDER_PATH
ABB_OUTPUT_FOLDER_PATH = CreateABBOutputFolder
Dim registryEntryPATHValue
registryEntryPATHValue = GetRegistryEntry("HKEY_LOCAL_MACHINE\Software\Dell\Dell MD Storage Array Management Pack Suite\Path")
'registryEntryPATHValue would point to C:\Program Files\Dell Management Packs\MDStorage Mgmt Suite\<version>\ in a typical default installation of MDMP<version> suite
Dim ABB_FOLDER_PATH
'Default ABB folder path is assigned as empty
ABB_FOLDER_PATH = ""
If(strcomp(registryEntryPATHValue,"") = 0) Then
'If registry entry present, but value is empty, we set glb_registryEntryPresent to FALSE
glb_registryEntryPresent = False
Else
glb_registryEntryPresent = True
ABB_FOLDER_PATH = registryEntryPATHValue & "Library"
End If
If ipCfgFilePath = "" Then
ipCfgFilePath = ABB_FOLDER_PATH & "\dell_MDStorageArray_ip.cfg"
End If
Set oAPI = CreateMOMScriptAPI
If CheckEnvironment Then
Set oDiscoveryData = CreateDiscoveryData
ParseRBOD_IPCfg()
ReturnDiscoveryData oDiscoveryData
End If
If logLevel <> 0 Then
objLogTextFile.Close
Set objLogTextFile = Nothing
End If
Function ParseRBOD_IPCfg()
' Function to parse the IPs from the user input cfg file
Dim a, objTextFile, strLine
a=0
Const ForReading = 1
DebugOut "Opening: " & ipCfgFilePath
Set objTextFile = FileSystemObject.OpenTextFile(ipCfgFilePath, ForReading)
Do Until objTextFile.AtEndOfStream
strLine = objTextFile.Readline
RBOD_IP_ARR = Split(strLine,";")
Loop
For Each rbod_ip In RBOD_IP_ARR
If(Instr(UNIQUE_RBOD_IP_ARR,rbod_ip)=0) Then
logMessage = "INFO : Discover RBOD IP: " & rbod_ip
MOMDebugLog 1, logMessage
UNIQUE_RBOD_IP_ARR = UNIQUE_RBOD_IP_ARR & "," & rbod_ip
hyphenIP = rbod_ip
If ( InStr(hyphenIP,".") > 0 ) Then
hyphenIP = Replace(hyphenIP,".","_")
End If
If ( InStr(hyphenIP,":") > 0 ) Then
hyphenIP = Replace(hyphenIP,":","_")
End If
set oInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Dell.Storage.MDStorageArray.RBODDeviceSeed']$")
call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputer)
call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.LogicalDevice']/DeviceID$", hyphenIP)
call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.LogicalDevice']/Name$", "MD Storage Array")
Call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.LogicalDevice']/Description$", "MD Array Seed Object")
call oInst.AddProperty("$MPElement[Name='Dell.Storage.MDStorageArray.RBODDeviceSeed']/monitorip$", rbod_ip)
call oInst.AddProperty("$MPElement[Name='Dell.Storage.MDStorageArray.RBODDeviceSeed']/APIVersionCheck$", apiVerCheck)
call oDiscoveryData.AddInstance(oInst)
End If
Next
End Function
'************** Functions list defns
Function CheckFileExists(sFileName)
If (FileSystemObject.FileExists(sFileName)) Then
CheckFileExists = True
Else
CheckFileExists = False
End If
End Function
Function CheckFolderExists(sFolderName)
If (FileSystemObject.FolderExists(sFolderName)) Then
CheckFolderExists = True
Else
CheckFolderExists = False
End If
End Function
Function GetVersion(sFilePathAndName)
Dim abbVersion
abbVersion = FileSystemObject.GetFileVersion(sFilePathAndName)
If Len(abbVersion) = 0 Then
MOMDebugLog 1, "INFO : No DellABB version information found, baselining the version to 4.0."
abbVersion = "4.0.0.0"
End If
GetVersion = abbVersion
End Function
Function IsDellABBCompatibleVersion(sABBVersion, mpVersion)
Dim eventMessage, arrABBVersion, arrMPVersion, iFirstArraySize, iSecondArraySize, i, minArraySize
If iFirstArraySize <= iSecondArraySize Then
minArraySize = iFirstArraySize
Else
minArraySize = iSecondArraySize
End If
If minArraySize >= 2 Then
For i=0 to minArraySize - 1
If CInt(arrABBVersion(i)) < CInt(arrMPVersion(i)) Then
eventMessage = "Lower version of DellABB.exe (" & sABBVersion & ") found. Expecting DellABB.exe (" & mpVersion & ")."
MOMDebugLog 1, "INFO : IsDellABBCompatibleVersion = False, " & eventMessage
LogSCOMEvent eventMessage, 298, 1
IsDellABBCompatibleVersion = False
Exit Function
ElseIf CInt(arrABBVersion(i)) > CInt(arrMPVersion(i)) Then
eventMessage = "Higher version of DellABB.exe (" & sABBVersion & ") found. Expecting DellABB.exe (" & mpVersion & ")."
MOMDebugLog 1, "INFO : IsDellABBCompatibleVersion = False, " & eventMessage
LogSCOMEvent eventMessage, 298, 1
IsDellABBCompatibleVersion = False
Exit Function
End If
Next
eventMessage = "DellABB version matches correctly with the Management Pack version."
MOMDebugLog 1, "INFO : IsDellABBCompatibleVersion = True, " & eventMessage
IsDellABBCompatibleVersion = True
Exit Function
End If
eventMessage = "Wrong version information retrieved from DellABB.exe."
MOMDebugLog 1, "INFO : IsDellABBCompatibleVersion = False, " & eventMessage
IsDellABBCompatibleVersion = False
End Function
Function CreateLog
' Begin Logheader
If logLevel <> 0 Then
Dim fileSize, strOutFile, newFilename, dateStr, datesuffix, timesuffix, subStrLoc
Const strFileName = "Discovery_DellMDStorageArray.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 mdmpFolder : mdmpFolder = "Dell_MDStorageArray_ManagementPack_Logs"
dim wshPrcEnv : Set wshPrcEnv = wsShell.Environment("Process")
tFolder = Replace(tFolder, "%SystemRoot%", wshPrcEnv("SYSTEMROOT"), 1, -1, vbTextCompare)
If Not FileSystemObject.FolderExists(tFolder) Then
FileSystemObject.CreateFolder(tFolder)
End If
If Not FileSystemObject.FolderExists(tFolder & "\" & mdmpFolder) Then
FileSystemObject.CreateFolder(tFolder & "\" & mdmpFolder)
End If
strOutFile = tFolder & "\"& mdmpFolder & "\" & 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 (debugLevel > 0) and (debugLevel <= logLevel) Then
objLogTextFile.WriteLine(Now() & " ---- " & Message)
Err.Clear
End If
End Sub
' End of Logheader
'**************
Function CheckEnvironment
CheckEnvironment = False
If glb_registryEntryPresent = False Then
' add event to eventlog on ABB Toolset path not present
eventMessage = "ABB Toolset Folder not found on the OpsMgr Management Server. Please install/repair the Dell MD Storage Array Management Pack Suite 6.1 to get the ABB Toolset and to monitor the MD Storage Arrays using Dell MD Storage Array Management Pack 6.1."
LogSCOMEvent eventMessage, 300, 2
Exit Function
End If
If Not CheckFolderExists (ABB_FOLDER_PATH) Then
' add event to eventlog on ABB Toolset path not present
eventMessage = "ABB Toolset Folder not found on the OpsMgr Management Server. Please install/repair the Dell MD Storage Array Management Pack Suite 6.1 to get the ABB Toolset and to monitor the MD Storage Arrays using Dell MD Storage Array Management Pack 6.1."
LogSCOMEvent eventMessage, 300, 2
Exit Function
End If
If Not FileSystemObject.FolderExists(ABB_OUTPUT_FOLDER_PATH & "\TMP") Then
FileSystemObject.CreateFolder(ABB_OUTPUT_FOLDER_PATH & "\TMP")
DebugOut "Creating Folder :" & ABB_OUTPUT_FOLDER_PATH & "\TMP"
End If
If Not FileSystemObject.FolderExists(ABB_OUTPUT_FOLDER_PATH & "\data") Then
FileSystemObject.CreateFolder(ABB_OUTPUT_FOLDER_PATH & "\data")
DebugOut "Creating Folder :" & ABB_OUTPUT_FOLDER_PATH & "\data"
End If
' add event to eventlog in case if the ipcfg file, abb cfg file or abb.exe is missing
eventMessage = ""
dim comma : comma = ""
If Not CheckFileExists(ABB_FOLDER_PATH & ABB_EXE_NAME) Then
eventMessage = eventMessage & comma & ABB_FOLDER_PATH & ABB_EXE_NAME
comma = ", "
End If
If Not CheckFileExists(ABB_FOLDER_PATH & ABB_CFG_NAME) Then
eventMessage = eventMessage & comma & ABB_FOLDER_PATH & ABB_CFG_NAME
comma = ", "
End If
If Not CheckFileExists(ipCfgFilePath) Then
eventMessage = eventMessage & comma & ipCfgFilePath
End If
If Len(eventMessage) > 1 Then
eventMessage = "File(s): " & eventMessage & " not found on the OpsMgr Management Server. Please install/repair the Dell MD Storage Array Management Pack Suite 6.1 to get the ABB Toolset. Ensure the IP listing file (dell_MDStorageArray_ip.cfg (or overridden path setting)) is present in the installed library folder (ABB Toolset folder) or in the overridden IP Config file path location."
LogSCOMEvent eventMessage, 300, 2
Exit Function
End If
logMessage = "INFO : ABB executable and config file exists on Management Server"
MOMDebugLog 1, logMessage
logMessage = "INFO : IP Config File Path : " & ipCfgFilePath
MOMDebugLog 1, logMessage
If Not IsDellABBCompatibleVersion(GetVersion(ABB_FOLDER_PATH & ABB_EXE_NAME), "6.1.0.0") Then
' IMPORTANT: We dont stop the discovery process here but rather continue to discover and monitor using the non-compatible dellabb.exe(lower version or higher version).
' The user will hence experience some missing attributes/added attributes/added components, but the MP code is made to be both backward and forward compatible with dellabb.exe
' Generate the event to eventlog on ABB not compatible
' Return true to start discovery using the non-compatible dellabb.exe
logMessage = "INFO : DellABB is not compatible with management pack. Still proceeding with the Discovery"
MOMDebugLog 1, logMessage
End If
CheckEnvironment = True
End Function
'********** SCOM Functions
Function CreateMOMScriptAPI
If DebugScript = False Then
Set CreateMOMScriptAPI = CreateObject("MOM.ScriptAPI")
Else
DebugOut "Creating MOM Script API"
Set CreateMOMScriptAPI = New RegExp
End If
End Function
Function CreateDiscoveryData
If DebugScript = False Then
set CreateDiscoveryData = oAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)
Else
DebugOut "Creating instance of Discovery Data"
Set CreateDiscoveryData = New RegExp
End If
End Function
Function ReturnDiscoveryData (oDiscoveryData)
If DebugScript = False Then
Call oAPI.Return(oDiscoveryData)
Else
DebugOut "Returning Discovery Data"
End If
End Function
Function LogSCOMEvent(eventMessage, alertNum, alertLevel)
If DebugScript = False Then
Call oAPI.LogScriptEvent("RBODABBDiscover.vbs",alertNum,alertLevel,eventMessage)
Call oAPI.Return(oDiscoveryData)
End If
logMessage = "Generate EVENT: " & eventMessage
MOMDebugLog 1, logMessage
End Function
Sub oInst_AddProperty(prop, value)
DebugOut prop & " = " & value
End Sub </Script></ScriptBody>
<TimeoutSeconds>1200</TimeoutSeconds>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>