PureStorage.FlashArray.TimedScript.PowerShell.PortMonitor.ProbeActionModuleType (ProbeActionModuleType)

Element properties:

TypeProbeActionModuleType
IsolationOwnProcess
AccessibilityInternal
RunAsDefault
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
Probe ProbeAction Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe Default

Overrideable Parameters:

IDParameterTypeSelector
TimeoutSecondsint$Config/TimeoutSeconds$
LogToArraybool$Config/LogToArray$

Source Code:

<ProbeActionModuleType ID="PureStorage.FlashArray.TimedScript.PowerShell.PortMonitor.ProbeActionModuleType" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" type="xsd:integer" name="TimeoutSeconds"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" type="xsd:boolean" name="LogToArray" minOccurs="0" maxOccurs="1"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
<OverrideableParameter ID="LogToArray" Selector="$Config/LogToArray$" ParameterType="bool" Comment="Enable/Disable additional detailed logging to the array"/>
</OverrideableParameters>
<ModuleImplementation Isolation="OwnProcess">
<Composite>
<MemberModules>
<ProbeAction ID="Probe" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe">
<ScriptName>PortHealthMonitor.ps1</ScriptName>
<ScriptBody><Script>param($Endpoint, $Username, $Password, $LogToArray)


function PortExits ($ports, $name) {
return ($ports | Where {$_.name -eq $name}) -ne $null
}

function GetPortInformation ($FlashArray, $name) {
$portInformation = @{}
$ports = Get-PfaArrayPorts -Array $FlashArray
$ports | foreach {
$portInformation[$_.name] = @{name=$_.name; enabled=$true}
}
$networkInterfaces = Get-PfaNetworkInterfaces -Array $FlashArray
$networkInterfaces | Where {($_.services.Contains("iscsi")) -or ($_.services.Contains("nvme-roc"))} | foreach {
if (-not (PortExits -ports $ports -name $_.name)) {
$portInformation[$_.name.ToUpper()] = @{name=$_.name.ToUpper() ; enabled=$false}
}
}

$hwAttributes = Get-PfaAllHardwareAttributes -Array $FlashArray
$portInformation.Keys | foreach {
$name = $_
$hwPort = $hwAttributes | Where {$_.name -eq $name}
$portInformation[$_]["speed"] = $hwPort.speed
$portInformation[$_]["status"] = $hwPort.status
$portInformation[$_]["connected"] = (($hwPort.speed -gt 0) -and ("ok" -eq $hwPort.status)) -or ("ok" -ne $hwPort.status)
}

return $portInformation.Values
}

