Fujitsu Windows Performance Data Collection Probe Action

Fujitsu.Servers.PRIMERGY.Windows.PerfMon.PerformanceMonitor.Probe (ProbeActionModuleType)

Fujitsu Windows Performance Data Collection Probe Action Type

Element properties:

TypeProbeActionModuleType
IsolationAny
AccessibilityInternal
RunAsSystem.PrivilegedMonitoringAccount
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
PassThrough ProbeAction System.PassThroughProbe Default
Script ProbeAction Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe Default

Source Code:

<ProbeActionModuleType ID="Fujitsu.Servers.PRIMERGY.Windows.PerfMon.PerformanceMonitor.Probe" Accessibility="Internal" RunAs="System!System.PrivilegedMonitoringAccount" Batching="false" PassThrough="false">
<Configuration>
<IncludeSchemaTypes>
<SchemaType>Windows!Microsoft.Windows.PowerShellSchema</SchemaType>
</IncludeSchemaTypes>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="0" name="StrictErrorHandling" type="xsd:boolean"/>
<!-- Fixed Parameters -->
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TargetName" type="NonNullString"/>
</Configuration>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<ProbeAction ID="PassThrough" TypeID="System!System.PassThroughProbe"/>
<ProbeAction ID="Script" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe">
<ScriptName>PerfMonMonitor.ps1</ScriptName>
<ScriptBody><Script>#===================================================================
#===================================================================
#
# FUJITSU Limited
# Copyright (C) FUJITSU Limited 2008 - 2019
#
#===================================================================
#===================================================================
#-------------------------------------------------------------------
# PerfMonMonitor.ps1 $ManagementGroup $TargetComputer [$DebugLevel] [$DebugTest]
#
# Summary:
# Monitoring of Fujitsu PRIMERGY Windows Server Components
#-------------------------------------------------------------------

param (
[string]$ManagementGroup,
[string]$TargetComputer,
[string]$DbgLevel,
[string]$DbgTest
)

Set-Variable -Name MPScript -Option Constant -Value "PerfMonMonitor.ps1"
Set-Variable -Name LogFileName -Option Constant -Value "PerfMonMonitorTrace"
$script:TargetComputer = $TargetComputer
$script:MGMGroup = $ManagementGroup

#script runs inside MP
$script:insideMP = $True

# check PowerShell version
$PSVersion = $PSVersionTable.PSVersion
if ($PSVersion.Major -lt 2) {
Debug-Out "PowerShellVersion V$PSVersion is too low! Use at least V2.0!", $DBG_INFO
exit 0
}

Set-Variable -Name IpmiEntityId_Unknown -Option Constant -Value 0
Set-Variable -Name IpmiEntityId_Processor -Option Constant -Value 1
Set-Variable -Name IpmiEntityId_DiskBay -Option Constant -Value 2
Set-Variable -Name IpmiEntityId_System -Option Constant -Value 3
Set-Variable -Name IpmiEntityId_AddInCard -Option Constant -Value 4
Set-Variable -Name IpmiEntityId_PowerSupply -Option Constant -Value 5
Set-Variable -Name IpmiEntityId_SystemChassis -Option Constant -Value 6
Set-Variable -Name IpmiEntityId_HardDisk -Option Constant -Value 7
Set-Variable -Name IpmiEntityId_Blade -Option Constant -Value 8
Set-Variable -Name IpmiEntityId_Fan -Option Constant -Value 9
Set-Variable -Name IpmiEntityId_Memory -Option Constant -Value 10
Set-Variable -Name IpmiEntityId_IoModule -Option Constant -Value 11
Set-Variable -Name IpmiEntityId_AirInlet -Option Constant -Value 12
Set-Variable -Name IpmiEntityId_Total -Option Constant -Value 13
Set-Variable -Name IpmiEntityId_Other -Option Constant -Value 14 # Invented. Make sure this is the last component.

$IpmiEntityIdArray = @("") * ($IpmiEntityId_Other + 1)
$IpmiEntityIdArray[$IpmiEntityId_Unknown] = 0x00
$IpmiEntityIdArray[$IpmiEntityId_Processor] = 0x03
$IpmiEntityIdArray[$IpmiEntityId_DiskBay] = 0x04
$IpmiEntityIdArray[$IpmiEntityId_System] = 0x07
$IpmiEntityIdArray[$IpmiEntityId_AddInCard] = 0x0B
$IpmiEntityIdArray[$IpmiEntityId_PowerSupply] = 0x0A
$IpmiEntityIdArray[$IpmiEntityId_SystemChassis] = 0x17
$IpmiEntityIdArray[$IpmiEntityId_HardDisk] = 0x1A
$IpmiEntityIdArray[$IpmiEntityId_Blade] = 0x1B
$IpmiEntityIdArray[$IpmiEntityId_Fan] = 0x1D
$IpmiEntityIdArray[$IpmiEntityId_Memory] = 0x20
$IpmiEntityIdArray[$IpmiEntityId_IoModule] = 0x2C
$IpmiEntityIdArray[$IpmiEntityId_AirInlet] = 0x37
$IpmiEntityIdArray[$IpmiEntityId_Total] = 0xE0
$IpmiEntityIdArray[$IpmiEntityId_Other] = 0xFF

$IpmiEntityNameArray = @("") * ($IpmiEntityId_Other + 1)
$IpmiEntityNameArray[$IpmiEntityId_Unknown] = "All"
$IpmiEntityNameArray[$IpmiEntityId_Processor] = "Processor"
$IpmiEntityNameArray[$IpmiEntityId_DiskBay] = "HDD Bay"
$IpmiEntityNameArray[$IpmiEntityId_System] = "System Board"
$IpmiEntityNameArray[$IpmiEntityId_AddInCard] = "Add-In Card"
$IpmiEntityNameArray[$IpmiEntityId_PowerSupply] = "Power Supply"
$IpmiEntityNameArray[$IpmiEntityId_SystemChassis] = "System Chassis"
$IpmiEntityNameArray[$IpmiEntityId_HardDisk] = "Hard Disk"
$IpmiEntityNameArray[$IpmiEntityId_Blade] = "Blade"
$IpmiEntityNameArray[$IpmiEntityId_Fan] = "Fan"
$IpmiEntityNameArray[$IpmiEntityId_Memory] = "Memory"
$IpmiEntityNameArray[$IpmiEntityId_IoModule] = "I/O Module"
$IpmiEntityNameArray[$IpmiEntityId_AirInlet] = "Ambient"
$IpmiEntityNameArray[$IpmiEntityId_Total] = "Total"
$IpmiEntityNameArray[$IpmiEntityId_Other] = "Other"

#-------------------------------------------------------------------

