Lenovo.XClarity.Integrator.Service.Connection.HealthProvider (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource System.Scheduler Default
PSScript ProbeAction Microsoft.Windows.PowerShellPropertyBagProbe Default

Overrideable Parameters:

IDParameterTypeSelector
IntervalSecondsint$Config/IntervalSeconds$
TimeoutSecondsint$Config/TimeoutSeconds$

Source Code:

<DataSourceModuleType ID="Lenovo.XClarity.Integrator.Service.Connection.HealthProvider" Accessibility="Public">
<Configuration>
<xsd:element name="ID" type="xsd:string"/>
<xsd:element name="Port" type="xsd:string"/>
<xsd:element name="IntervalSeconds" type="xsd:integer"/>
<xsd:element name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation>
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="System!System.Scheduler">
<Scheduler>
<SimpleReccuringSchedule>
<Interval Unit="Seconds">$Config/IntervalSeconds$</Interval>
</SimpleReccuringSchedule>
<ExcludeDates/>
</Scheduler>
</DataSource>
<ProbeAction ID="PSScript" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagProbe">
<ScriptName>Lenovo.LXCI.Service.ps1</ScriptName>
<ScriptBody><Script>
param($id,$port)

$api = new-object -comObject 'MOM.ScriptAPI'
$bag = $api.CreatePropertyBag()
$bag.AddValue('ID',$id)
$bag.AddValue('Port',$port)

function Get-RegistryValue($key, $value)
{
(Get-ItemProperty $key $value).$value
}

function WriteLog($str, $RegDebug, $debugLevel)
{
if ($RegDebug -gt $debugLevel)
{
#Write-Host $str
if ([System.Diagnostics.EventLog]::SourceExists("Lenovo.EventLogSource") -eq $false)
{
[System.Diagnostics.EventLog]::CreateEventSource("Lenovo.EventLogSource", "Operations Manager")
}
Write-EventLog -LogName 'Operations Manager' -Source 'Lenovo.EventLogSource' -EventId 3008 -EntryType Information -Message $str
}
}

$RegDebug = Get-RegistryValue 'HKLM:\SOFTWARE\Lenovo\Lenovo SCOM MP\Debug' 'Level'
if($RegDebug -eq $null)
{
$RegDebug = '0'
}
$RegDebug = [Convert]::ToInt32($RegDebug,10)

$logstring = "RegDebug = " + $RegDebug
WriteLog $logstring $RegDebug 5


$url = 'https://' + $id + ':' + $port + '/immcimlistener?operation=keep-alive'
$logstring = "Try to connect: " + $url
WriteLog $logstring $RegDebug 5

try{
# by default, SecurityProtocol is sslv3 and tls
# add 768 (tls11) and 3072(tls12) for case if web server only supports tls11 or tls12 protocol
# not use [System.Net.SecurityProtocolType]::Tls11/Tls12 directly because it only exists in .Net 4.5 or later
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 768 -bor 3072
}catch{}
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = $delegate

add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@

[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
$response = Invoke-WebRequest -Uri $url -UseBasicParsing

if ($response.StatusCode -eq 200)
{
$bag.AddValue('State','Healthy')
$logstring = "UUS: " + $id + " connection OK"
WriteLog $logstring $RegDebug 5
}
else
{
$bag.AddValue('State','Error')
$logstring = "UUS: " + $id + " connection fail"
WriteLog $logstring $RegDebug 5
}

$bag
</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>ID</Name>
<Value>$Config/ID$</Value>
</Parameter>
<Parameter>
<Name>Port</Name>
<Value>$Config/Port$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="PSScript">
<Node ID="DS"/>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
</DataSourceModuleType>