PowerSupply.DiscoveryRule (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.Discovery.Data

Member Modules:

ID Module Type TypeId RunAs 
DsPowerSupplyPs DataSource Microsoft.Windows.TimedPowerShell.DiscoveryProvider Default

Overrideable Parameters:

IDParameterTypeSelector
IntervalSecondsint$Config/IntervalSeconds$

Source Code:

<DataSourceModuleType ID="PowerSupply.DiscoveryRule" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="IntervalSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="computerName" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DsPowerSupplyPs" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime/>
<ScriptName>DiscoverPowerSupply.PS1</ScriptName>
<ScriptBody><Script>

# **********************************************************************************
# Script Name : DiscoverPowerSupply
# Authored by : MphasiS Corporation
# Description : Discovers Lenovo Servers PowerSupply Properties thru Out-Of Band
#
# Copyright (c) 2013 Lenovo Group. All rights reserved.
# Redistribution and use in source and binary forms, with or without modification,
# is not permitted without specific prior written permission from Lenovo.
# **********************************************************************************
param($sourceId,$managedEntityId,$computerName)

#--------------Inventory Logging--------------#
Function LogEntry($LogContent)
{
Try
{
$LoggingFlag_Reg = (New-Object -ComObject WScript.Shell).RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\LenovoPartnerPack\SCOMServer\Log")
if( $LoggingFlag_Reg -eq 1)
{
$SetLogging = $true
}
else
{
$SetLogging = $false
}
}
Catch
{
$SetLogging = $true
}

if ($SetLogging -eq $true)
{
$LogPath = ${Env:LENOVOPARTNERPACK_HOME} + "\Log"

if(![IO.Directory]::Exists($LogPath))
{
New-Item -ItemType directory -Path $LogPath
}

##$LogFileName = "ThinkServerPartnerPack_Inventory_"+ (Get-Date -Format "dd-MMM-yyyy")+".log"
$LogFileName = "ThinkServerPartnerPack_Inventory.log"
$LogFile = $LogPath + "\" + $LogFileName

$LogTime = Get-Date -Format "dd-MMM-yyyy HH:mm:ss"
$LogEntryContent = $LogTime + " : " + $LogContent

$LogEntryContent | Out-File $LogFile -Append -Force
}
}
#--------------Inventory Logging--------------#

$api = new-object -comObject 'MOM.ScriptAPI'
$discoveryPowerSupply = $api.CreateDiscoveryData(0, $SourceId, $ManagedEntityId)

$SCOMServer_Reg = (New-Object -ComObject WScript.Shell).RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Machine Settings\DefaultSDKServiceMachine")

$LocalHostName = [System.Net.Dns]::GetHostByName('localhost').HostName

IF ($SCOMServer_Reg -eq $LocalHostName)
{
#Import-Module OperationsManager
$ServersList = Get-SCOMClass -Name 'Lenovo.TMM.Server.MP.Host.Class' | Get-SCOMClassInstance | Select *.HostName, *.BMCIP

foreach($Server in $ServersList)
{
$ServerName = $Server.'[Lenovo.TMM.Server.MP.Host.Class].HostName'.Value
$BMCIPAddress = $Server.'[Lenovo.TMM.Server.MP.Host.Class].BMCIP'.Value

$BMCData = Get-SCOMClass -Name 'Lenovo.TMM.Server.MP.LenovoBMC.Class' | Get-SCOMClassInstance | where {$_.DisplayName -eq $ServerName } | Select *.UserName, *.Password
$BMCUserName = $BMCData.'[Lenovo.TMM.Server.MP.LenovoBMC.Class].UserName'.Value
$BMCPassword = $BMCData.'[Lenovo.TMM.Server.MP.LenovoBMC.Class].Password'.Value

#Enc - Code#
$dllPath = ${Env:LENOVOPARTNERPACK_HOME} + "\bin\LenovoCryptoLib.dll"
[Reflection.Assembly]::LoadFile($dllPath)
$EncInstance = New-Object LenovoCryptoLib.LenovoAsymmetricEncryption
$EncInstance.CheckKeyAndSet();
$BMCUserName = $EncInstance.DecryptText($BMCUserName, $EncInstance.PrivateKey, 1024);
$BMCPassword = $EncInstance.DecryptText($BMCPassword, $EncInstance.PrivateKey, 1024);
#Enc - Code#
$JavaFilePath = ${Env:LENOVOPARTNERPACK_HOME}+ '\Lib\jre8\bin\java.exe'
$IsGrantely=$false

if (($BMCUserName -ne $null) -and ($BMCPassword -ne $null))
{
$PowerSupplyJarFilePath = "${Env:LENOVOPARTNERPACK_HOME}"+ "\Lib\VeraxIPMIWrapper.jar"

Try
{
$ServiceId = &amp; $JavaFilePath -jar $PowerSupplyJarFilePath "service-id" $BMCIPAddress $BMCUserName $BMCPassword
if (($ServiceId -ne $null) -and ($ServiceId.Trim() -ne '') -and ($ServiceId.indexof("AMI") -ge 0))
{
$PowerSupplyJarFilePath = "${Env:LENOVOPARTNERPACK_HOME}"+ "\Lib\LenovoHAPI.jar"
$PowerSupplysList = &amp; $JavaFilePath -jar $PowerSupplyJarFilePath "PowerSupply" $BMCIPAddress $BMCUserName $BMCPassword | ConvertFrom-Json
}
else
{
$PowerSupplysList = &amp; $JavaFilePath -jar $PowerSupplyJarFilePath "PowerSupply" $BMCIPAddress $BMCUserName $BMCPassword | ConvertFrom-Json
}
}
Catch
{
LogEntry("Error while fetching Power Supply Unit details using Out of band for "+ $computerName)
}
if ($PowerSupplysList.result.Count -gt 0)
{
foreach ($PowerSupply in $PowerSupplysList.result)
{
if (($PowerSupply.grantelyFlag -eq $true) -and ($PowerSupply.name -notlike "*present" ))
{
$IsGrantely = $true
$instance = $discoveryPowerSupply.CreateClassInstance("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.PowerSupply.Class']$")
$NameOfPowerSupply = $PowerSupply.name
$Description = $PowerSupply.description
if ( $Description.Trim() -eq '' )
{
$Description="Not Available"
}
$PowerSupplyStatus = $PowerSupply.status
if ( ($PowerSupplyStatus -eq "Invalid") -or ($PowerSupplyStatus -eq "Ok") )
{
$PowerSupplyStatus = "Normal"
}
$NameForPowerReading = "Not Available"
$CurrentReading = $PowerSupply.currentReading

$instance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $NameOfPowerSupply)
$instance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $ServerName)
$instance.AddProperty("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.PowerSupply.Class']/Description$", $Description)
$instance.AddProperty("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.PowerSupply.Class']/NameOfPowerSupply$", $NameOfPowerSupply)
$instance.AddProperty("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.PowerSupply.Class']/PowerSupplyStatus$", $PowerSupplyStatus)
$instance.AddProperty("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.PowerSupply.Class']/CurrentReading$", $CurrentReading)

$discoveryPowerSupply.AddInstance($instance)
}
}

if ($IsGrantely -eq $false)
{
foreach ($PowerSupply in $PowerSupplysList.result)
{
if ($PowerSupply.sensorType -eq 'FullSensorRecord')
{
$NameForPowerReadingPU = $PowerSupply.name +" of "+ $ServerName
$CurrentReadingPU = $PowerSupply.currentReading
}
}

foreach ($PowerSupply in $PowerSupplysList.result)
{
if ($PowerSupply.sensorType -eq 'CompactSensorRecord')
{
if ( $PowerSupply.description.Trim() -eq 'PowerSupplyPresenceDetected' )
{
$instance = $discoveryPowerSupply.CreateClassInstance("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.PowerSupply.Class']$")
#$NameOfPowerSupply = $PowerSupply.name +" of "+ $ServerName
$NameOfPowerSupply = $PowerSupply.name
$Description = 'PowerSupplyPresenceDetected'
$PowerSupplyStatus = $PowerSupply.status
if ( ($PowerSupplyStatus -eq "Invalid") -or ($PowerSupplyStatus -eq "Ok") )
{
$PowerSupplyStatus = "Normal"
}
$NameForPowerReading = $NameForPowerReadingPU
$CurrentReading = $CurrentReadingPU

$instance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $NameOfPowerSupply)
$instance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $ServerName)
$instance.AddProperty("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.PowerSupply.Class']/Description$", $Description)
$instance.AddProperty("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.PowerSupply.Class']/NameOfPowerSupply$", $NameOfPowerSupply)
$instance.AddProperty("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.PowerSupply.Class']/PowerSupplyStatus$", $PowerSupplyStatus)
$instance.AddProperty("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.PowerSupply.Class']/CurrentReading$", $CurrentReading)

$discoveryPowerSupply.AddInstance($instance)
}
else
{
$instance = $discoveryPowerSupply.CreateClassInstance("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.PowerSupply.Class']$")

#$NameOfPowerSupply = $PowerSupply.name +" of "+ $ServerName
$NameOfPowerSupply = $PowerSupply.name
$Description = $PowerSupply.description
$PowerSupplyStatus = $PowerSupply.status
if ( ($PowerSupplyStatus -eq "Invalid") -or ($PowerSupplyStatus -eq "Ok") )
{
$PowerSupplyStatus = "Normal"
}
$NameForPowerReading = 'Not Available'
$CurrentReading = '0 Watts'
if ( $PowerSupply.description.Trim() -eq 'Not Available' )
{
$CurrentReading = "Not Available"
$PowerSupply.description = ""
}
$instance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $NameOfPowerSupply)
$instance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $ServerName)
$instance.AddProperty("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.PowerSupply.Class']/Description$", $Description)
$instance.AddProperty("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.PowerSupply.Class']/NameOfPowerSupply$", $NameOfPowerSupply)
$instance.AddProperty("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.PowerSupply.Class']/PowerSupplyStatus$", $PowerSupplyStatus)
$instance.AddProperty("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.PowerSupply.Class']/CurrentReading$", $CurrentReading)

$discoveryPowerSupply.AddInstance($instance)
}
}
}
}
}
}
}
}
$discoveryPowerSupply

</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>sourceID</Name>
<Value>$MPElement$</Value>
</Parameter>
<Parameter>
<Name>managedEntityID</Name>
<Value>$Target/Id$</Value>
</Parameter>
<Parameter>
<Name>computerName</Name>
<Value>$Config/computerName$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>3600</TimeoutSeconds>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DsPowerSupplyPs"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>