TempSensor.DiscoveryRule (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.Discovery.Data

Member Modules:

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

Overrideable Parameters:

IDParameterTypeSelector
IntervalSecondsint$Config/IntervalSeconds$

Source Code:

<DataSourceModuleType ID="TempSensor.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="DsTempSensorPs" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime/>
<ScriptName>DiscoverTempSensor.PS1</ScriptName>
<ScriptBody><Script>

# **********************************************************************************
# Script Name : DiscoverTempSensor
# Authored by : MphasiS Corporation
# Description : Discovers Lenovo Servers Temperature Sensor Properties
#
# 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'
$discoveryTempSensor = $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)
{
$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'

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

Try
{
$TemperatureSensorList = &amp; $JavaFilePath -jar $TemperatureSensorJarFilePath temperaturesensor $BMCIPAddress $BMCUserName $BMCPassword | ConvertFrom-Json
}
Catch
{
LogEntry("Error while fetching Temperature Sensor details using Out of band for "+ $computerName)
}

if ($TemperatureSensorList.result.Count -gt 0)
{
foreach ($TemperatureSensor in $TemperatureSensorList.result)
{
if ($TemperatureSensor.name -ne $null)
{
$instance = $discoveryTempSensor.CreateClassInstance("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.TemperatureSensor.Class']$")
$Description = $TemperatureSensor.name

if ([int]$TemperatureSensor.upperCriticalThreshold -eq 0)
{
$UpperThresholdCriticalTemperature = "N/A"
}
else
{
$UpperThresholdCriticalTemperature = [int]$TemperatureSensor.upperCriticalThreshold
}
if ([int]$TemperatureSensor.upperNonRecoverableThreshold -eq 0)
{
$UpperThresholdFatalTemperature = "N/A"
}
else
{
$UpperThresholdFatalTemperature = [int]$TemperatureSensor.upperNonRecoverableThreshold
}
if ([int]$TemperatureSensor.upperNonCriticalThreshold -eq 0)
{
$UpperThresholdNonCriticalTemperature = "N/A"
}
else
{
$UpperThresholdNonCriticalTemperature = [int]$TemperatureSensor.upperNonCriticalThreshold
}

$instance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $Description)
$instance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $ServerName)
$instance.AddProperty("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.TemperatureSensor.Class']/TempSenDescription$", $Description)
$instance.AddProperty("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.TemperatureSensor.Class']/CurrentTemperature$", $TemperatureSensor.currentReading)
$instance.AddProperty("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.TemperatureSensor.Class']/UpperThresholdCriticalTemperature$", $UpperThresholdCriticalTemperature)
$instance.AddProperty("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.TemperatureSensor.Class']/UpperThresholdFatalTemperature$", $UpperThresholdFatalTemperature)
$instance.AddProperty("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.TemperatureSensor.Class']/UpperThresholdNonCriticalTemperature$", $UpperThresholdNonCriticalTemperature)

$discoveryTempSensor.AddInstance($instance)
}
}
}
}
}
}
$discoveryTempSensor

</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="DsTempSensorPs"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>