function Main
{
$script:TargetComputer = Get-Content Env:ComputerName
Initialize-Logging $SEC_PerfMonMonitor ""

Debug-Out "Performance Monitor Version is: *** $($script:MPVersion) ***" $DBG_INFO
Debug-Out "Performance Monitor Management Group is: *** $($script:MGMGroup) ***" $DBG_INFO

$PSVersion = $PSVersionTable.PSVersion
$WMIVersion = $PSVersionTable.BuildVersion
$OSVersion = [System.Environment]::OSVersion.Version
$OSName = Get-OSProperty "ProductName"
$OSEdition = Get-OSProperty "EditionID"
Debug-Out "Running on PowerShell $PSVersion, WMI $WMIVersion, OS $OSVersion." $DBG_INFO
Debug-Out "Running on '$OSName', Edition '$OSEdition.'" $DBG_INFO

if (("$OSEdition".Contains("Nano") -eq $True)) { $script:isNano = $True }
Debug-Out "Running on Nano Server = $($script:isNano)" $DBG_INFO

if ($script:insideMP -eq $True) {
try {
$oAPI = New-Object -ComObject "MOM.ScriptAPI" -ErrorAction Stop
$oPropertyBag = $Null
} catch {
Debug-Out "Could not generate 'MOM.ScriptAPI' object. We are not inside an MP, set insideMP = False" $DBG_INFO
$script:insideMP = $False
}
}

if ($script:isNano -eq $True) {
Debug-Out "*******" $DBG_INFO
Debug-Out "******* We are running on Nano Server. Quit." $DBG_INFO
Debug-Out "*******" $DBG_INFO
exit 0
}

# SVAgents
#-----------------------------------
$SVAgentVersion = "N/A"

$SVAgentsPath = Get-SVAgentsPath
Debug-Out "SV-Agents Path: $SVAgentsPath" $DBG_INFO

# We are assuming that the service runs.
# Real check is requesting SV Agent Version.
$script:SVAgentRunning = $True

if ([string]::IsNullOrEmpty($SVAgentsPath)) {
Debug-Out "No ServerView Agent installed!" $DBG_INFO
$script:SVAgentRunning = $False
exit -1
}
$script:SVAgentRunning = Get-SVAgentsRunning
Debug-Out "ServerView Agent Service found running = $($script:SVAgentRunning)" $DBG_INFO

if ($script:SVAgentRunning -eq $False) {
Debug-Out "**** ServerView Agent is not running on PRIMERGY Server $($script:TargetComputer). *** Quit. ****" $DBG_INFO
if ($script:insideMP -eq $True) {
# Anything to do here?
}
exit 0
} else {
$script:oSwitch = New-Object -comObject "Rswitch.Rswitch.1"
#*** give a hint to agents, who accesses them (in case of DEBUG / trace)
$script:oSwitch.ClientName = $script:SVISCOMName

# request SV Agent version to check whether SCCI is possible
# Note: SV Agentless service seems to indicate SV Agents running but does not support SCCI
$Status = $script:oSwitch.ScciQuery(0x0C00, 0xA806, 0, -1, 0, [REF]$SVAgentVersion, 0)
if ($Status -ne 0) {
Debug-Out "oSwitch: No Data for opCode=0x0C00 opCodeExt=0xA806 objIndex=0 cabID=-1" $DBG_DESC
Debug-Out "#############" $DBG_INFO
Debug-Out "############# ServerView SCCI not supported on $($script:TargetComputer)!" $DBG_INFO
Debug-Out "#############" $DBG_INFO
$script:oSwitch = $Null
$script:SVASRunning = $True
} else {
Debug-Out "oSwitch: opCode=0x0C00 opCodeExt=0xA806 objIndex=0 cabID=-1 -&gt; scciValue = '$SVAgentVersion'" $DBG_DESC
if ($SVAgentVersion.Length -gt 6 ) { $SVAgentVersion = $SVAgentVersion.Substring(0, 7) }
Debug-Out "SV-Agent Version: $SVAgentVersion" $DBG_INFO
if (($SVAgentVersion.Length -eq 0) -or ($SVAgentVersion -lt $SVAGENTVERSION_MIN)) {
Debug-Out "ServerView Agent Version V$SVAgentVersion too old! Use at least V$SVAGENTVERSION_MIN!" $DBG_INFO
}
}
}

if ($script:SVASRunning -eq $True) {
Debug-Out "**** ServerView Agentless Service is running. *** Quit. ****" $DBG_INFO
exit 0
}

$script:CIMProvider = $False
if (($SVAgentVersion -ne "N/A") -and (($SVAgentVersion -gt $SVCIMVERSION_MIN) -and ($OSVersion -gt "6.0"))) { $script:CIMProvider = $True }
Debug-Out "This system has CIMProvider = $script:CIMProvider" $DBG_INFO

# check whether the script was forced to CIM/SCCI
if (($script:DebugTest -eq "SCCI") -or ($script:DebugTest -eq "CIM")) {
if ($script:DebugTest -eq "SCCI") { $script:CIMProvider = $False }
if ($script:DebugTest -eq "CIM") { $script:CIMProvider = $True }
Debug-Out "This system has CIMProvider = $script:CIMProvider" $DBG_INFO
}

# check currently simulated commands
$DbgSimList = Get-ScciData 0xF009 0 0 -1
if ("$DbgSimList" -ne "") {
$DbgSimList = $DbgSimList.Substring(0, $DbgSimList.Length - 1)
$DbgSimList = $DbgSimList.Replace("OC=", " OC=")
Debug-Out "Simulations:" $DBG_INFO
Debug-Out "$DbgSimList" $DBG_INFO
}

if ($script:CIMProvider -eq $False) { $SVNamespace = $cimv2NS }
if ($script:CIMProvider -eq $True) { $SVNamespace = $svsNS }

# check whether Agents or Providers can supply data
if ($SVAgentVersion -gt $SVAGENTVERSION_MIN) {
$CheckSVOverallState = Get-SVOverallState
Debug-Out "Check ServerView Overall State: $CheckSVOverallState" $DBG_INFO
if ($CheckSVOverallState -eq $False) {
if ($script:CIMProvider -eq $True) {
Debug-Out "**** ServerView CIM providers cannot supply data. *** Quit. ****" $DBG_INFO
} else {
Debug-Out "**** ServerView Agents cannot supply data. *** Quit. ****" $DBG_INFO
}
exit 0
}
} else {
$CheckSVOverallState = $True
}

# Main Cabinet ID
if ($script:SVAgentRunning -eq $True) {
$script:Cabinet = -1
$script:Cabinet = Get-ScciData 0xE204 0 0 -1
Debug-Out "Main Cabinet ID = $($script:Cabinet)" $DBG_INFO
}


# Determine Cabinet Number(s) for SCCI
#---------------------------------------------------------------
if ($script:SVAgentRunning -eq $True) {
$cabName = Get-ScciData 0x0C00 0x0108 0 $script:Cabinet
$Cabinets = "Main: $($script:Cabinet) ($cabName)"

$script:CabinetArray[0] = $script:Cabinet
$cabData = Get-ScciData 0x0220 0 0 $script:Cabinet

if ($Null -ne $cabData) {
$index = 1
$Cabinets = "$Cabinets, Extension: "
if ($cabData -is [system.array]) {
for ($i=0; $i -lt $cabData.Length; $i++) {
$script:CabinetArray[$index] = "$('{0:X2}' -f $cabData[$i+1])$('{0:X2}' -f $cabData[$i])"
$script:CabinetArray[$index] = [convert]::ToInt32($script:CabinetArray[$index], 16)
$i++
$index++
}
Debug-Out " cabString[]: $cabString" $DBG_INFO
} else {
if ($cabData -gt 0xFFFF) {
$script:CabinetArray[$index] = $cabData -band 0x0000FFFF
$index ++
#$script:CabinetArray[$index] = $cabData -shr 16 # PS v3.0
$script:CabinetArray[$index] = [convert]::ToInt32([math]::Floor($cabData * [math]::Pow(2,-16)))
} else {
$script:CabinetArray[$index] = $cabData
}
$index ++
}

$index = 0
foreach ($cabData in $script:CabinetArray) {
if ($index -gt 0 -and $Null -ne $cabData) {
$cabName = Get-ScciData 0x0C00 0x0108 0 $cabData
Debug-Out "CabinetID $($index): $cabData ($cabName)" $DBG_INFO
$Cabinets = "$Cabinets, $cabData ($cabName)"
}
$index ++
}
}
}
Debug-Out "Cabinets: [$Cabinets]" $DBG_INFO


#---------------------------
$script:componentTypeArray = @("") * $cMAXINDEX
$script:componentClassArray = @("") * $cMAXINDEX

$index = 0
if ($script:CIMProvider -eq $True) {
$SVAgentClass = "SVS_PGYTemperatureSensor"
$CimData = Get-CimQuery -Query "SELECT * FROM $SVAgentClass" -Namespace $SVNamespace

if ($script:WMIInstanceValid -eq $True) {
foreach ($objItem in $CimData) {
$script:componentNameArray[$index] = $objItem.ElementName

if ($script:componentNameArray[$index] -like "*VR*") {
Debug-Out "Skipping Temperature Sensor: '$($script:componentNameArray[$index])'" $DBG_INFO
} else {
$script:componentStatusArray[$index] = $script:CIM_HealthState[$objItem.HealthState]
$script:componentInfoArray[$index] = $objItem.CurrentReading
$script:componentTypeArray[$index] = ""
$script:componentClassArray[$index] = ""
Debug-Out "\$($SVNamespace):$SVAgentClass.ElementName: $($objItem.ElementName)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.HealthState: $($objItem.HealthState)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.CurrentReading: $($objItem.CurrentReading)" $DBG_DESC

$DevCabinet = [convert]::ToInt32(($objItem.DeviceID -Split "-")[0], 16)
$DevIndex = [convert]::ToInt32(($objItem.DeviceID -Split "-")[1], 16)
#$DevCabinet = [convert]::ToInt32(($objItem.DeviceID.Split("-"))[0], 16)
#$DevIndex = [convert]::ToInt32(($objItem.DeviceID.Split("-"))[1], 16)

$script:componentNameArray[$index] = "$('{0:X}' -f $DevCabinet)/$DevIndex $($script:componentNameArray[$index])"

$index ++
}
}
}
} else {
foreach ($cab in $script:CabinetArray) {
if ($Null -ne $cab) {
$SCCIIndex = Get-ScciData 0x400 0 0 $cab
for ($i=0; $i -lt $SCCIIndex; $i++) {
$script:componentNameArray[$index] = Get-ScciData 0x404 0 $i $cab
$script:componentNameArray[$index] = "$('{0:X}' -f $cab)/$i $($script:componentNameArray[$index])"

if ($script:componentNameArray[$index] -like "*VR*") {
Debug-Out "Skipping Temperature Sensor: '$($script:componentNameArray[$index])'" $DBG_INFO
} else {
$script:componentStatusArray[$index] = Get-ScciData 0x401 0 $i $cab
$script:componentInfoArray[$index] = Get-ScciData 0x402 0 $i $cab
if ($Null -eq $script:componentInfoArray[$index] -or $script:componentInfoArray[$index] -eq 0) {
#Debug-Out "Skipping Temperature Sensor: '$($script:componentNameArray[$index])', got no current reading." $DBG_INFO
} else {
$script:componentTypeArray[$index] = Get-ScciData 0x403 0 $i $cab
$script:componentClassArray[$index] = ""

switch ($script:componentStatusArray[$index]) {
0 { $script:componentStatusArray[$index] = $STATUS_UNKNOWN } # 0: Sensor not available
1 { $script:componentStatusArray[$index] = $STATUS_OK } # 1: Sensor OK
3 { $script:componentStatusArray[$index] = $STATUS_WARNING } # 3: Sensor failed / not connected
4 { $script:componentStatusArray[$index] = $STATUS_WARNING } # 4: Temperature warning (too hot)
5 { $script:componentStatusArray[$index] = $STATUS_ERROR } # 5: Temperature critical (too hot - an optional shutdown is possible)
6 { $script:componentStatusArray[$index] = $STATUS_OK } # 6: Temperature normal
7 { $script:componentStatusArray[$index] = $STATUS_WARNING } # 7: Temperature warning
default { $script:componentStatusArray[$index] = $STATUS_UNKNOWN }
}

switch ($script:componentTypeArray[$index]) {
1 { $script:componentTypeArray[$index] = $IpmiEntityIdArray[$IpmiEntityId_Processor] } # 1: CPU sensor
2 { $script:componentTypeArray[$index] = $IpmiEntityIdArray[$IpmiEntityId_AirInlet] } # 2: Ambient (outside temperature) sensor
3 { $script:componentTypeArray[$index] = $IpmiEntityIdArray[$IpmiEntityId_AddInCard] } # 3: In-housing sensor
4 { $script:componentTypeArray[$index] = $IpmiEntityIdArray[$IpmiEntityId_IoModule] } # 4: I/O board sensor
5 { $script:componentTypeArray[$index] = $IpmiEntityIdArray[$IpmiEntityId_PowerSupply] } # 5: Power backplane sensor
default { $script:componentTypeArray[$index] = "" }
}

$index ++
}
}
}
}
}
}

Debug-Out "Number of Temperature Sensors: $index" $DBG_INFO
Select-IpmiClass $index
for ($i=0; $i -lt $index; $i++) {
Debug-Out "Temperature Sensor $($i): '$($script:componentNameArray[$i])' / '$('{0:X2}' -f $script:componentTypeArray[$i])' / '$($script:componentClassArray[$i])', [$($script:componentStatusArray[$i])], Current Value: [$($script:componentInfoArray[$i])]" $DBG_INFO
}

if ($index -gt 0) {
if ($script:insideMP -eq $True) {
for ($i=0; $i -lt $index; $i++) {
# only create property bags for sensors which actually exist
if ($script:componentStatusArray[$i] -ne $STATUS_UNKNOWN) {
$oPropertyBag = $oApi.CreatePropertyBag()

# The server this Temperature Monitor is hosted
$oPropertyBag.AddValue('NetworkName' , $script:TargetComputer)
Debug-Out "oPropertyBag.AddValue: 'NetworkName' = '$($script:TargetComputer)'" $DBG_SCOM

# Properties to identify this Temperature Monitor Instance
$oPropertyBag.AddValue('SensorName' , "$($script:componentNameArray[$i])")
$oPropertyBag.AddValue('SensorType' , "Temperature")
$oPropertyBag.AddValue('SensorClass' , "$($script:componentClassArray[$i])")
$oPropertyBag.AddValue('SensorEntityId' , "$($script:componentTypeArray[$i])")
$oPropertyBag.AddValue('HealthStatus' , "$($script:componentStatusArray[$i])")
$oPropertyBag.AddValue('CurrentValue' , "$($script:componentInfoArray[$i])") # Actual Performance Monitor Value in &#xFFFD;C ...

$Fahrenheit = [int](32 + ( [convert]::ToDouble($script:componentInfoArray[$i] * 9/5) ) )
$oPropertyBag.AddValue('NonMetricValue' , "$Fahrenheit") # Actual Performance Monitor Value in &#xFFFD;F ...

Debug-Out "oPropertyBag.AddValue: 'SensorName' = '$($script:componentNameArray[$i])'" $DBG_SCOM
Debug-Out "oPropertyBag.AddValue: 'SensorType' = 'PowerConsumption'" $DBG_SCOM
Debug-Out "oPropertyBag.AddValue: 'SensorClass' = '$($script:componentClassArray[$i])'" $DBG_SCOM
Debug-Out "oPropertyBag.AddValue: 'SensorEntityId' = '$($script:componentTypeArray[$i])'" $DBG_SCOM
Debug-Out "oPropertyBag.AddValue: 'HealthStatus' = '$($script:componentStatusArray[$i])'" $DBG_SCOM
Debug-Out "oPropertyBag.AddValue: 'CurrentValue' = '$($script:componentInfoArray[$i])'" $DBG_SCOM
Debug-Out "oPropertyBag.AddValue: 'NonMetricValue' = '$Fahrenheit'" $DBG_SCOM

# return each property bag when it is created
#$oAPI.Return($oPropertyBag)
$oPropertyBag
#Debug-Out "" $DBG_INFO
}
}
}
} else {
Debug-Out "***** Found no Temperature Sensors for Performance Monitoring *****" $DBG_INFO
} #********** End of Temperature Sensors


# Power Consumption
#-----------------------------
$index = 0
if ($script:CIMProvider -eq $True) {
$SVAgentClass = "SVS_PGYPowerConsumptionSensor"
$CimData = Get-CimQuery -Query "SELECT * FROM $SVAgentClass" -Namespace $SVNamespace

if ($script:WMIInstanceValid -eq $True) {
foreach ($objItem in $CimData) {
$script:componentNameArray[$index] = $objItem.ElementName
$script:componentTypeArray[$index] = [convert]::ToInt32(($objItem.DeviceID -Split "-")[1], 16)
#$script:componentTypeArray[$index] = [convert]::ToInt32(($objItem.DeviceID.Split("-"))[1], 16)
$script:componentClassArray[$index] = ""
$script:componentStatusArray[$index] = $script:CIM_HealthState[$objItem.HealthState]
$script:componentInfoArray[$index] = $objItem.CurrentReading
Debug-Out "\$($SVNamespace):$SVAgentClass.ElementName: $($objItem.ElementName)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.DeviceID: $($objItem.DeviceID)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.HealthState: $($objItem.HealthState)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.CurrentState: $($objItem.CurrentState)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.CurrentReading: $($objItem.CurrentReading)" $DBG_DESC

$DevCabinet = [convert]::ToInt32(($objItem.DeviceID -Split "-")[0], 16)
$DevIndex = [convert]::ToInt32(($objItem.DeviceID -Split "-")[2], 16)
#$DevCabinet = [convert]::ToInt32(($objItem.DeviceID.Split("-"))[0], 16)
#$DevIndex = [convert]::ToInt32(($objItem.DeviceID.Split("-"))[2], 16)

$script:componentNameArray[$index] = "$('{0:X}' -f $DevCabinet)/$('{0:X}' -f $script:componentTypeArray[$index])/$DevIndex $($script:componentNameArray[$index])"

Debug-Out "Power Consumption Sensor $($index): '$($script:componentNameArray[$index])' / '$($objItem.DeviceID)'" $DBG_INFO
if ([string]::IsNullOrEmpty($objItem.CurrentReading) -or $objItem.CurrentReading -eq 0) {
Debug-Out "Skipping Power Consumption Sensor: '$($script:componentNameArray[$index])', got no current reading." $DBG_INFO
} elseif (($objItem.DeviceID -Split "-")[1] -eq "17" -and ($objItem.DeviceID -Split "-")[2] -eq "1") {
#} elseif (($objItem.DeviceID.Split("-"))[1] -eq "17" -and ($objItem.DeviceID.Split("-"))[2] -eq "1") {
Debug-Out "Skipping Power Consumption Sensor: '$($script:componentNameArray[$index])', Chassis Power-Out sensor" $DBG_INFO
} elseif (($objItem.DeviceID -Split "-")[1] -eq "e0" -and ($objItem.DeviceID -Split "-")[2] -eq "1") {
#} elseif (($objItem.DeviceID.Split("-"))[1] -eq "e0" -and ($objItem.DeviceID.Split("-"))[2] -eq "1") {
Debug-Out "Skipping Power Consumption Sensor: '$($script:componentNameArray[$index])', Node Power-Out sensor" $DBG_INFO
} else {
for ($SCCIIndex = 1; $SCCIIndex -lt $IpmiEntityIdArray.Length; $SCCIIndex ++) {
if ([convert]::ToInt32(($objItem.DeviceID -Split "-")[1], 16) -eq $IpmiEntityIdArray[$SCCIIndex]) {
#if ([convert]::ToInt32(($objItem.DeviceID.Split("-"))[1], 16) -eq $IpmiEntityIdArray[$SCCIIndex]) {
$script:componentTypeArray[$index] = $IpmiEntityIdArray[$SCCIIndex]
break
}
}
$index ++
}
}
}

$SVAgentClass = "SVS_PGYPowerProductionSensor"
$CimData = Get-CimQuery -Query "SELECT * FROM $SVAgentClass" -Namespace $SVNamespace

$DevCabinet = 0
$DevIndex = 0
if ($script:WMIInstanceValid -eq $True) {
foreach ($objItem in $CimData) {
$script:componentNameArray[$index] = $objItem.ElementName
$script:componentTypeArray[$index] = $IpmiEntityIdArray[$IpmiEntityId_PowerSupply]
$script:componentClassArray[$index] = ""
$script:componentStatusArray[$index] = $script:CIM_HealthState[$objItem.HealthState]
$script:componentInfoArray[$index] = $objItem.CurrentReading
Debug-Out "\$($SVNamespace):$SVAgentClass.ElementName: $($objItem.ElementName)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.DeviceID: $($objItem.DeviceID)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.HealthState: $($objItem.HealthState)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.CurrentState: $($objItem.CurrentState)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.CurrentReading: $($objItem.CurrentReading)" $DBG_DESC

$DevCabinet = [convert]::ToInt32(($objItem.DeviceID -Split "-")[0], 16)
$DevIndex = [convert]::ToInt32(($objItem.DeviceID -Split "-")[1], 16)
#$DevCabinet = [convert]::ToInt32(($objItem.DeviceID.Split("-"))[0], 16)
#$DevIndex = [convert]::ToInt32(($objItem.DeviceID.Split("-"))[1], 16)

$script:componentNameArray[$index] = "$('{0:X}' -f $DevCabinet)/$('{0:X}' -f $script:componentTypeArray[$index])/$DevIndex $($script:componentNameArray[$index])"

Debug-Out "Power Production Sensor $($index): '$($script:componentNameArray[$index])' / '$($objItem.DeviceID)'" $DBG_INFO
if ([string]::IsNullOrEmpty($objItem.CurrentReading) -or $objItem.CurrentReading -eq 0) {
Debug-Out "Skipping Power Production Sensor: '$($script:componentNameArray[$index])', got no current reading." $DBG_INFO
} elseif (($objItem.DeviceID -Split "-")[1] -eq "17" -and ($objItem.DeviceID -Split "-")[2] -eq "1") {
#} elseif (($objItem.DeviceID.Split("-"))[1] -eq "17" -and ($objItem.DeviceID.Split("-"))[2] -eq "1") {
Debug-Out "Skipping Power Production Sensor: '$($script:componentNameArray[$index])', Chassis Power-Out sensor" $DBG_INFO
} elseif (($objItem.DeviceID -Split "-")[1] -eq "e0" -and ($objItem.DeviceID -Split "-")[2] -eq "1") {
#} elseif (($objItem.DeviceID.Split("-"))[1] -eq "e0" -and ($objItem.DeviceID.Split("-"))[2] -eq "1") {
Debug-Out "Skipping Power Production Sensor: '$($script:componentNameArray[$index])', Node Power-Out sensor" $DBG_INFO
} else {
for ($SCCIIndex = 1; $SCCIIndex -lt $IpmiEntityIdArray.Length; $SCCIIndex ++) {
if ([convert]::ToInt32(($objItem.DeviceID -Split "-")[1], 16) -eq $IpmiEntityIdArray[$SCCIIndex]) {
#if ([convert]::ToInt32(($objItem.DeviceID.Split("-"))[1], 16) -eq $IpmiEntityIdArray[$SCCIIndex]) {
$script:componentTypeArray[$index] = $IpmiEntityNameArray[$SCCIIndex]
break
}
}
$index ++
}
}
}
} else {
foreach ($cab in $script:CabinetArray) {
if ($Null -ne $cab) {
for ($SCCIIndex = 1; $SCCIIndex -lt $IpmiEntityIdArray.Length; $SCCIIndex ++) {
$PCIndex = 0
$Status = $script:oSwitch.ScciQuery(0x0531, $IpmiEntityIdArray[$SCCIIndex], 0, $cab, 0, [REF]$PCIndex, 0)
if ($Status -ne 0) {
# this SCCI value does not exist
Debug-Out "oSwitch: No Data for opCode=0x$('{0:X}' -f 0x0531) opCodeExt=0x$('{0:X}' -f $IpmiEntityIdArray[$SCCIIndex]) objIndex=0 cabID=$cab" $DBG_DESC
$PCIndex = 0
} else {
Debug-Out "Get-ScciData: opCode=0x$('{0:X}' -f 0x0531) opCodeExt=0x$('{0:X}' -f $IpmiEntityIdArray[$SCCIIndex]) objIndex=0 cabID=$cab -&gt; PCIndex = '$PCIndex'" $DBG_DESC
}
Debug-Out "Number of Power Consumption Sensors of class '$($IpmiEntityNameArray[$SCCIIndex])' (0x$('{0:X2}' -f $IpmiEntityIdArray[$SCCIIndex])): $PCIndex" $DBG_INFO

for ($i=0; $i -lt $PCIndex; $i++) {
$script:componentTypeArray[$index] = $IpmiEntityIdArray[$SCCIIndex]
$script:componentClassArray[$index] = ""
$script:componentNameArray[$index] = Get-ScciData 0x0532 $IpmiEntityIdArray[$SCCIIndex] $i $cab
$script:componentStatusArray[$index] = Get-ScciData 0x534 $IpmiEntityIdArray[$SCCIIndex] $i $cab
$script:componentInfoArray[$index] = Get-ScciData 0x533 $IpmiEntityIdArray[$SCCIIndex] $i $cab

$script:componentNameArray[$index] = "$('{0:X}' -f $cab)/$('{0:X}' -f $IpmiEntityIdArray[$SCCIIndex])/$i $($script:componentNameArray[$index])"

if ($Null -eq $script:componentInfoArray[$index] -or $script:componentInfoArray[$index] -eq 0) {
Debug-Out "Skipping Power Consumption Sensor: '$($script:componentNameArray[$index])', got no current reading." $DBG_INFO
} elseif ($IpmiEntityIdArray[$SCCIIndex] -eq 0x17 -and $i -eq 1) {
Debug-Out "Skipping Power Consumption Sensor: '$($script:componentNameArray[$index])', Chassis Power-Out sensor" $DBG_INFO
} elseif ($IpmiEntityIdArray[$SCCIIndex] -eq 0xE0 -and $i -eq 1) {
Debug-Out "Skipping Power Consumption Sensor: '$($script:componentNameArray[$index])', Node Power-Out sensor" $DBG_INFO
} else {
# the 'inner' sensors do not supply an individual health state
if ($Null -eq $script:componentStatusArray[$index]) {
$script:componentStatusArray[$index] = $STATUS_OK
} else {
switch ($script:componentStatusArray[$index]) {
0 { $script:componentStatusArray[$index] = $STATUS_OK } # Power consumption within limit
1 { $script:componentStatusArray[$index] = $STATUS_WARNING } # Power consumption above warning threshold
2 { $script:componentStatusArray[$index] = $STATUS_Error } # Power consumption above limit
3 { $script:componentStatusArray[$index] = $STATUS_OK } # Power consumption limiting disabled
default { $script:componentStatusArray[$index] = $STATUS_UNKNOWN }
}
}
$index ++
}
}
}
}
}
}

Debug-Out "Number of Power Consumption Sensors: $index" $DBG_INFO
Select-IpmiClass $index
for ($i=0; $i -lt $index; $i++) {
Debug-Out "Power Consumption Sensor $($i): '$($script:componentNameArray[$i])' / '$('{0:X2}' -f $script:componentTypeArray[$i])' / '$($script:componentClassArray[$i])', [$($script:componentStatusArray[$i])], Current Value: [$($script:componentInfoArray[$i])]" $DBG_INFO
}

if ($index -gt 0) {
if ($script:insideMP -eq $True) {
for ($i=0; $i -lt $index; $i++) {
if ($script:componentStatusArray[$i] -ne $STATUS_UNKNOWN) {
$oPropertyBag = $oApi.CreatePropertyBag()

# The server this Power Consumption Monitor is hosted
$oPropertyBag.AddValue('NetworkName' , $script:TargetComputer)
Debug-Out "oPropertyBag.AddValue: 'NetworkName' = '$($script:TargetComputer)'" $DBG_SCOM

# Properties to identify this Power Consumption Monitor Instance
$oPropertyBag.AddValue('SensorName' , "$($script:componentNameArray[$i])")
$oPropertyBag.AddValue('SensorType' , "PowerConsumption")
$oPropertyBag.AddValue('SensorClass' , "$($script:componentClassArray[$i])")
$oPropertyBag.AddValue('SensorEntityId' , "$($script:componentTypeArray[$i]) ")
$oPropertyBag.AddValue('HealthStatus' , "$($script:componentStatusArray[$i])")
$oPropertyBag.AddValue('CurrentValue' , "$($script:componentInfoArray[$i])") # Actual Performance Monitor Value in Watt ...

$BtuValue = [int](32 + ( [convert]::ToDouble($script:componentInfoArray[$i] * 3.413) ) )
$oPropertyBag.AddValue('NonMetricValue' , "$BtuValue") # Actual Performance Monitor Value in BTU/h ...

Debug-Out "oPropertyBag.AddValue: 'SensorName' = '$($script:componentNameArray[$i])'" $DBG_SCOM
Debug-Out "oPropertyBag.AddValue: 'SensorType' = 'PowerConsumption'" $DBG_SCOM
Debug-Out "oPropertyBag.AddValue: 'SensorClass' = '$($script:componentClassArray[$i])'" $DBG_SCOM
Debug-Out "oPropertyBag.AddValue: 'SensorEntityId' = '$($script:componentTypeArray[$i])'" $DBG_SCOM
Debug-Out "oPropertyBag.AddValue: 'HealthStatus' = '$($script:componentStatusArray[$i])'" $DBG_SCOM
Debug-Out "oPropertyBag.AddValue: 'CurrentValue' = '$($script:componentInfoArray[$i])'" $DBG_SCOM
Debug-Out "oPropertyBag.AddValue: 'NonMetricValue' = '$($BtuValue)'" $DBG_SCOM

# return each property bag when it is created
#$oAPI.Return($oPropertyBag)
$oPropertyBag
#Debug-Out "" $DBG_INFO
}
}
}
} else {
Debug-Out "***** Found no Power Consumption Sensors for Performance Monitoring *****" $DBG_INFO
} #********** End of Power Consumption Sensors

Debug-Out "***** Normal end of script. *****" $DBG_INFO
exit 0
} # End Of "Main()"

