Select Case WScript.Arguments(2)
Case "true","physical","1" : isPhysical = True
Case Else : isPhysical = False
End Select
Dim metricVal
metricVal = GetPerformanceMetric(metrictoquery, nicindex, isPhysical)
Dim oAPI, oBag
' 18446744073709551615 = ULONG_MAX
' This value is returned if the metric is not valid.
If metricVal <> "18446744073709551615" Then
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()
Call oBag.AddValue("NICPerfValue",Fix(metricVal))
Call oAPI.Return(oBag)
End If
Function GetPerformanceMetric(metricname, nicindex, isPhysical)
Dim OMSABinPath ' Store Path from Registry key
Dim drive ' Drive letter
Dim version, regError, rc
regError = 0
GetPerformanceMetric = "18446744073709551615"
' Get OMSA Lib Path
MOMDebugLog 1, "Getting Metric"
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 wintemp_path, nicPerfFilePath
Dim guid22, timer, oShell, strCommand, perfmetric
'On Error Resume Next
Const TIMEOUT = 20
GetTempFolderPath wintemp_path, drive
GetOMReportFileGUID guid22
nicPerfFilePath = wintemp_path & "\" & "nperf" & "-" & nicindex & "-" & guid22 & ".xml"
MOMDebugLog 1, "Logging to " & nicPerfFilePath
Dim teamconfig : teamconfig = ""
if Not isPhysical Then teamconfig = " config=team "
MOMDebugLog 1, "Teamconfig=" & teamconfig
strCommand = "cmd /C " & chr(34) & OMSABinPath & "\" & "omreport.exe" & Chr(34) & " chassis nics " & teamconfig & " index=" & nicindex & " -fmt xml -outc " & nicPerfFilePath
Set oShell = CreateObject ("WScript.Shell")
rc = oShell.run (strCommand, 0, true)
If rc <> 0 Then
DelFile(nicPerfFilePath)
Err.Clear
Else
' Infinite Loop Until file OM_REPORT_FILE_NAME is created
timer = 0
Do While bFileExists(nicPerfFilePath) <> -1
WScript.Sleep(1000)
timer = timer + 1
if (timer > TIMEOUT) Then
MOMDebugLog 1, "Exit RunCmd. Reason: OMREPORT CHASSIS NICS not responding"
Exit Do
End If
Loop
' Parse XML block
nicPerfFilePath = nicPerfFilePath
Dim xmlDoc, i, str
If (bFileExists(nicPerfFilePath)) Then
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
If (IsObject(xmlDoc) = True) Then
xmlDoc.async = "false"
xmlDoc.load(nicPerfFilePath)
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(nicPerfFilePath)
Exit Function
End If
Set perfmetric = xmlDoc.getElementsByTagName(metricname) 'get metric value
MOMDebugLog 1, "Retrieving Performance Metric:"
For i = 0 To (perfmetric.length - 1)
GetPerformanceMetric = perfmetric.Item(i).nodeTypedValue
MOMDebugLog 1, GetPerformanceMetric
Next
Else
logMessage = "Error: DOM object not created using CreateObject - Microsoft.XMLDOM"
MOMDebugLog 1, logMessage
End If
DelFile(nicPerfFilePath)
Else
logMessage = "NIC CLI XML Output File does not exist - " & nicPerfFilePath
MOMDebugLog 1, logMessage
End If
'end Parse XML block
' Clean up the CLI Output : Delete OM_REPORT_FILE_NAME for NICs
End If ' End of If Condition for rc<>0 for oshell.run(omreport storage controller)
Set nicPerfFilePath = 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
Dim objLogTextFile
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
Sub InitLogFile
If logLevel <> 0 Then
Dim fileSize, strOutFile
Dim wintemp_path, drive, guid44
GetOMReportFileGUID guid44
Dim strFileName: strFileName = "Perf_" & guid44 & ".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)
Dim objLogFSO: 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 Discovery : Start()"
MOMDebugLog 1, logMessage
MOMDebugLog 1, logMessage
Err.Clear
End If
End Sub </Script></ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
<EventPolicy>
<StdOutMatches/>
</EventPolicy>
<ObjectName>$Config/ObjectName$</ObjectName>
<CounterName>$Config/CounterName$</CounterName>
<InstanceName>$Config/InstanceName$</InstanceName>
<Value>$Data/Property[@Name='NICPerfValue']$</Value>
</DataSource>
</MemberModules>
<Composition>
<Node ID="NICPerformanceDS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>Performance!System.Performance.Data</OutputType>
</DataSourceModuleType>