'**********************************************************************************
' Script Name - Dell Server NIC Unit Component Discovery
' Author: Vaideeswaran Ganesan
'
' Description:
' Creates the link between the Physical and Teamed NICs.
' (c) Copyright © 2009– 2017 Dell Inc, or its subsidiaries. All Rights Reserved
'**********************************************************************************
' Target against TeamedEnrichedNetworkInterfaceUnits only.
' Assumption: OMVersion is >= 6.2.0.1.
'*********************************
' MAIN begin
'*********************************
Option Explicit
On Error Resume Next
SetLocale("en-us")
Dim oArgs
Set oArgs = WScript.Arguments
If oArgs.Count < 6 Then
Wscript.Quit -1
End If
Dim sourceId, managedEntityId, targetComputer, selectedTeamName
Dim nicFlag, virnicFlag, teamNicIndex
Dim logLevel, objLogTextFile, objLogFSO, logMessage, enableTeaming
' Begin Logheader
If logLevel <> 0 Then
Dim fileSize, strOutFile
Const strFileName = "DellDiscoverNICLinks.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
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
Set objLogTextFile = objLogFSO.OpentextFile(strOutFile, ForWriting, True)
Else
Set objLogTextFile = objLogFSO.OpentextFile(strOutFile, ForAppending, True)
End If
logMessage = "------------------------------------------------------"
MOMDebugLog 1, logMessage
logMessage = "INFO: Script - Dell Server NIC Physical-Teamed Link Discovery : Start()"
MOMDebugLog 1, logMessage
Err.Clear
End If
Sub MOMDebugLog (ByVal debugLevel, ByVal Message)
On Error Resume Next
If (debugLevel > 0) and (debugLevel <= logLevel) Then
objLogTextFile.WriteLine(Now() & " ---- " & Message)
Err.Clear
End If
End Sub
' End of Logheader
Dim oAPI, oDiscoveryData, oInst, strComputer, objDellConnection, omVer
Set oAPI = CreateObject("MOM.ScriptAPI")
set oDiscoveryData = oAPI.CreateDiscoveryData(0, sourceId, managedEntityId)
If enableTeaming = True Or LCase(enableTeaming) = "true" Then
logMessage = "INFO: enable Physical/Teamed NIC Correlation is " & enableTeaming
MOMDebugLog 1, logMessage
logMessage = "INFO: Creating Links for " & selectedTeamName
MOMDebugLog 1, logMessage
EnrichedPhysicalTeamedLinkDiscovery
Else
logMessage = "INFO: enable Physical/Teamed is " & enableTeaming
MOMDebugLog 1, logMessage
End If
Call oAPI.Return(oDiscoveryData)
Set oDiscoveryData = Nothing
Set oAPI = Nothing
logMessage = "INFO: Script - Dell Server NIC Physical-Teamed Link Discovery : end()"
MOMDebugLog 1, logMessage
logMessage = "------------------------------------------------------"
MOMDebugLog 1, logMessage
' Close file used for logs
If logLevel <> 0 Then
objLogTextFile.Close
Set objLogTextFile = Nothing
Set objLogFSO = Nothing
End If
' **********************************************
' End Main
' **********************************************
'*************************************************************************
' Function : EnrichedPhysicalTeamedLinkDiscovery()
' Desc : To return Physical & Teamed Links using OMSA 6.2.0.1+
' Arguments : None
'*************************************************************************
Function EnrichedPhysicalTeamedLinkDiscovery()
On Error Resume Next
Dim OMSABinPath ' Store Path from Registry key
Dim drive ' Drive letter
Dim version, regError, rc
regError = 0
' Get OMSA Lib Path
rc = GetOMABinPath(OMSABinPath, regError)
If rc <> 0 Then
logMessage = "GetOMSAHealth:GetOMABinPath Error"
MOMDebugLog 1, logMessage
Err.Clear
WScript.Quit()
End If
' Get Install root path
rc = GetOMInstallRoot(drive, OMSABinPath) ' return the current absolute path or the root path for the OMSA Install
If rc <> 0 Then
logMessage = "GetOMSAHealth:GetOMInstallRoot Error"
MOMDebugLog 1, logMessage
Err.Clear
WScript.Quit()
End If
If regError = 1 Then
logMessage = "Task Fail: OMSA not installed / OMSA Registry Value not found."
MOMDebugLog 1, logMessage
Err.Clear
WScript.Quit()
End If
Dim guid1, wintemp_path, nicFilePath
GetTempFolderPath wintemp_path, drive
GetOMReportFileGUID guid1
On Error Resume Next
Dim guid22, timer, oShell, strCommand
Const TIMEOUT = 20
GetOMReportFileGUID guid22
nicFilePath = wintemp_path & "\" & "niclink" & guid22 & ".xml"
strCommand = "cmd /C " & chr(34) & OMSABinPath & "\" & "omreport.exe" & Chr(34) & " chassis nics config=team index=" & teamNicIndex & " -fmt xml -outc " & nicFilePath
Set oShell = CreateObject ("WScript.Shell")
rc = oShell.run (strCommand,0,true)
If rc <> 0 Then
DelFile(nicFilePath)
Err.Clear
Exit Function
End If
' Infinite Loop Until file OM_REPORT_FILE_NAME is created
timer = 0
Do While bFileExists(nicFilePath) <> -1
WScript.Sleep(1000)
timer = timer + 1
if (timer > TIMEOUT) Then
MOMDebugLog "Exit RunCmd. Reason: OMREPORT CHASSIS NICS not responding"
Exit Do
End If
Loop
If Not bFileExists(nicFilePath) Then
logMessage = "NIC CLI XML Output File does not exist - " & nicFilePath
MOMDebugLog 1, logMessage
End If
' Parse XML block
Dim xmlDoc, i, str
Dim interfaceDesc, interfaceDescVal, nicStatus, nicStatusVal
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
If (IsObject(xmlDoc) = True) Then
xmlDoc.async = "false"
xmlDoc.load(nicFilePath)
If (xmlDoc.parseError.errorCode <> 0) Then
Dim myErr
Set myErr = xmlDoc.parseError
logMessage = "XML Parse Error Reason: " & myErr.reason
MOMDebugLog 1, logMessage
logMessage = "XML Parse Error Line: " & myErr.line
MOMDebugLog 1, logMessage
logMessage = "XML Parse Error Character: " & myErr.linepos
MOMDebugLog 1, logMessage
logMessage = "XML Parse Error Text: " & myErr.srcText
MOMDebugLog 1, logMessage
DelFile(nicFilePath)
Exit Function
End If
Else
DelFile(nicFilePath)
logMessage = "Error: DOM object not created using CreateObject - Microsoft.XMLDOM"
MOMDebugLog 1, logMessage
End IF
Dim teamedNic, teamName
Set teamedNic = xmlDoc.SelectSingleNode("//VirNicObj")
MOMDebugLog 1, "Obtained team Nic Details."
teamName = ""
If (Not (teamedNic is Nothing)) Then
If (Not (teamedNic.SelectSingleNode("IfDescription") is Nothing)) Then
teamName = teamedNic.SelectSingleNode("IfDescription").nodeTypedValue
MOMDebugLog 1, "Team Name : " & teamName
End If
End If
Dim oRelationship, oInst1
Dim teamMemberList, teamMember
Set teamMemberList = xmlDoc.getElementsByTagName("teamMemberList")
MOMDebugLog 1, "Number of Team Members : " & teamMemberList.length
If ((teamName = selectedTeamName) And (Not (teamMemberList Is Nothing))) Then
For i = 0 To (teamMemberList.length - 1)
Set teamMember = teamMemberList(i)
Set interfaceDesc = teamMember.SelectSingleNode("IfDescription") 'Collecting the Interface Description for every Team Member
Set nicStatus = teamMember.SelectSingleNode("nicStatus") 'Collecting the Nic Status for every Team Member
If interfaceDesc Is Nothing Then
interfaceDescVal = ""
Else
interfaceDescVal = interfaceDesc.nodeTypedValue
End If
If nicStatus Is Nothing Then
nicStatusVal = "Not Available"
Else
nicStatusVal = nicStatus.nodeTypedValue
End If
logMessage = interfaceDescVal & "," & " selected=" & selectedTeamName & ", status=" & nicStatusVal
MOMDebugLog 1, logMessage
If nicStatusVal = "4" Then
logMessage = interfaceDescVal & " is disabled. Will not be monitored"
MOMDebugLog 1, logMessage
ElseIf teamName <> interfaceDescVal Then
set oRelationship = oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='Dell.WindowsServer.EnrichedPhysicalNIC.References.EnrichedTeamedNICUnit']$")
MOMDebugLog 1, "Linking: physical(" & interfaceDescVal & ") with Team(" & teamName & ")"
set oInst1 = oDiscoveryData.CreateClassInstance("$MPElement[Name='Dell.WindowsServer.EnrichedNetworkInterfaceUnit']$")
call oInst1.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputer)
call oInst1.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.LogicalDevice']/DeviceID$", TargetComputer)
call oInst1.AddProperty("$MPElement[Name='Dell.WindowsServer.EnrichedNetworkInterfaceUnit']/NetConnectionID$", interfaceDescVal)
call oDiscoveryData.AddInstance(oInst1)
oRelationship.Source = oInst1
oRelationship.Target = oInst
call oDiscoveryData.AddInstance(oRelationship)
End If
Next
Else
logMessage = "Either the TeamMemberList Tag is empty or Team Name does not match"
MOMDebugLog 1, logMessage
End If
' Clean up the CLI Output : Delete OM_REPORT_FILE_NAME for NICs
DelFile(nicFilePath)
Set nicFilePath = Nothing
Set strCommand = Nothing
Set oShell = Nothing
End Function
'*****************************************************************
'GetOMABinPath
'Routine to read the registry to query the OMA Install Path
'*****************************************************************
Function GetOMABinPath(o_sPath, ByRef regError)
On Error Resume Next
Dim strOMAKey
Dim oShell, tmp
Set oShell = CreateObject ("WScript.Shell")
o_sPath = ""
o_sPath = oShell.RegRead(OMSA_REG_INTALL_PATH)
If o_sPath = "" Then
o_sPath = oShell.RegRead(OMSA64_REG_INTALL_PATH)
End If
If o_sPath = "" Then
tmp = DEF_OMSA_BIN_PATH & "\omreport.exe"
If(bFileExists(tmp)) Then
o_sPath = DEF_OMSA_BIN_PATH
logMessage = "GetOMABinPath - OMSABinPath is empty, Using Default Existing Path" & DEF_OMSA_BIN_PATH
MOMDebugLog 1, logMessage
Else
regError = 1
End If
Else
o_sPath = o_sPath & "\bin"
End If
If Err <> 0 Then
GetOMSABinPath = Err.Number
Err.Clear
End If
End Function
'*****************************************************************
'GetOMInstallRoot
'Routine to determine the Drive letter where OMSA is installed
'*****************************************************************
Private Function GetOMInstallRoot(ByRef path, ByVal OMSAInstallPath)
On Error Resume Next
' Return the root drive of the OMInstall Path
path = Left(OMSAInstallPath, 2)
End Function
'*****************************************************************
'bFileExists
'Routine to determine if the OMSA Report file is created
'*****************************************************************
Function bFileExists(ByVal filespec1)
On Error Resume Next
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
bFileExists = (fso.FileExists(filespec1))
Set fso = Nothing
End Function
'*****************************************************************
'DelFile
'Routine to delete the OMSA Report file
'*****************************************************************
Function DelFile(ByVal filespec2)
On Error Resume Next
Dim fso, oFile
If bFileExists(filespec2) Then
Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFile filespec2, True
Set fso = Nothing
End If
If Err <> 0 Then
DelFile = Err.Number
Err.Clear
End If
End Function
'*****************************************************************
'GetTempFolderPath
'Routine to Get Win Temp Folder path
'*****************************************************************
Function GetTempFolderPath(ByRef WinTempFolder, ByVal drive_letter)
On Error Resume Next
Dim FldrExistFlag, fso
FldrExistFlag = False
dim wshShell : Set wshShell = Createobject("WScript.Shell")
dim wshSysEnv : Set wshSysEnv = wshShell.Environment
dim strSysTempFolder : strSysTempFolder = wshSysEnv("TEMP")
dim wshPrcEnv : Set wshPrcEnv = wshShell.Environment("Process")
strSysTempFolder = Replace(strSysTempFolder, "%SystemRoot%", wshPrcEnv("SYSTEMROOT"), 1, -1, vbTextCompare)
WinTempFolder = strSysTempFolder
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FolderExists(WinTempFolder)) Then
FldrExistFlag = True
Else
FldrExistFlag = False
End If
If WinTempFolder = "" OR FldrExistFlag = False Then
WinTempFolder = drive_letter
End If
Set wshShell = Nothing
Set wshSysEnv = Nothing
Set strSysTempFolder = Nothing
Set wshPrcEnv = Nothing
If Err <> 0 Then
GetTempFolderPath = Err.Number
Err.Clear
End If
End Function
'*****************************************************************
'GetOMReportFileGUID
'Routine to generate unique GUIDs for OMREPORT FILE
'*****************************************************************
Function GetOMReportFileGUID(ByRef o_guid)
On Error Resume Next
Dim TypeLib, NewGUID
Set TypeLib = CreateObject("Scriptlet.TypeLib")
NewGUID = TypeLib.Guid
o_guid = (left(NewGUID, len(NewGUID)-2))
Set TypeLib = Nothing
End Function
'**********************************************************
' CheckVBScriptEngine()
' Check VBScript engine version:
'**********************************************************
Function CheckVBScriptEngine()
On Error Resume Next
Dim bIsCompatV, var
Const VBSCRIPT_MIN_VERSION = 56
var = ((ScriptEngineMajorVersion * 10) + ScriptEngineMinorVersion)
If ((var) < VBSCRIPT_MIN_VERSION) Then
bIsCompatV = False
Else
bIsCompatV = True
End If
If Err <> 0 Then
CheckVBScriptEngine = Err.Number
Err.Clear
Else
CheckVBScriptEngine = bIsCompatV
End If
End Function