PureStorage.FlashArray.PowerShellWriteAction.Tasks.VerifyEndpoint (WriteActionModuleType)

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
InputTypeSystem.BaseData

Member Modules:

ID Module Type TypeId RunAs 
WriteTask WriteAction Microsoft.Windows.PowerShellWriteAction Default

Overrideable Parameters:

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

Source Code:

<WriteActionModuleType ID="PureStorage.FlashArray.PowerShellWriteAction.Tasks.VerifyEndpoint" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Endpoint" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="UserName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Password" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" type="xsd:int" name="TimeoutSeconds"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" type="xsd:boolean" name="LogToArray" minOccurs="0" maxOccurs="1"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" type="xsd:boolean" name="IgnoreCertificateErrors" 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"/>
<OverrideableParameter ID="IgnoreCertificateErrors" Selector="$Config/IgnoreCertificateErrors$" ParameterType="bool"/>
</OverrideableParameters>
<ModuleImplementation>
<Composite>
<MemberModules>
<WriteAction ID="WriteTask" TypeID="Windows!Microsoft.Windows.PowerShellWriteAction">
<ScriptName>VerifyEndpointTask.ps1</ScriptName>
<ScriptBody><Script># This script verifies connectivity of endpoint

param($Endpoint, $Username, $Password, $LogToArray, $IgnoreCertificateErrors, $newtonsoft_path, $renci_path, $rest_shared_path, $rest_path, $sdk_path)

$ScriptName = "VerifyEndpointTask.ps1"

function Write-Message($message, $log_level) {
Write-Host $message

Log $ScriptName $log_level $message
}

function VerifyEndpoint() {
$StartTime = Get-Date

# Import the SCOM PowerShell module
LoadOperationsManagerModule $ScriptName

$whoami = whoami
Log $ScriptName $GLOBAL:INFO_LEVEL "Starting script. Running as ($whoami)"

LoadPowerShellSDK $ScriptName

Write-Message "Verifying endpoint: $Endpoint ..." $GLOBAL:INFO_LEVEL

if ([string]::IsNullOrWhiteSpace($Username)) {
Write-Message "Invalid username. Please make sure a RunAs account for $Endpoint is added to the 'FlashArray Admin Account' profile." $GLOBAL:ERROR_LEVEL
} elseif ([string]::IsNullOrEmpty($Password)) {
Write-Message "Invalid password. Please make sure a RunAs account for $Endpoint is added to the 'FlashArray Admin Account' profile." $GLOBAL:ERROR_LEVEL
} else {
Test-Endpoint
}

$EndTime = Get-Date
$ScriptTime = ($EndTime - $StartTime).TotalSeconds
Log $ScriptName $GLOBAL:INFO_LEVEL "Script has completed. Runtime was ($ScriptTime) seconds."
}

function Test-Endpoint() {
Write-Message "Testing network connectivity to the array ..." $GLOBAL:INFO_LEVEL
$results = Test-NetConnection -ComputerName $Endpoint -InformationLevel "Detailed"
if ($results.NameResolutionSucceeded) {
Write-Message "DNS name resolution success." $GLOBAL:INFO_LEVEL
} else {
Write-Message "DNS name resolution is not working for the supplied array name." $GLOBAL:ERROR_LEVEL
return
}

$ports = @("443", "22")
foreach ($port in $ports) {
Write-Message "Testing port $port ..." $GLOBAL:INFO_LEVEL
$results = Test-NetConnection -Port $port -ComputerName $Endpoint -InformationLevel "Detailed"
if ($results.TcpTestSucceeded) {
Write-Message "Port $port success." $GLOBAL:INFO_LEVEL
} else {
Write-Message "Port $port failed." $GLOBAL:ERROR_LEVEL
return
}
}

Write-Message "Connecting to array ..." $GLOBAL:INFO_LEVEL
try {
$disableLoggingToArray = -not $LogToArray
$Password = $Password | ConvertTo-SecureString -AsPlainText -Force

$FlashArray = New-PfaArray -EndPoint $Endpoint -UserName $Username -Password $Password -ClientName $GLOBAL:clientName -ClientVersion $GLOBAL:mpVersion -IgnoreCertificateError:$IgnoreCertErrors -HttpTimeOutInMilliSeconds 60000 -DisableLoggingToArray:$disableLoggingToArray
Disconnect-PfaArray -Array $FlashArray

Write-Message "Success. $Endpoint is accessible." $GLOBAL:INFO_LEVEL
} catch {
Write-Message "Connection to array failed. `nCheck that your credentials are correct. `nError: $_" $GLOBAL:ERROR_LEVEL
}
}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 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("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)
$GLOBAL:LOG_CODES_MAP.Add("PodMediatorStatus.ps1", 2208)
##################### 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 {
Log $script_name $GLOBAL:VERBOSE_LEVEL "Loading PowerShell SDK dependencies"
Add-Type -Path $newtonsoft_path, $renci_path, $rest_shared_path, $rest_path

Log $script_name $GLOBAL:VERBOSE_LEVEL "Importing PowerShell SDK"
Import-Module $sdk_path -Verbose
}
catch {
Log $script_name $GLOBAL:ERROR_LEVEL "Failed to import PowerShell SDK"
}
}

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: $_"
}
}