function PortHealthMonitor {
# Import the SCOM PowerShell module
$ScriptName = "PortHealthMonitor.ps1"
LoadOperationsManagerModule $ScriptName
$disableLoggingToArray = -not $LogToArray

# Gather script start time
$StartTime = Get-Date
# Gather who the script is running as
$WhoAmI = whoami
# Load MomScript API
$momapi = new-object -comObject 'MOM.ScriptAPI'
# Log script event that we are starting task
Log $ScriptName $GLOBAL:INFO_LEVEL "Starting script"
LoadPowerShellSDK $ScriptName

# Convert password to secure string
$Password = $Password | ConvertTo-SecureString -AsPlainText -Force

# Check if array can be accessed
try {
$IgnoreCertErrors = GetIgnoreCertErrors $true
$FlashArray = New-PfaArray -EndPoint $Endpoint -UserName $Username -Password $Password -ClientName $GLOBAL:clientName -ClientVersion $GLOBAL:mpVersion -IgnoreCertificateError:$IgnoreCertErrors -HttpTimeOutInMilliSeconds 60000 -DisableLoggingToArray:$disableLoggingToArray
} catch {
$FlashArray = $null
Log $ScriptName $GLOBAL:ERROR_LEVEL "Connection to FlashArray $Endpoint failure."
}

$portData = @{}
$ports = Get-PfaArrayPorts -Array $FlashArray
foreach ($port in $ports) {

}

$warningStates = "degraded", "failing", "identifying", "unrecognized", "evacuated", "evacuating", "updating"

$portInformation = GetPortInformation -FlashArray $FlashArray
foreach ($portInfo in $portInformation) {
$name = $portInfo["name"]
$speed = $portInfo["speed"]
$status = $portInfo["status"]
$enabled = $portInfo["enabled"]
$connected = $portInfo["connected"]
$Result = "GoodCondition"

if (($false -eq $enabled) -or ($false -eq $connected)) {
$Result = "DisabledOrDisconnected"
Log $ScriptName $GLOBAL:WARNING_LEVEL "$Endpoint $name Disabled or disconnected port Found (status: $status, speed: $speed)"
}
elseif (("ok" -eq $status -and $speed -gt 0) -or ("recovering" -eq $status)) {
$Result = "GoodCondition"
Log $ScriptName $GLOBAL:VERBOSE_LEVEL "$Endpoint $Port Good Condition Found (status: $status, speed: $speed, address: $address)"
}
elseif ($warningStates -contains $status) {
$Result = "WarnCondition"
Log $ScriptName $GLOBAL:WARNING_LEVEL "$Endpoint $name Warn Condition Found (status: $status, speed: $speed, address: $address)"
}
else {
$Result = "BadCondition"
Log $ScriptName $GLOBAL:ERROR_LEVEL "$Endpoint $Port Error Condition Found (status: $status, speed: $speed, address: $address)"
}
# Create property bag for every port
$bag = $momapi.CreatePropertyBag()
$bag.AddValue('PortName', $name)
$bag.AddValue('Result', $Result)
$bag
}

Disconnect-PfaArray -Array $FlashArray

#Log an event for script ending and total execution time.
$EndTime = Get-Date
$ScriptTime = ($EndTime - $StartTime).TotalSeconds
Log $ScriptName $GLOBAL:INFO_LEVEL "Script has completed at $Endpoint. Runtime was ($ScriptTime) seconds."
}function SetLogLevel ($LogLevel){
Write-Host "Setting LogLevel to $LogLevel"
if ($LogLevel -ge 1 -and $LogLevel -le 4){
New-Item -Path HKLM:\SOFTWARE\PureStorage\SCOM -Name LogLevel -Force
Set-Item -Path HKLM:\SOFTWARE\PureStorage\SCOM\LogLevel -Value $LogLevel
$GLOBAL:CURRENT_LOG_LEVEL = $LogLevel
}
}

function GetLogLevel ($default){
if (Test-Path HKLM:\SOFTWARE\PureStorage\SCOM\LogLevel){
$item = Get-ItemProperty "HKLM:\SOFTWARE\PureStorage\SCOM\LogLevel"
$log_level = $item.'(default)'
$log_level
}
else
{
$default
}
}

function SetIgnoreCertErrors ($value){
Write-Host "Setting IgnoreCertErros to $value"
New-Item -Path HKLM:\SOFTWARE\PureStorage\SCOM -Name IgnoreCertErrors -Force
Set-Item -Path HKLM:\SOFTWARE\PureStorage\SCOM\IgnoreCertErrors -Value $value
}

function GetIgnoreCertErrors ($default){
if (Test-Path HKLM:\SOFTWARE\PureStorage\SCOM\IgnoreCertErrors){
$item = Get-ItemProperty "HKLM:\SOFTWARE\PureStorage\SCOM\IgnoreCertErrors"
$log_level = [bool]($item.'(default)')
$log_level
}
else
{
$default
}
}


