URLGenie.PingTask.PA

URLGenie.PingTask.PA (ProbeActionModuleType)

Element properties:

TypeProbeActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
InputTypeSystem.BaseData
OutputTypeMicrosoft.Windows.SerializedObjectData

Member Modules:

ID Module Type TypeId RunAs 
POSH ProbeAction Microsoft.Windows.PowerShellProbe Default

Source Code:

<ProbeActionModuleType ID="URLGenie.PingTask.PA" Accessibility="Internal" Batching="false" PassThrough="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="Description" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="0" name="Marker" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="URL" type="xsd:string"/>
</Configuration>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<ProbeAction ID="POSH" TypeID="Windows!Microsoft.Windows.PowerShellProbe">
<ScriptName>PingTask.ps1</ScriptName>
<ScriptBody><Script>###########################################################################
#
# NAME: PingTask.ps1
#
# Created by: Tyson Paul ( https://blogs.msdn.microsoft.com/tysonpaul/ )
#
# COMMENT: A simple diagnostic ping test. For use with the URLScripted monitor. To include additional hosts to ping, add a line to the Description property in the format below:
# Let the "Marker" be "PINGTEST" with the hostname surrounded with # characters. Multiple targets can be submitted.
# "PINGTEST#myserver.domain.local# words and stuff... PINGTEST#myotherserver.domain.local#"
#
# VERSION HISTORY:
# 20160811 - Changed marker to identify additional targets to ping. Now supports custom beginning and ending tokens in the marker array: $Marker.
# 20131219 - Initial release
#
###########################################################################

param(
[string]$URL,
[string]$Description = "PINGTEST#localhost#",
[system.object[]]$Marker = @("PINGTEST#","#")
)

###############################################################################################
function PingIt {
param(
[string]$target
)
[string]$resolved = ""
$ErrorActionPreference = 'SilentlyContinue'
Write-Host "-------------------------------------------"
Write-Host "Target: $target "
$test = Test-Connection -Cn $target -BufferSize 16 -Count 1 -ea 0 2&gt; $null
if (!($test)) {
Write-Host " Problem connecting to target:[$($target)] !"
if ($target) {
Write-Host " Looking up IP addresses for $target ..."
$resolved = [System.Net.Dns]::GetHostAddresses($target)
if (!($resolved)) { Write-Host " No IP found for $target ." }
else { $resolved }
}
} # end if
else {
$ip = $test.IPV4Address.ipaddresstostring
Write-Host " SUCCESS CONNECTING TO TARGET: [$($target)]! IP Address: $ip"
}
$ErrorActionPreference = 'Continue'
} #End PingIt


###############################################################################################
$info = @"

NOTE: This diagnostic task will automatically attempt to ping the URL(s) and any additional hosts
that you specify in the description field. For the instance you can specify any number of hosts to
ping in the description field when you surround the host with certain identifiers as shown in the example below:

"This is an example description for a URL instance that is to be targed by the URLScripted monitor.
In addition to the URL(s) configured for the instance, the following hosts can be pinged with this built-in diagnostic task if this
monitor should happen to fail:
PINGTEST#MyServer1.Mydomain.com# PINGTEST#MyServer2.Mydomain.com# and also this server, PINGTEST#MyOtherServer.Mydomain.com#.
The results of this diagnostic can be seen in the Health Explorer Context window for the object instance."

"@

Write-Host $info
Write-Host "URL: [ $($URL) ]"
Write-Host ""
Write-Host "Description: $Description"
Write-Host "`n"
[int]$i = 0
foreach ($address in ($URL.Split('^'))) {
$i++
Write-Host "URL #" $i ": [ $address ]"
PingIt ([System.URI]$address).Host #this only works on properly formatted URL (must include 'http://' )
Write-Host "" #ghetto formatting
}

If ($Marker.Count -le 1) { $Marker = $Marker[0].ToString().Split("[,;]") }
#Normalize these variables to uppercase. IndexOf is case-sensitive.
$Description = $Description.ToUpper()
0..1 | % {$Marker[$_] = $Marker[$_].ToUpper() }

do {

if ($Description -like "*$($Marker[0])*" ) {
$once = 1
$Remainder = ($Description.Substring(($Description.IndexOf($Marker[0]) + ($Marker[0]).Length), $Description.Length - ($Description.IndexOf($Marker[0]) + ($Marker[0]).Length)))
[string]$Target = ($Remainder.Substring(0,($Remainder.IndexOf($Marker[1]) )) )
PingIt $Target
$Description = ($Description.Substring(($Description.IndexOf($Marker[0]) + ($Marker[0]).Length),$Description.Length - ($Description.IndexOf($Marker[0]) + ($Marker[0]).Length)))
}
Else {
If (-not $once) { Write-Host "Note: No additional Pingtest 'Marker':[$($Marker[0])] detected in Description." }
}
} while ($Description.Contains($Marker[0]))

Write-Host "`n" #New line
Exit</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>Description</Name>
<Value>$Config/Description$</Value>
</Parameter>
<Parameter>
<Name>Marker</Name>
<Value>$Config/Marker$</Value>
</Parameter>
<Parameter>
<Name>URL</Name>
<Value>$Config/URL$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>90</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="POSH"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>Windows!Microsoft.Windows.SerializedObjectData</OutputType>
<InputType>System!System.BaseData</InputType>
</ProbeActionModuleType>