function Format-Number($value, $digits, $unit)
{
return [string][Math]::Round($value, $digits) + $unit
}

function Format-ByteNumber($value, $suffix)
{
if ($null -eq $value) {
return '-'
} elseif ($value -ge 1PB){
$v = $value/1PB
$unit =' PB'
} elseif ($value -ge 1TB){
$v = $value/1TB
$unit = ' TB'
} elseif ($value -ge 1GB){
$v = $value/1GB
$unit = ' GB'
} elseif ($value -ge 1MB){
$v = $value/1MB
$unit = ' MB'
} elseif ($value -ge 1kB){
$v = $value/1kB
$unit = ' kB'
} else {
$v = $value
$unit =' B'
}

return Format-Number $v 2 ($unit + $suffix)
}

function Get-PerfCounterValue($instance, $counterName, $startTime, $endTime)
{
$criteria = New-Object Microsoft.EnterpriseManagement.Monitoring.MonitoringPerformanceDataCriteria("CounterName='$counterName'")
$performanceDataCollection = $instance.GetMonitoringPerformanceData($criteria)
Log $ScriptName $GLOBAL:VERBOSE_LEVEL $performanceDataCollection
$valueReader = $performanceDataCollection.GetValueReader($startTime, $endTime)
while ($valueReader.Read()) {
Write-Output $valueReader.GetMonitoringPerformanceDataValue().SampleValue
}
}


InitLogging


VerifyEndpoint
</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>Endpoint</Name>
<Value>$Config/Endpoint$</Value>
</Parameter>
<Parameter>
<Name>UserName</Name>
<Value>$Config/UserName$</Value>
</Parameter>
<Parameter>
<Name>Password</Name>
<Value>$Config/Password$</Value>
</Parameter>
<Parameter>
<Name>LogToArray</Name>
<Value>$Config/LogToArray$</Value>
</Parameter>
<Parameter>
<Name>IgnoreCertificateErrors</Name>
<Value>$Config/IgnoreCertificateErrors$</Value>
</Parameter>
<Parameter>
<Name>newtonsoft_path</Name>
<Value>$FileResource[Name="Newtonsoft.Json"]/Path$</Value>
</Parameter>
<Parameter>
<Name>renci_path</Name>
<Value>$FileResource[Name="Renci.SshNet"]/Path$</Value>
</Parameter>
<Parameter>
<Name>rest_shared_path</Name>
<Value>$FileResource[Name="PureStorage.Rest.Shared"]/Path$</Value>
</Parameter>
<Parameter>
<Name>rest_path</Name>
<Value>$FileResource[Name="PureStorage.Rest"]/Path$</Value>
</Parameter>
<Parameter>
<Name>sdk_path</Name>
<Value>$FileResource[Name="PureStoragePowerShellSDK"]/Path$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="WriteTask"/>
</Composition>
</Composite>
</ModuleImplementation>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>