I keep getting this error when trying to run a XML Custom EXE/Script Sensor:
XML: XML Parser mismatch: Wanted </prtg^>, got </ptrg^> -- JSON: The returned JSON does not match the expected structure (Invalid JSON.). (code: PE231)
I suspect its because my returned JSON isn't properly structured. Here is my code:
param( [string]$target ) $target = "105.1.164.2" $trace = tracert -w 150 -4 $target $count = 0 $result = "" $response = 0 $trace foreach ($line in $trace) { if($line.contains(" ms") -or $line.contains(" * ") ) { $line = $line.replace(" ms", "") $count = $count + 1 $array = $line.trim() -split "\s+" $ip = $array[4] $result = $result + $ip.trim() + ">" $response = $array[3] $response } } $result = $result.Substring(0, $result.Length - 1) $message = "$count" + " hops to reach " + $target + " in " + $response + "ms " + " via " + $result write-host $count":"$message Write-Host @" ^<prtg^> ^<result^> ^<channel^>hops^</channel^> ^<value^>$count^</value^> ^</result^> ^<result^> ^<channel^>latency^</channel^> ^<unit^>ms^</unit^> ^<value^>$response^</value^> ^</result^> ^</ptrg^> "@
Add comment