Sonda stanu portów karty HBA
Microsoft.SystemCenter.VirtualMachineManager.Storage.2016.HBA.PortState.Probe (ProbeActionModuleType)
Dostawca sondy stanów portów kart HBA magazynu
Knowledge Base article: Element properties: Member Modules:
Overrideable Parameters:
Source Code: <ProbeActionModuleType ID="Microsoft.SystemCenter.VirtualMachineManager.Storage.2016.HBA.PortState.Probe" Accessibility="Internal">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" maxOccurs="1" name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" maxOccurs="1" name="PortTypeFilter" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="0" maxOccurs="1" name="DefaultPortCountPerAdapter" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
<OverrideableParameter ID="PortTypeFilter" Selector="$Config/PortTypeFilter$" ParameterType="string"/>
<OverrideableParameter ID="DefaultPortCountPerAdapter" Selector="$Config/DefaultPortCountPerAdapter$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation>
<Composite>
<MemberModules>
<ProbeAction ID="PassThrough" TypeID="System!System.PassThroughProbe"/>
<ProbeAction ID="PS" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagProbe">
<ScriptName>StorageHBAPortState.DS.ps1</ScriptName>
<ScriptBody><Script> param( [String] $PortTypeFilter, [Int] $DefaultPortCountPerAdapter)
# Creates sets of property bag data wit Adapter State based on Port Status foreach HBA
# Script parameters
# - $PortTypeFilter - Filter to apply to Port Type
$SCRIPT_NAME = "StorageHBAPortState.DS.ps1"
$ErrorActionPreference = "Stop"
# Event type constants
$EVENT_TYPE_LOG = 0
$EVENT_TYPE_ERROR = 1
$EVENT_TYPE_WARNING = 2
$EVENT_TYPE_INFORMATION = 4
# Typed property bag constants
$PROPERTY_TYPE_ALERT = 0
$PROPERTY_TYPE_EVENT = 1
$PROPERTY_TYPE_PERFORMANCE = 2
$PROPERTY_TYPE_STATE = 3
#Port States Constans
$HBA_PORTSTATE_UNKNOWN = 1
$HBA_PORTSTATE_ONLINE = 2
$HBA_PORTSTATE_OFFLINE = 3
$HBA_PORTSTATE_BYPASSED = 4
$HBA_PORTSTATE_DIAGNOSTICS = 5
$HBA_PORTSTATE_LINKDOWN = 6
$HBA_PORTSTATE_ERROR = 7
$HBA_PORTSTATE_LOOPBACK = 8
#Status Codes Constans
$Status_ONLINE = 1
$Status_PARCIALLYOFFLINE = 2
$Status_TOTALOFFLINE = 3
#Status Descriptions Constans
$Status_ONLINE_DESC = "Online"
$Status_PARCIALLYOFFLINE_DESC = "Partially Offline"
$Status_TOTALOFFLINE_DESC = "Totally Offline"
# State type constants
$STATE_SUCCESS = "Success"
$STATE_WARNING = "Warning"
$STATE_ERROR = "Error"
# Port Type Filter Constants
$Filter_AllPortTypes = "*"
# Create MOM API object
$momAPI = new-object -comObject MOM.ScriptAPI
Write-Host "$SCRIPT_NAME - Starting Execution HBA Port State Monitoring Powershell Script"
$PortIndex = 0
$adaptersColl = Get-WmiObject -namespace "root\wmi" -Class MS_SM_AdapterInformationQuery
if($adaptersColl -ne $null)
{
foreach ($AdapterInfo in $adaptersColl)
{
$OffLinePortsList = @()
$OffLinePortText = ""
$InstanceName = $AdapterInfo.InstanceName
$UniqueAdapterId = $AdapterInfo.UniqueAdapterId
$PortCount = $AdapterInfo.NumberOfPorts
$PortAdapterStatusDesc = ""
$portInfoMethods = Get-WmiObject MS_SM_PortInformationMethods -Namespace "root\wmi" | where {$_.InstanceName -eq $InstanceName}
if($portInfoMethods -ne $null)
{
for ($PortIndex=0; $PortIndex -lt $DefaultPortCountPerAdapter; $PortIndex++)
{
$adapterPorts = $portInfoMethods.SM_GetAdapterPortAttributes($PortIndex,30) | Where-Object {$_.HBAStatus -eq $HBA_PORTSTATE_LINKDOWN}
if($adapterPorts -eq $null)
{
$adapterPorts = $portInfoMethods.SM_GetAdapterPortAttributes($PortIndex,30) | Where-Object {$_.HBAStatus -ne $HBA_PORTSTATE_LINKDOWN}
}
$PortType = $adapterPorts.PortAttributes.PortType
$HBAStatus = $adapterPorts.HBAStatus
if($HBAStatus -eq $HBA_PORTSTATE_LINKDOWN)
{
$PortStateVal = $HBA_PORTSTATE_LINKDOWN
}
else
{
$PortStateVal = $adapterPorts.PortAttributes.PortState
}
$PortDesc = "Port#" + $PortIndex
$CheckState = $false
if($PortTypeFilter -eq $Filter_AllPortTypes)
{
$CheckState = $true
}
else
{
if($PortType -eq $PortTypeFilter)
{
$CheckState = $true
}
else
{
$CheckState = $false
}
}
if($CheckState -eq $true)
{
if(($PortStateVal -eq $HBA_PORTSTATE_OFFLINE) -or ($PortStateVal -eq $HBA_PORTSTATE_LINKDOWN) -or ($PortStateVal -eq $HBA_PORTSTATE_ERROR))
{
$OffLinePortsList += $PortDesc
$OffLinePortText += $PortDesc + ","
}
}
}
}
if($OffLinePortsList.Length -eq $DefaultPortCountPerAdapter)
{
$PortAdapterStatusDesc = $Status_TOTALOFFLINE_DESC
$PortAdapterStatusCode = $Status_TOTALOFFLINE
}
else
{
if($OffLinePortsList.Length -gt 0 -and $OffLinePortsList.Length -lt $DefaultPortCountPerAdapter)
{
$PortAdapterStatusDesc = $Status_PARCIALLYOFFLINE_DESC
$PortAdapterStatusCode = $Status_PARCIALLYOFFLINE
}
else
{
$PortAdapterStatusDesc = $Status_ONLINE_DESC
$PortAdapterStatusCode = $Status_ONLINE
}
}
$ArrCount = $OffLinePortsList.Length.ToString()
#Add PropertyBag
$AdapterPropertyBag = $momAPI.CreatePropertyBag()
$AdapterPropertyBag.AddValue("DeviceID", $UniqueAdapterId)
$AdapterPropertyBag.AddValue("HBAInstanceName", $InstanceName)
$AdapterPropertyBag.AddValue("PortsOffLineCount", $ArrCount)
$AdapterPropertyBag.AddValue("TotalPorts", $PortCount)
$AdapterPropertyBag.AddValue("DefaultPortCountPerAdapter", $DefaultPortCountPerAdapter)
$AdapterPropertyBag.AddValue("ListPortsOffLine", $OffLinePortText)
$AdapterPropertyBag.AddValue("HBAStatus", $HBAStatus)
$AdapterPropertyBag.AddValue("StatusCode", $PortAdapterStatusCode)
$AdapterPropertyBag.AddValue("StatusDesc", $PortAdapterStatusDesc)
$AdapterPropertyBag
}
}
Write-Host "$SCRIPT_NAME - Complete Execution HBA Port State Monitoring Powershell Script"
</Script> </ScriptBody>
<Parameters>
<Parameter>
<Name>PortTypeFilter</Name>
<Value>$Config/PortTypeFilter$</Value>
</Parameter>
<Parameter>
<Name>DefaultPortCountPerAdapter</Name>
<Value>$Config/DefaultPortCountPerAdapter$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<StrictErrorHandling>true</StrictErrorHandling>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="PS">
<Node ID="PassThrough"/>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
<TriggerOnly>true</TriggerOnly>
</ProbeActionModuleType>