#----------------------------------------------------------------

function Select-IpmiClass
{
param (
$index
)

# sort into IPMI EntityIds
for ($i=0; $i -lt $index; $i++) {
# create specific class for Memory and SystemBoard modules
if ($script:componentNameArray[$i] -like "*MEM*") {
$script:componentTypeArray[$i] = $IpmiEntityIdArray[$IpmiEntityId_Memory] # Memory
} elseif ($script:componentNameArray[$i] -like "*DIMM*") {
$script:componentTypeArray[$i] = $IpmiEntityIdArray[$IpmiEntityId_Memory] # Memory
} elseif ($script:componentNameArray[$i] -like "*Systemboard*") {
$script:componentTypeArray[$i] = $IpmiEntityIdArray[$IpmiEntityId_System] # SystemBoard
}

# try to match to IPMI Entity IDs where none was supplied
if ($script:componentTypeArray[$i] -eq "") {
if ($script:componentNameArray[$i] -like "*CPU*") {
$script:componentTypeArray[$i] = $IpmiEntityIdArray[$IpmiEntityId_Processor] # 1: CPU sensor
} elseif ($script:componentNameArray[$i] -like "*Ambient*") {
$script:componentTypeArray[$i] = $IpmiEntityIdArray[$IpmiEntityId_AirInlet] # 2: Ambient (outside temperature) sensor
} elseif ($script:componentNameArray[$i] -like "*Front*") {
$script:componentTypeArray[$i] = $IpmiEntityIdArray[$IpmiEntityId_AirInlet] # 2: Ambient (outside temperature) sensor
} elseif ($script:componentNameArray[$i] -like "*Mezz*") {
$script:componentTypeArray[$i] = $IpmiEntityIdArray[$IpmiEntityId_IoModule] # 4: I/O board sensor
} elseif ($script:componentNameArray[$i] -like "*Monitor*") {
$script:componentTypeArray[$i] = $IpmiEntityIdArray[$IpmiEntityId_IoModule] # 4: I/O board sensor
} elseif ($script:componentNameArray[$i] -like "*IO*") {
$script:componentTypeArray[$i] = $IpmiEntityIdArray[$IpmiEntityId_IoModule] # 4: I/O board sensor
} elseif ($script:componentNameArray[$i] -like "*RAID*") {
$script:componentTypeArray[$i] = $IpmiEntityIdArray[$IpmiEntityId_IoModule] # 4: I/O board sensor
} elseif ($script:componentNameArray[$i] -like "*PSU*") {
$script:componentTypeArray[$i] = $IpmiEntityIdArray[$IpmiEntityId_PowerSupply] # 5: Power backplane sensor
} elseif ($script:componentNameArray[$i] -like "*Disk*") {
$script:componentTypeArray[$i] = $IpmiEntityIdArray[$IpmiEntityId_HardDisk] # HDD
} elseif ($script:componentNameArray[$i] -like "*HDD*") {
$script:componentTypeArray[$i] = $IpmiEntityIdArray[$IpmiEntityId_HardDisk] # HDD
} else {
$script:componentTypeArray[$i] = $IpmiEntityIdArray[$IpmiEntityId_AddInCard] # 3: In-housing sensor
}
}
}

# determine class from IPMI EntityId
for ($i=0; $i -lt $index; $i++) {
switch ($script:componentTypeArray[$i]) {
$IpmiEntityIdArray[$IpmiEntityId_AirInlet] { $script:componentClassArray[$i] = $IpmiEntityNameArray[$IpmiEntityId_AirInlet] } # Ambient / AirInlet
$IpmiEntityIdArray[$IpmiEntityId_Processor] { $script:componentClassArray[$i] = $IpmiEntityNameArray[$IpmiEntityId_Processor] } # Processor
$IpmiEntityIdArray[$IpmiEntityId_Memory] { $script:componentClassArray[$i] = $IpmiEntityNameArray[$IpmiEntityId_Memory] } # Memory
$IpmiEntityIdArray[$IpmiEntityId_System] { $script:componentClassArray[$i] = $IpmiEntityNameArray[$IpmiEntityId_System] } # SystemBoard
$IpmiEntityIdArray[$IpmiEntityId_SystemChassis] { $script:componentClassArray[$i] = $IpmiEntityNameArray[$IpmiEntityId_SystemChassis] } # SystemChassis
$IpmiEntityIdArray[$IpmiEntityId_PowerSupply] { $script:componentClassArray[$i] = $IpmiEntityNameArray[$IpmiEntityId_PowerSupply] } # PowerSupply
$IpmiEntityIdArray[$IpmiEntityId_Total] { $script:componentClassArray[$i] = $IpmiEntityNameArray[$IpmiEntityId_Total] } # Total Power
default { $script:componentClassArray[$i] = $IpmiEntityNameArray[$IpmiEntityId_Other] } # Other
}
}
}

