Dim objArgs, SourceID, ManagedEntityId, TargetComputer, ImagePath
Dim objMOMAPI, objWMIService, objDiscoveryData
Dim strObject, colobjHBAs, colobjPorts, colobjPortStats
Dim objHBA, objPort, objPortStats, objPortStatsDet
Dim arrOfInst(97)'2 * maxnoofadapters
Dim objAdapInst, objPortInst, objPortStatsInst
Dim bFoundInstance, Index, portWWN, nodeWWN,SystemEntity
bFoundInstance = True
Set objArgs = WScript.Arguments
If WScript.Arguments.Count > 0 Then
SourceId = objArgs(0)
ManagedEntityId = objArgs(1)
ImagePath = objArgs(2)
TargetComputer = objArgs(3)
End If
Set objMOMAPI = CreateObject("MOM.ScriptAPI")
Set objDiscoveryData = objMOMAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)
Set objWMIService = GetObject( "winmgmts:\\localhost\root\wmi" )
Set colobjHBAs = objWMIService.ExecQuery( "Select * From MSFC_FCAdapterHBAAttributes" )
If (colobjHBAs is Nothing) Then
bFoundInstance = False
End If
Index = 0
If (colobjHBAs.count > 0 And bFoundInstance) Then
For Each objHBA In colobjHBAs
Index = Index + 1
nodeWWN = WWNToString(objHBA.NodeWWN)'unique to this adapter port.
SystemEntity = objHBA.MfgDomain + "-" + objHBA.SerialNumber + "-" + objHBA.Model + "-" + CStr(Index)
If (Index > MAX_PHYSICALPORTS-1) Then
Call objMOMAPI.LogScriptEvent("DiscoverHBAs.vbs", 200, 1, "HBA Instances count exceeded limit.")
Exit For
End If
If (ChkStrExistsInArray(arrOfInst,objHBA.SerialNumber,Index) = false) Then 'SerialNumber is unique.
Set objAdapInst = objDiscoveryData.CreateClassInstance("$MPElement[Name='Brocade.FCHBA.Monitoring.HBA']$")
Call objAdapInst.AddProperty("$MPElement[Name='Brocade.FCHBA.Monitoring.Host']/ImagePath$", ImagePath)
Call objAdapInst.AddProperty ("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputer)
Call objAdapInst.AddProperty("$MPElement[Name='Brocade.FCHBA.Monitoring.HBA']/SerialNumber$", objHBA.SerialNumber)
Call objAdapInst.AddProperty("$MPElement[Name='Brocade.FCHBA.Monitoring.HBA']/InstanceName$", objHBA.InstanceName)
Call objAdapInst.AddProperty("$MPElement[Name='Brocade.FCHBA.Monitoring.HBA']/NodeWWN$", nodeWWN)
Call objAdapInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", SystemEntity)
Call objDiscoveryData.AddInstance(objAdapInst)
'Call objMOMAPI.LogScriptEvent("DiscoverHBAs.vbs", 200, 2, "one Adapter instance added")
End If
Next
End If
'Call objMOMAPI.LogScriptEvent("DiscoverHBAs.vbs", 200, 2, "Completed DiscoverHBAs.vbs.")
'Submit the discovery data for processing.
Call objMOMAPI.Return(objDiscoveryData)
WScript.Quit
'----------------------------End Of Main Fn---------------
'Converts WWN to StringWWN
Function WWNToString(arrayWWN)
Dim I
WWNToString = Hex0(arrayWWN(0))
For I = 1 To 7
WWNToString = WWNToString + ":" + Hex0(arrayWWN(I))
Next
End Function
'Returns the hexadecimal string value of input number(as two digits).
Function Hex0(n)
Hex0 = Hex(n)
If (n < &h10) Then Hex0 = "0" + Hex0
End Function
'If str exists then returns true
'If not exists then returns false and adds the string to the array
Function ChkStrExistsInArray(arrayOfStrs(),InputStr,LastItemIndex)
Dim I
ChkStrExistsInArray = False
For I = 0 To LastItemIndex
If (StrComp(LCase(arrayOfStrs(I)),LCase(InputStr)) = 0) Then
ChkStrExistsInArray = true
Exit For
End If
Next
If (ChkStrExistsInArray = False) Then
arrayOfStrs(LastItemIndex+1) = InputStr
End If
End Function </Script></ScriptBody>
<TimeoutSeconds>400</TimeoutSeconds>
</DataSource>
</Discovery>