Go to All Forums

Plugin: Network Hops and Round Trip TIme

This plugin will return the hops in a trace route and the round trip time. Needs the latest version of PowerShell. Set primary and secondary destination by name or IP.

 

$version = 1 #Mandatory
$displayname = "Trace on $env:computername"
$heartbeat = "false" #Mandatory

Function Get-Data()
{

$destination = "9.9.9.9" #Primary DNS
$altdestination = "192.168.0.1" #EDGE Router

if ((Test-NetConnection $destination).PingSucceeded) {} else {$destination = $altdestination}
$results = Test-NetConnection $destination -TraceRoute
$hops = ($results.TraceRoute).count
$RTT = ($results.PingReplyDetails).RoundtripTime

$data = @{}
$data.Add("Hops", $hops)
$data.Add("RTT", $RTT)

return $data
}
Function Set-Units() #OPTIONAL - These units will be displayed in the Dashboard
{
$units = @{}
$units.Add("hops","#")
$units.Add("RTT", "ms")
return $units
}

$mainJson = @{}
$mainJson.Add("plugin_version", $version)
$mainJson.Add("heartbeat_required", $heartbeat)
$mainJson.Add("displayname", $displayname) #Comment this if you don't display name
$mainJson.Add("data", (Get-Data))
$mainJson.Add("units", (Set-Units)) #Comment this if you don't have Units
####### Plugin Output Vaidation -- No need to edit this function ########
###This is only to verify whether the Ouput format is valid######
$validate = $true
if($args.Count -gt 0 -and $args[0] -eq "skipvalidation")
{
$validate = $false
}
Function Validate-Plugin($pluginData)
{
$validationObj = @{}
$errormsg = ""
if($pluginData -eq $null -or $pluginData.count -le 0)
{
$errormsg += "# The Plugin Output Is empty #"
}
else
{
if($pluginData.ContainsKey("heartbeat_required"))
{
if(($val="true","false" -notcontains $pluginData["heartbeat_required"]))
{
$errormsg += '# Mandatory field heartbeat_required should be true or false #'
}
}
else
{
$errormsg += '# Mandatory field heartbeat_required is missing #'
}
if($pluginData.ContainsKey("plugin_version"))
{
if(($pluginData["plugin_version"] -match '^\d+$') -eq $false)
{
$errormsg += '# Mandatory field plugin_version should be an integer #'
}
}
else
{
$errormsg += '# Mandatory field plugin_version is missing #'
}
if($pluginData.ContainsKey("data"))
{
if($pluginData["data"] -eq $null)
{
$errormsg += '# Mandatory field data is empty #'
}
elseif(($pluginData["data"]).Count -le 0)
{
$errormsg += '# There should be atleast one data metric present #'
}
}
else
{
$errormsg += '# Mandatory field data is missing #'
}
}
if($errormsg.Length -gt 0)
{
$validationObj.Add("Errors",$errormsg)
$validationObj.Add("Result","**************Plugin output is not valid************")
}
else
{
$validationObj.Add("Result","**************Plugin output is valid**************")
}
return $validationObj
}
if($validate)
{
$mainJson.Add("validation output",(Validate-Plugin $mainJson))
}
return $mainJson | ConvertTo-Json
####### Plugin Output Vaidation Function ########

 

Like (4) Reply
Replies (0)