#................................................................
#-------------------------------------------------------------------
# SCOM.ps1
#-------------------------------------------------------------------

Set-Variable -Name cMAXINDEX -Option Constant -Value 196
$script:componentNameArray = @("") * $cMAXINDEX
$script:componentStatusArray = @("") * $cMAXINDEX
$script:componentInfoArray = @("") * $cMAXINDEX
$script:componentName = ""
$script:componentStatus = ""
$script:componentInfo = ""

Set-Variable -Name PROCESSOR -Option Constant -Value 0
Set-Variable -Name MEMORY -Option Constant -Value 1
Set-Variable -Name STORAGE -Option Constant -Value 2
Set-Variable -Name NETWORK -Option Constant -Value 3
Set-Variable -Name MGMTCTRL -Option Constant -Value 4
Set-Variable -Name FANS -Option Constant -Value 5
Set-Variable -Name TEMPERATURE -Option Constant -Value 6
Set-Variable -Name VOLTAGES -Option Constant -Value 7
Set-Variable -Name POWERSUPPLY -Option Constant -Value 8
Set-Variable -Name POWERCONSUMP -Option Constant -Value 9
Set-Variable -Name RAIDSUBSYSTEM -Option Constant -Value 10
Set-Variable -Name PHYSICALDISK -Option Constant -Value 11
Set-Variable -Name LOGICALDRIVE -Option Constant -Value 12
Set-Variable -Name DRIVERMONITOR -Option Constant -Value 13 # currently not supported subsystem
Set-Variable -Name PCISLOTS -Option Constant -Value 14 # currently not supported subsystem
Set-Variable -Name OTHER -Option Constant -Value 15 # make sure this is the last subsystem
# continue with specific components
Set-Variable -Name SVOVERALL -Option Constant -Value 16
Set-Variable -Name SVVERSION -Option Constant -Value 17
Set-Variable -Name SELFTEST -Option Constant -Value 18
Set-Variable -Name TPMMODULE -Option Constant -Value 19
Set-Variable -Name RAIDOVERALL -Option Constant -Value 20
Set-Variable -Name RAIDVERSION -Option Constant -Value 21 # make sure this is the last component

