PureStorage.FlashArray.PureArray.PowerShell.Script.Perf.PA (ProbeActionModuleType)

Element properties:

TypeProbeActionModuleType
IsolationAny
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.PureArray.PowerShell.Script.Perf.PA" Accessibility="Internal" Batching="false" PassThrough="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="Any">
<Composite>
<MemberModules>
<ProbeAction ID="Probe" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe">
<ScriptName>PureStorage.FlashArray.PureArray.PowerShell.Script.Perf.PA.ps1</ScriptName>
<ScriptBody><Script># Gets performance data for the Pure Array
param($Endpoint, $Username, $Password, $LogToArray)

function CreateCounterPropertyBag ($name, $value, $array_name) {
$prop_bag = $momapi.CreatePropertyBag()
$prop_bag.AddValue("InstanceName", $array_name)
$prop_bag.AddValue("CounterName", $name)
$prop_bag.AddValue("CounterValue", $value)
return $prop_bag
}

function Get-PureArrayPerformanceData() {
# Import the SCOM PowerShell module
$ScriptName = "ArrayPerformanceRule.ps1"
$disableLoggingToArray = -not $LogToArray

LoadOperationsManagerModule $ScriptName

$StartTime = Get-Date
$whoami = whoami
$momapi = New-Object -comObject MOM.ScriptAPI
$Password = $Password | ConvertTo-SecureString -AsPlainText -Force

Log $ScriptName $GLOBAL:INFO_LEVEL "Script is starting. Running, as ($whoami)."
LoadPowerShellSDK $ScriptName

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 {
Log $ScriptName $GLOBAL:ERROR_LEVEL "Connection to array failed on these credentials. $Username. Check that the PurePowershell cmdlet is installed, and your credentials are correct. Error: $_"
exit
}

if ($FlashArray -eq $null) {
Log $ScriptName $GLOBAL:ERROR_LEVEL "Array instance for $Endpoint is null"
}
$ArrayName = (Get-PfaArrayId -Array $FlashArray).array_name
$metrics = Get-PfaArrayIOMetrics -Array $FlashArray
Log $ScriptName $GLOBAL:VERBOSE_LEVEL "Metrics for $Endpoint : $metrics"
$writes_per_second = 1.0 * $metrics.writes_per_sec
$usec_per_write_op = 1.0 * $metrics.usec_per_write_op
$output_per_second = 1.0 * $metrics.output_per_sec
$reads_per_second = 1.0 * $metrics.reads_per_sec
$input_per_second = 1.0 * $metrics.input_per_sec
$usec_per_read_op = 1.0 * $metrics.usec_per_read_op
$spaceMetrics = Get-PfaArraySpaceMetrics -Array $FlashArray
Log $ScriptName $GLOBAL:VERBOSE_LEVEL "Space metrics for $Endpoint : $spaceMetrics"
$capacity = $spaceMetrics.capacity
$usedSpace = $spaceMetrics.total
if ($capacity -eq $null) {
$capacity = 0
}
if ($usedSpace -eq $null) {
$usedSpace = 0
}

if ($ArrayName -ne $null) {
Log $ScriptName $GLOBAL:VERBOSE_LEVEL "Creating property bags for $ArrayName...."

$bag = $momapi.CreatePropertyBag()
$bag.AddValue("InstanceName", $ArrayName)
$bag.AddValue("writes_per_second", $writes_per_second)
$bag.AddValue("usec_per_write_op", $usec_per_write_op)
$bag.AddValue("output_per_second", $output_per_second)
$bag.AddValue("reads_per_second", $reads_per_second)
$bag.AddValue("input_per_second", $input_per_second)
$bag.AddValue("usec_per_read_op", $usec_per_read_op)
$bag.AddValue("total_bandwidth", $input_per_second + $output_per_second)
$bag.AddValue("total_iops", $reads_per_second + $writes_per_second)
$bag.AddValue("capacity", $capacity)
$bag.AddValue("used_space", $usedSpace)
$bag
}

Disconnect-PfaArray -Array $FlashArray
$EndTime = Get-Date
$ScriptTime = ($EndTime - $StartTime).TotalSeconds
Log $ScriptName $GLOBAL:INFO_LEVEL "Script has completed. 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

Get-PureArrayPerformanceData</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>Endpoint</Name>
<Value>$Target/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>