function InitLogging () {
$GLOBAL:MOMAPI = New-Object -comObject "Mom.ScriptAPI"
$GLOBAL:mpVersion = (Get-SCOMManagementPack -name "PureStorageFlashArray").Version.ToString()
if(!$GLOBAL:mpVersion) {$GLOBAL:mpVersion = 'unknown'}
$GLOBAL:clientName = "SCOM"
##### LOG LEVEL ####
# 1 Errors
# 2 Warnings
# 3 Information
# 4 Verbose
$GLOBAL:ERROR_LEVEL = 1
$GLOBAL:WARNING_LEVEL = 2
$GLOBAL:INFO_LEVEL = 3
$GLOBAL:VERBOSE_LEVEL = 4
$GLOBAL:CURRENT_LOG_LEVEL = GetLogLevel $GLOBAL:VERBOSE_LEVEL

$GLOBAL:LOG_CODES_MAP = @{}
$GLOBAL:DEFAULT_LOG_CODE = 5555
################## Discoveries ##################
$GLOBAL:LOG_CODES_MAP.Add("PureVolumeDiscovery.ps1", 2001)
$GLOBAL:LOG_CODES_MAP.Add("PurePortDiscovery.ps1", 2002)
$GLOBAL:LOG_CODES_MAP.Add("PureHostDiscovery.ps1", 2003)
$GLOBAL:LOG_CODES_MAP.Add("PureControllerDiscovery.ps1", 2004)
$GLOBAL:LOG_CODES_MAP.Add("PureArrayDiscovery.ps1", 2005)
$GLOBAL:LOG_CODES_MAP.Add("InitialArrayDiscovery.ps1", 2006)
##################### Rules #######################
$GLOBAL:LOG_CODES_MAP.Add("AlertsRule.ps1", 2101)
$GLOBAL:LOG_CODES_MAP.Add("ArrayPerformanceRule.ps1", 2102)
$GLOBAL:LOG_CODES_MAP.Add("HostgroupPerformanceRule.ps1", 2103)
$GLOBAL:LOG_CODES_MAP.Add("HostPerformanceRule.ps1", 2104)
$GLOBAL:LOG_CODES_MAP.Add("VolumePerformanceRule.ps1", 2105)
#################### Monitors ######################
$GLOBAL:LOG_CODES_MAP.Add("AlertsRuleMonitor.ps1", 2201)
$GLOBAL:LOG_CODES_MAP.Add("ArrayIOSpaceMonitor.ps1", 2202)
$GLOBAL:LOG_CODES_MAP.Add("ConnectionHealthMonitor.ps1", 2203)
$GLOBAL:LOG_CODES_MAP.Add("ControllerHealthMonitor.ps1", 2204)
$GLOBAL:LOG_CODES_MAP.Add("VolumeIOMonitor.ps1", 2205)
$GLOBAL:LOG_CODES_MAP.Add("HostIOMonitor.ps1", 2206)
$GLOBAL:LOG_CODES_MAP.Add("PortHealthMonitor.ps1", 2207)
##################### Tasks #######################
$GLOBAL:LOG_CODES_MAP.Add("NewHostTask.ps1", 2301)
$GLOBAL:LOG_CODES_MAP.Add("NewVolumeTask.ps1", 2302)
$GLOBAL:LOG_CODES_MAP.Add("VerifyEndpointTask.ps1", 2303)
################### Dashboards ####################
$GLOBAL:LOG_CODES_MAP.Add("PureVolumeState.ps1", 2401)
$GLOBAL:LOG_CODES_MAP.Add("PureArrayDashboardIOPSData.ps1", 2402)
$GLOBAL:LOG_CODES_MAP.Add("PureArrayDashboardLatencyData.ps1", 2403)
$GLOBAL:LOG_CODES_MAP.Add("PureArrayDashboardBandwidthData.ps1", 2404)
$GLOBAL:LOG_CODES_MAP.Add("PureHostState.ps1", 2405)
$GLOBAL:LOG_CODES_MAP.Add("PureArrayDashboardSpaceMetricsData.ps1", 2406)
}

function GetLogCode ($filename) {
$code = $GLOBAL:LOG_CODES_MAP[$filename]
if ($code -eq $null) {
$code = $DEFAULT_LOG_CODE
}
return $code
}