$script:ComponentsList = @("Processors", "Memory", "Storage", "Networks (Ethernet)", "Management Controller",
"Fans (Cooling)", "Temperatures", "Voltages", "Power Supplies", "Power Consumption",
"RAID Subsystem", "RAID Physical Disks", "RAID Logical Drives", "Driver Monitor", "PCI Slots", "Other Components"
"SV OverallState", "SV Agents Version", "Bios Selftest", "TPM Module", "Raid OverallState", "Raid Version")
$script:ComponentsStateList = @("Processors", "Memory", "Storage", "Networks", "ManagementController",
"Fans", "TemperatureSensors", "VoltageSensors", "PowerSupplies", "PowerConsumption",
"RaidSubsystem", "RaidPhysicalDisks", "RaidLogicalDrives", "DriverMonitor", "PCISlots", "OtherComponents",
"SVOverallState", "SVAgentsVersion", "BiosSelftest", "TPMModule", "RaidOverallState", "RaidVersion")

Set-Variable -Name STATUS_NONE -Option Constant -Value "None"
Set-Variable -Name STATUS_ERROR -Option Constant -Value "Error"
Set-Variable -Name STATUS_DEGRADED -Option Constant -Value "Degraded"
Set-Variable -Name STATUS_OK -Option Constant -Value "OK"
Set-Variable -Name STATUS_UNKNOWN -Option Constant -Value "Unknown"
Set-Variable -Name STATUS_NOTPRESENT -Option Constant -Value "Not Present"
Set-Variable -Name STATUS_NOTMANAGEABLE -Option Constant -Value "Not Manageable"
Set-Variable -Name STATUS_INVALID -Option Constant -Value "Invalid"
Set-Variable -Name STATUS_COMMERR -Option Constant -Value "Communication Error"
Set-Variable -Name STATUS_NOSTATE -Option Constant -Value "No State"

