HealthServicesPingCheck (WriteActionModuleType)

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
InputTypeSystem.BaseData

Member Modules:

ID Module Type TypeId RunAs 
PSScript ProbeAction Microsoft.Windows.PowerShellPropertyBagProbe Default
LinkedDataMapper ConditionDetection Event.LinkedDataMapper Default
Mapper ConditionDetection System.Event.GenericDataMapper Default
EventWA WriteAction Microsoft.SystemCenter.CollectEvent Default

Overrideable Parameters:

IDParameterTypeSelector
NetBIOSNamestring$Config/NetBIOSName$
PrincipalNamestring$Config/PrincipalName$
ManagementServerNamestring$Config/ManagementServerName$
PingSamplesint$Config/PingSamples$
IntervalMillisecondsint$Config/IntervalMilliseconds$
TimeoutSecondsint$Config/TimeoutSeconds$

Source Code:

<WriteActionModuleType Accessibility="Public" ID="HealthServicesPingCheck">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="NetBIOSName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="PrincipalName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ManagementServerName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="PingSamples" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="IntervalMilliseconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="NetBIOSName" Selector="$Config/NetBIOSName$" ParameterType="string"/>
<OverrideableParameter ID="PrincipalName" Selector="$Config/PrincipalName$" ParameterType="string"/>
<OverrideableParameter ID="ManagementServerName" Selector="$Config/ManagementServerName$" ParameterType="string"/>
<OverrideableParameter ID="PingSamples" Selector="$Config/PingSamples$" ParameterType="int"/>
<OverrideableParameter ID="IntervalMilliseconds" Selector="$Config/IntervalMilliseconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<ProbeAction TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagProbe" ID="PSScript">
<ScriptName>HealthServicesPingCheck.ps1</ScriptName>
<ScriptBody><Script><![CDATA[#=================================================================================
# Script to ping check via PowerShell
#
# This script will use Get-WmiObject command to check ping status
# Takes a single parameter of a Health Service Computer Name FQDN
# Will be executed from Health Service primary management server.
# v 1.0
#=================================================================================

param($NetBIOSName,$PrincipalName,$ManagementServerName,$PingSamples,$intervalMilliseconds)
$scomapi = new-object -comObject "MOM.ScriptAPI"

If ($PrincipalName.Trim() -eq ""){
$PrincipalName="."
}


$stateCodes=@{}
$stateCodes.Add(0,"Success");
$stateCodes.Add(14,"Bad address");
$stateCodes.Add(11001,"Buffer Too Small");
$stateCodes.Add(11002,"Destination Net Unreachable");
$stateCodes.Add(11003,"Destination Host Unreachable");
$stateCodes.Add(11004,"Destination Protocol Unreachable");
$stateCodes.Add(11005,"Destination Port Unreachable");
$stateCodes.Add(11006,"No Resources");
$stateCodes.Add(11007,"Bad Option");
$stateCodes.Add(11008,"Hardware Error");
$stateCodes.Add(11009,"Packet Too Big");
$stateCodes.Add(11010,"Request Timed Out");
$stateCodes.Add(11011,"Bad Request");
$stateCodes.Add(11012,"Bad Route");
$stateCodes.Add(11013,"TimeToLive Expired Transit");
$stateCodes.Add(11014,"TimeToLive Expired Reassembly");
$stateCodes.Add(11015,"Parameter Problem");
$stateCodes.Add(11016,"Source Quench");
$stateCodes.Add(11017,"Option Too Big");
$stateCodes.Add(11018,"Bad Destination");
$stateCodes.Add(11032,"Negotiating IPSEC");
$stateCodes.Add(11050,"General Failure");

$Query = "SELECT PrimaryAddressResolutionStatus,StatusCode, ResponseTime FROM Win32_PingStatus WHERE Address = '$PrincipalName'"

for($i=1;$i -le $PingSamples;$i++)
{
$oStatus = get-wmiobject -Query $Query -ComputerName $ManagementServerName

if ($oStatus.PrimaryAddressResolutionStatus -ne 0)
{
$Query = "SELECT PrimaryAddressResolutionStatus,StatusCode, ResponseTime FROM Win32_PingStatus WHERE Address = '$NetBIOSName'"

$oStatus = get-wmiobject -Query $Query -ComputerName $ManagementServerName

if ($oStatus.PrimaryAddressResolutionStatus -ne 0)
{
$StatusCode=14
$ResponseTime=0
break
}
else{
$StatusCode=$oStatus.StatusCode
$ResponseTime=$oStatus.ResponseTime
if($StatusCode -eq 0) {break}
if($StatusCode -ne $null)
{
$StatusCode=11003
$ResponseTime=0
}
}
}
else{
$StatusCode=$oStatus.StatusCode
$ResponseTime=$oStatus.ResponseTime
if($StatusCode -eq 0) {break}
if($StatusCode -ne $null)
{
$StatusCode=11003
$ResponseTime=0
}
}
Start-Sleep -m $intervalMilliseconds
}
$scompb = $scomapi.CreatePropertyBag()
$scompb.AddValue("Status", $stateCodes.Item([Int]$StatusCode))
$scompb.AddValue("StatusCode",$StatusCode)
$scompb.AddValue("ResponseTime",$ResponseTime)
$scompb.AddValue("AgentServerName",$PrincipalName)
$scompb.AddValue("ManagementServerName",$ManagementServerName)
$scompb
]]></Script></ScriptBody>
<Parameters>
<Parameter>
<Name>NetBIOSName</Name>
<Value>$Config/NetBIOSName$</Value>
</Parameter>
<Parameter>
<Name>PrincipalName</Name>
<Value>$Config/PrincipalName$</Value>
</Parameter>
<Parameter>
<Name>ManagementServerName</Name>
<Value>$Config/ManagementServerName$</Value>
</Parameter>
<Parameter>
<Name>PingSamples</Name>
<Value>$Config/PingSamples$</Value>
</Parameter>
<Parameter>
<Name>IntervalMilliseconds</Name>
<Value>$Config/IntervalMilliseconds$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
<ConditionDetection ID="Mapper" TypeID="System!System.Event.GenericDataMapper">
<EventOriginId>$Target/Id$</EventOriginId>
<PublisherId>$MPElement$</PublisherId>
<PublisherName>ServerConnectivityCheck</PublisherName>
<Channel>Application</Channel>
<LoggingComputer>$Data/Property[@Name='ManagementServerName']$</LoggingComputer>
<EventNumber>100</EventNumber>
<EventCategory>3</EventCategory>
<EventLevel>0</EventLevel>
<UserName/>
<Params>
<Param>$Data/Property[@Name='Status']$</Param>
<Param>$Data/Property[@Name='StatusCode']$</Param>
<Param>$Data/Property[@Name='ResponseTime']$</Param>
<Param>$Data/Property[@Name='AgentServerName']$</Param>
<Param>$Data/Property[@Name='ManagementServerName']$</Param>
</Params>
</ConditionDetection>
<ConditionDetection TypeID="Event.LinkedDataMapper" ID="LinkedDataMapper">
<ManagedEntityId>$Target/Id$</ManagedEntityId>
<RuleId>$MPElement$</RuleId>
</ConditionDetection>
<WriteAction TypeID="SC!Microsoft.SystemCenter.CollectEvent" ID="EventWA"/>
</MemberModules>
<Composition>
<Node ID="EventWA">
<Node ID="LinkedDataMapper">
<Node ID="Mapper">
<Node ID="PSScript"/>
</Node>
</Node>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>