function GetSCOMLogLevel ($level) {
switch ($level){
$GLOBAL:ERROR_LEVEL {1}
$GLOBAL:WARNING_LEVEL {2}
$GLOBAL:INFO_LEVEL {0}
$GLOBAL:VERBOSE_LEVEL {0}
}
}

function Log ($script_name, $level, $message) {
if ($level -le $GLOBAL:CURRENT_LOG_LEVEL){
$code = GetLogCode $script_name
$level = GetSCOMLogLevel $level
if($GLOBAL:mpVersion -eq 'unknown') {$GLOBAL:mpVersion = (Get-SCOMManagementPack -name "PureStorageFlashArray").Version.ToString()}
$fullScriptName = "$script_name" + " [$GLOBAL:mpVersion]"
$GLOBAL:MOMAPI.LogScriptEvent($fullScriptName, $code, $level, $message)
}
}

function LoadPowerShellSDK ($script_name){
Log $script_name $GLOBAL:VERBOSE_LEVEL "Importing PowerShell SDK in $script_name"

try {
$PurePowerShellSDKKey = Get-ItemProperty "HKLM:\SOFTWARE\PureStorage\SCOM\PowerShellSDKPath"
$PurePowerShellSDKLocation = $PurePowerShellSDKKey.'(default)'
Log $script_name $GLOBAL:VERBOSE_LEVEL "Importing PowerShell SDK from $PurePowerShellSDKLocation"
Import-Module $PurePowerShellSDKLocation -Verbose
}
catch {
Log $script_name $GLOBAL:ERROR_LEVEL "Failed to import PowerShell SDK from $PurePowerShellSDKLocation"
}
}

function LoadOperationsManagerModule ($script_name)
{
Log $script_name $GLOBAL:INFO_LEVEL "Importing Operations Manager module in $script_name"
try
{
# https://blogs.technet.microsoft.com/cchamp/2015/09/30/loading-the-scom-powershell-module-for-real-this-time/
$OMCmdletsTest = (Get-Module|% {$_.Name}) -Join ' '
If (!$OMCmdletsTest.Contains('OperationsManager')) {
$ModuleFound = $false
$SetupKeys = @('HKLM:\Software\Microsoft\Microsoft Operations Manager\3.0\Setup',
'HKLM:\SOFTWARE\Microsoft\System Center Operations Manager\12\Setup')
foreach($setupKey in $SetupKeys) {
If ((Test-Path $setupKey) -and ($ModuleFound -eq $false)) {
$setupKey = Get-Item -Path $setupKey
$installDirectory = $setupKey.GetValue('InstallDirectory')
$psmPath = $installdirectory + '\Powershell\OperationsManager\OperationsManager.psm1'
If (Test-Path $psmPath) {
$ModuleFound = $true
}
}
}
If ($ModuleFound) {
Import-Module $psmPath
} else {
Import-Module OperationsManager
}
}
else { Log $ScriptName $GLOBAL:INFO_LEVEL "Operations Manager module is already present" }
}
catch
{
Log $script_name $GLOBAL:INFO_LEVEL "Failed to import Operations Manager: $_"
}
}

InitLogging


PortHealthMonitor
</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>Endpoint</Name>
<Value>$Target/Host/Property[Type="PureStorage.FlashArray.PureArray"]/Endpoint$</Value>
</Parameter>
<Parameter>
<Name>Username</Name>
<Value>$RunAs[Name="PureStorage.FlashArray.FlashArrayAdminAccount"]/UserName$</Value>
</Parameter>
<Parameter>
<Name>Password</Name>
<Value>$RunAs[Name="PureStorage.FlashArray.FlashArrayAdminAccount"]/Password$</Value>
</Parameter>
<Parameter>
<Name>LogToArray</Name>
<Value>$Config/LogToArray$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="Probe"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
<TriggerOnly>true</TriggerOnly>
</ProbeActionModuleType>