$script:CIM_HealthState = @($STATUS_UNKNOWN) * 26
$script:CIM_HealthState[0] = $STATUS_UNKNOWN # Unknown
$script:CIM_HealthState[5] = $STATUS_OK # OK
$script:CIM_HealthState[10] = $STATUS_DEGRADED # Minor Failure
$script:CIM_HealthState[15] = $STATUS_DEGRADED # Major Failure
$script:CIM_HealthState[20] = $STATUS_ERROR # Critical Failure
$script:CIM_HealthState[25] = $STATUS_ERROR # Non-recoverable Error

#................................................................

#-------------------------------------------------------------------
# DataRequest.ps1
#-------------------------------------------------------------------

Set-Variable -Name SVAGENTVERSION_MIN -Option Constant -Value "7.00.00"
Set-Variable -Name SVCIMVERSION_MIN -Option Constant -Value "8.00.00"
Set-Variable -Name CIMRAID_AGENTS_MIN -Option Constant -Value "8.00.00"

Set-Variable -Name SVRAIDVERSION_BASE -Option Constant -Value "3.1.4"
Set-Variable -Name SVRAIDVERSION_MIN -Option Constant -Value "6.0.3"
Set-Variable -Name CIMRAID_SVRAID_MIN -Option Constant -Value "6.4.11"

Set-Variable -Name SCCISLEEPTIME -Option Constant -Value 100
Set-Variable -Name wmiRetries -Option Constant -Value 5
Set-Variable -Name waitTimeMin -Option Constant -Value 100
Set-Variable -Name waitTimeMax -Option Constant -Value 1000

Set-Variable -Name cimv2NS -Option Constant -Value "root\cimv2"
Set-Variable -Name svsNS -Option Constant -Value "root\svs"

$script:WMIInstanceValid = $False
$script:oSwitch = $Null

#----------------------------------------------------------------

# query CIM Data
function Get-CimQuery
{
param (
[string]$Query,
[string]$Namespace
)

$script:WMIInstanceValid = $False
try {
if ($PSVersion.Major -ge 4) {
Debug-Out "Get-CimInstance -Query $Query -Namespace $Namespace" $DBG_DESC
$WmiData = @(Get-CimInstance -Query $Query -Namespace $Namespace -ErrorAction Stop)
} else {
Debug-Out "Get-WMIObject -Query '$Query' -Namespace '$Namespace'" $DBG_DESC
$WmiData = @(Get-WMIObject -Query $Query -Namespace $Namespace -ErrorAction Stop)
}
$WmiObjCount = $WmiData.Count

if ($WmiObjCount -ne 0) {
$script:WMIInstanceValid = $True
Debug-Out "'$Query' successfully delivered $WmiObjCount objects" $DBG_DESC
} else {
$script:WMIInstanceValid = $False
Debug-Out "'$Query' was successful but did not deliver any data. Reset WmiData object." $DBG_DESC
$WmiData = $Null
}
} catch [Exception] {
Debug-Out "Exception when requesting '$Query' from '$Namespace'." $DBG_DESC
Debug-Out "ErrorMessage: $($_.Exception.Message)" $DBG_DESC
}

return $WmiData
}

#----------------------------------------------------------------

# get ServerView Overall State
function Get-SVOverallState
{
$SVSStateOK = $True
if ($script:CIMProvider -eq $True) {
$CimData = Get-CimQuery -Query "SELECT * FROM SVS_PGYHealthStateComponent WHERE ElementName = 'System'" -Namespace "root/svs"
if ($script:WMIInstanceValid -eq $True) {
Debug-Out "\root/svs:SVS_PGYHealthStateComponent.Presence: $($CimData.Presence)" $DBG_DESC
# Anything but 1 (Present) here indicates a problem with CIM Providers (caused by test automation most likely). Abort.
if ($CimData.Presence -ne 1) {
$SVSStateOK = $False
}
}
} else {
# Anything but 1 (OK) or 2 (Warning) or 3 (Error) here indicates a problem with CIM Providers (caused by test automation most likely). Abort.
$SVSState = Get-ScciData 0x2333 0 0 -1
if ($SVSState -ne 1 -and $SVSState -ne 2 -and $SVSState -ne 3) {
$SVSStateOK = $False
}
}

return $SVSStateOK
}

#----------------------------------------------------------------

function Get-ScciData
{
param (
[int]$opCode,
[int]$opCodeExt,
[int]$objIndex,
[int]$cabID
)

$scciValue = $Null

if ($script:SVAgentRunning -eq $True) {
$Status = $script:oSwitch.ScciQuery($opCode, $opCodeExt, $objIndex, $cabID, 0, [REF]$scciValue, 0)
if ($Status -ne 0) {
Debug-Out "GetScciData: No Data for opCode=0x$('{0:X4}' -f $opCode) opCodeExt=0x$('{0:X}' -f $opCodeExt) objIndex=$objIndex cabID=$cabID" $DBG_DESC
$scciValue = $Null
} else {
if ($scciValue -is [system.array]) {
Debug-Out "GetScciData: opCode=0x$('{0:X4}' -f $opCode) opCodeExt=0x$('{0:X}' -f $opCodeExt) objIndex=$objIndex cabID=$cabID -&gt; scciValue = '[$scciValue]'" $DBG_DESC
} else {
Debug-Out "GetScciData: opCode=0x$('{0:X4}' -f $opCode) opCodeExt=0x$('{0:X}' -f $opCodeExt) objIndex=$objIndex cabID=$cabID -&gt; scciValue = '$scciValue'" $DBG_DESC
}
}
} else {
$scciValue = $Null
}

return $scciValue
}

#................................................................

#-------------------------------------------------------------------
# Logging.ps1
#-------------------------------------------------------------------

$script:MPVERSION = "8.5.0.0"

#DebugLevel options are defined in bits and may be combined using binary Or
Set-Variable -Name DBG_NO -Option Constant -Value 0 # 0000: print no debug lines
Set-Variable -Name DBG_INFO -Option Constant -Value 1 # 0001: print informational debug lines
Set-Variable -Name DBG_DATA -Option Constant -Value 2 # 0010: print SCCI/CIM data related debug lines
Set-Variable -Name DBG_DESC -Option Constant -Value 4 # 0100: print lines relevant for documentation document
Set-Variable -Name DBG_SCOM -Option Constant -Value 8 # 1000: print SCOM related information
Set-Variable -Name DBG_ALL -Option Constant -Value 3 # 0011: standard output

$script:DebugMode = $False
$script:DebugFile = $False
$script:DebugLevel = ""
$script:DebugTest = ""
$script:DebugOverWrite = $True
if (-not [string]::IsNullOrEmpty($DbgLevel) -and ($DbgLevel -match '^\d+$')) { $script:DebugLevel = [convert]::ToInt32($DbgLevel, 10) }
if (-not [string]::IsNullOrEmpty($DbgTest)) { $script:DebugTest = "$DbgTest".ToUpper() }

Set-Variable -Name SVISCOMLogBase -Option Constant -Value "SVISCOM"
Set-Variable -Name SVISCOMLogPath -Option Constant -Value "SVISCOM-Win"
Set-Variable -Name SVISCOMLogIniName -Option Constant -Value "SVISCOMLog.ini"
Set-Variable -Name SVISCOMLogIn_Name -Option Constant -Value "SVISCOMLog.in_"
$script:LogFileDirBase = ""
$script:LogFileDir = ""
$script:SVISCOMLogIni = ""
$script:SVISCOMLogIn_ = ""
$script:LogFilePath = ""
$script:lineCounter = 0

Set-Variable -Name SEC_PerfMonMonitor -Option Constant -Value "[PerfMonMonitor]"
Set-Variable -Name STR_DBGMODE -Option Constant -Value "DebugMode"
Set-Variable -Name STR_OVERWRITE -Option Constant -Value "OverWrite"
Set-Variable -Name STR_DBGLEVEL -Option Constant -Value "DebugLevel"
Set-Variable -Name STR_DBGTEST -Option Constant -Value "DebugTest"

#-------------------------------------------------------------------

function Initialize-Logging
{
param (
$SectionIni,
$Component
)

# get the system environment variable TEMP (usually: C:\Windows\TEMP), depending on e.g. partition
$TEMP = $Env:TEMP
$SYSTEMDRIVE = $Env:SYSTEMDRIVE

$script:LogFileDirBase = "$TEMP\$SVISCOMLogBase"
$script:LogFileDir = "$TEMP\$SVISCOMLogBase\$SVISCOMLogPath"
$script:SVISCOMLogIni = "$LogFileDir\$SVISCOMLogIniName"
$script:SVISCOMLogIn_ = "$LogFileDir\$SVISCOMLogIn_Name"
if ($script:MGMGroup -ne "") {
$script:LogFileFullName = "$($LogFileName)_$($script:TargetComputer)_$($script:MGMGroup).log"
} else {
$script:LogFileFullName = "$($LogFileName)_$($script:TargetComputer).log"
}
$script:LogFilePath = "$LogFileDir\$($script:LogFileFullName)"

# get setting for DebugMode and DebugFile
if ($script:DebugMode -eq $False) {
Get-LogFileIni $SVISCOMLogIni $SectionIni
# Default DebugLevel: All
if ("$($script:DebugLevel)" -eq "" -and $script:DebugMode -eq $True) { $script:DebugLevel = $DBG_ALL }
}
if ($script:DebugMode -eq $True) { $script:DebugFile = $True }

Debug-Out "TEMP = $TEMP" $DBG_INFO
Debug-Out "SYSTEMDRIVE = $SYSTEMDRIVE" $DBG_INFO
Debug-Out "LogFileDirBase = $($script:LogFileDirBase)" $DBG_INFO
Debug-Out "LogFileDir = $($script:LogFileDir)" $DBG_INFO
Debug-Out "SVISCOMLogIni = $($script:SVISCOMLogIni)" $DBG_INFO
Debug-Out "SVISCOMLogIn_ = $($script:SVISCOMLogIn_)" $DBG_INFO
Debug-Out "TargetComputer = $($script:TargetComputer)" $DBG_INFO
Debug-Out "LogFileName = $LogFileName" $DBG_INFO
Debug-Out "LogFilePath = $($script:LogFilePath)" $DBG_INFO
Debug-Out "DebugMode = $($script:DebugMode)" $DBG_INFO
Debug-Out "OverWrite = $($script:DebugOverWrite)" $DBG_INFO
Debug-Out "DebugLevel = $($script:DebugLevel)" $DBG_INFO
Debug-Out "DebugTest = $($script:DebugTest)" $DBG_INFO

# PerfMon MP is not allow to do 'new MP' stuff

if ($script:DebugFile -eq $True) {
Initialize-LogFile
}
}

#----------------------------------------------------------------

function Initialize-LogFile
{
$startTime = Get-Date -format "yyyy-MM-dd HH:mm:ss"
$script:lineCounter = 0

$sMessage = "`r`n********** $startTime **********`r`n********** $($script:LogFilePath) **********"
$sMPVersion = "MP Version: *** $($MPVersion) ***`r`n"

if (Test-Path -Path $script:LogFilePath) {
Debug-Out "Log file exists at: $($script:LogFilePath)" $DBG_INFO
if ($script:DebugOverWrite -eq $True) {
Remove-Item -Path $script:LogFilePath -Force | Out-Null
}
}

if (-not (Test-Path -Path $script:LogFilePath)) {
New-Item -Path $script:LogFilePath -ItemType File | Out-Null
}

try {
if (Test-Path -Path $script:LogFileDir -ErrorAction Stop) {
Debug-Out "Log file folder exists at: $($script:LogFileDir)" $DBG_INFO
} else {
Debug-Out "Create log file folder at: $($script:LogFileDir)" $DBG_INFO
$Null = New-Item -Path $script:LogFileDir -ItemType Directory -ErrorAction Stop
}
} catch {
Debug-Out "Could not access log file folder: $($script:LogFileDir). Abort Logging." $DBG_INFO
$script:DebugMode = $False
$script:DebugFile = $False
}

Add-Content -Path $script:LogFilePath -Value $sMessage
Add-Content -Path $script:LogFilePath -Value $sMPVersion
}


#----------------------------------------------------------------

function Get-LogFileIni
{
param (
[string] $FilePathName,
[string] $Section
)

if (Test-Path -Path $FilePathName) {
Debug-Out "Get INI file values from '$FilePathName', section '$Section'" $DBG_INFO
$thisVal = $(Get-IniValue $FilePathName $Section $STR_DBGMODE).ToUpper()
if (($thisVal -ne "") -and
($thisVal -eq "YES" -or $thisVal -eq "TRUE" -or $thisVal -eq "1")) {
$script:DebugMode = $True
$script:DebugFile = $True
}

$thisVal = $(Get-IniValue $FilePathName $Section $STR_OVERWRITE).ToUpper()
if (($thisVal -ne "") -and
($thisVal -eq "NO" -or $thisVal -eq "FALSE" -or $thisVal -eq "0")) {
$script:DebugOverWrite = $False
}

$thisVal = $(Get-IniValue $FilePathName $Section $STR_DBGLEVEL).ToUpper()
#if (($script:DebugLevel -eq "" -or $script:DebugLevel -eq 0) -and
# ($thisVal -ne "" -and $thisVal -match '^\d+$')) {
if ($script:DebugLevel -eq "" -and $thisVal -ne "") {
$script:DebugLevel = $thisVal
} else {
#Debug-Out "DebugLevel '$thisVal' is NO number. Ignore." $DBG_INFO
}

$thisVal = $(Get-IniValue $FilePathName $Section $STR_DBGTEST).ToUpper()
if ($script:DebugTest -eq "" -and $thisVal -ne "") {
$script:DebugTest = $thisVal
}
} else {
Debug-Out "INI file '$FilePathName' does not exist." $DBG_INFO
}
}

#----------------------------------------------------------------

function Get-IniValue
{
param (
[string] $FilePathName,
[string] $Section,
[string] $KeyValue
)

$regex = [RegEx]"$KeyValue=(?&lt;Value&gt;.+$)"

# Get file content
$inLines = Get-Content $FilePathName
for ($i = 0; $i -lt $inLines.Length; $i++) {
# ignore comment lines
if (!"$($inLines[$i])".StartsWith(";")) {
# Find section
if ($inLines[$i] -contains "$Section") {
do {
$Res = $regex.Match($inLines[$i])
if ($Res.Success) {
if (!"$($inLines[$i])".StartsWith(";")) {
return $($Res.Groups['Value'].Value)
} else {
return ""
}
break
}
$i++
} until ($i -ge $inLines.Length -or "$($inLines[$i])".Contains("["))
}
}
}

return ""
}

#----------------------------------------------------------------

function Debug-Out
{
param (
[string] $Text,
[int] $Level
)

if ($Level -bAnd $script:DebugLevel) {
if ($script:DebugMode -eq $True) {
Write-Host $Text

if ($script:DebugFile -eq $True) {
if (($script:LogFilePath -ne "") -and (Test-Path -Path $script:LogFilePath)) {
$script:lineCounter++
Add-Content -Path $script:LogFilePath -Value "[$($script:lineCounter)] $(Get-Date -Format "yyyy-MM-dd HH:mm:ss") $Text"
}
}
}
}
}

#................................................................
#-------------------------------------------------------------------
# Utils.ps1
#-------------------------------------------------------------------

$script:SVISCOMName = "SVISCOM-Win"

#-------------------------------------------------------------------

Set-Variable -Name regRootSVUUIDPath -Option Constant -Value "SYSTEM\CurrentControlSet\Control\UUID\C3681B60-0D26-11D3-8319-00A0C9B61E25"
Set-Variable -Name regRootSVAgentsPathname -Option Constant -Value "ServerView Snmp Agents"
$script:SVAgentsPathname = "Pathname"
$script:CIMProvider = $False
$script:SVAgentRunning = $False
$script:SVASRunning = $False
$script:isNano = $False

$script:Cabinet = 0
$script:CabinetArray = @(-1,$Null,$Null,$Null,$Null,$Null)

#-------------------------------------------------------------------

function Get-OSProperty
{
param (
$property
)

$osProperty = ""
try {
$osProperty = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\" -ErrorAction Stop).$Property
} catch {
$osProperty = ""
}
# Debug-Out "OS property $property: $osProperty" $DBG_INFO

return $osProperty
}

#----------------------------------------------------------------

function Get-SVAgentsPath
{
$AgentsPath = ""
try {
$regSVAgentsPath = (Get-ItemProperty "HKLM:\$regRootSVUUIDPath" -ErrorAction Stop).$regRootSVAgentsPathname
$regSVAgentsPath = "$regSVAgentsPath\STATUS_MIB\CurrentVersion"
$AgentsPath = (Get-ItemProperty "HKLM:\$regSVAgentsPath" -ErrorAction Stop).$SVAgentsPathname
} catch {
$AgentsPath = ""
}
# Debug-Out "SV-Agents Path: $AgentsPath" $DBG_INFO

return $AgentsPath
}

#----------------------------------------------------------------

function Get-SVAgentsRunning
{
$AgentsRunning = $False
try {
if ((Get-Service -Name SrvCtrl -ErrorAction Stop).Status -eq "Running") {
$AgentsRunning = $True
}
} catch {
$AgentsRunning = $False
}
# Debug-Out "ServerView Agent Service found running = $AgentsRunning)", DBG_INFO

return $AgentsRunning
}

#................................................................


#-------------------------------------------------------------------
# Main.ps1
#-------------------------------------------------------------------
Main $args
</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>ManagementGroup</Name>
<Value>$Target/ManagementGroup/Name$</Value>
</Parameter>
<Parameter>
<Name>TargetName</Name>
<Value>$Config/TargetName$</Value>
</Parameter>
<Parameter>
<Name>TimeoutSeconds</Name>
<Value>$Config/TimeoutSeconds$</Value>
</Parameter>
<Parameter>
<Name>ScriptName</Name>
<Value>PerfMonMonitor.ps1</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<StrictErrorHandling>$Config/StrictErrorHandling$</StrictErrorHandling>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="Script">
<Node ID="PassThrough"/>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
<TriggerOnly>true</TriggerOnly>
</ProbeActionModuleType>