New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


Error code PE231 Invalid JSON

Votes:

0

Your Vote:

Up

Down

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^>
"@

custom-script-exe exe-script-sensor help prtg windows windows-2012-r2

Created on Jul 18, 2017 9:32:08 PM by  justinkae (0) 1

Last change on Jul 19, 2017 5:00:00 AM by  Sven Roggenhofer [Paessler Technical Support]



Best Answer

Accepted Answer

Votes:

0

Your Vote:

Up

Down

We're talking past each other hehe. Please replace the Write-Host part with the following:

Write-Host @" <prtg> <result> <channel>hops</channel> <value>$count</value> </result> <result> <channel>latency</channel> <unit>ms</unit> <value>$response</value> </result> <text>$message</text> </prtg> "@

Created on Jul 25, 2017 1:28:21 PM by  Stephan Linke [Paessler Support]



19 Replies

Votes:

0

Your Vote:

Up

Down

Hi Justin,

Why are there circumflex characters all over the output? :) Does the following work?

Write-Host @"
<prtg>
<result>
<channel>hops</channel>
<value>$count</value>
</result>
<result>
<channel>latency</channel>
<unit>ms</unit>
<value>$response</value>
</result>
</ptrg>
"@

edit Sorry, the script contains multiple errors. Here's the fixed script:

param(
  [string]$target
)
$target = ""
$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]
    }
}
$result = $result.Substring(0, $result.Length - 1)
$message = "$count" + " hops to reach " + $target + " in " + $response + "ms " + " via " + $result

Write-Host @"
<prtg>
<result>
<channel>hops</channel>
<value>$count</value>
</result>
<result>
<channel>latency</channel>
<unit>ms</unit>
<value>$response</value>
</result>
<text>$message</text>
</ptrg>
"@

Created on Jul 19, 2017 10:46:39 AM by  Stephan Linke [Paessler Support]

Last change on Jul 20, 2017 12:33:35 PM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Didn't work :(. Is there some setting I need to enable?

Created on Jul 19, 2017 1:08:44 PM by  justinkae (0) 1



Votes:

0

Your Vote:

Up

Down

Please check the edit in my initial post :)

Created on Jul 20, 2017 8:48:34 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

The <text> node cannot be a subnode of the last <result> node

Where it reads

.....
<result>
  <channel>latency</channel>
  <unit>ms</unit>
  <value>$response</value>
  <text>$message</text>
</result>
</ptrg>

It should read

.....
<result>
  <channel>latency</channel>
  <unit>ms</unit>
  <value>$response</value>
</result>
<text>$message</text>
</ptrg>

Created on Jul 20, 2017 11:08:36 AM by  PRTGToolsFamily [prtgtoolsfamily.com] (12,725) 3 4



Votes:

0

Your Vote:

Up

Down

You're indeed correct - thanks again! Fixed it in my post :)

Created on Jul 20, 2017 12:33:54 PM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Still doesn't work. Same Error message.

Created on Jul 20, 2017 1:59:19 PM by  justinkae (0) 1



Votes:

0

Your Vote:

Up

Down

This one, still?

XML: XML Parser mismatch: Wanted </prtg^>, got </ptrg^> -- JSON: The returned JSON does not match the expected structure (Invalid JSON.). (code: PE231) Did you actually replace the code in the correct script that resides in the EXEXML folder?

Created on Jul 21, 2017 6:30:16 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

yes

Created on Jul 21, 2017 1:10:13 PM by  justinkae (0) 1



Votes:

0

Your Vote:

Up

Down

Oh well, couldn't see the forest for the trees:

  • Scripts starts with <prtg>
  • Ends with <p»tr«g>

So correcting the end tag should make it work properly ;)

Created on Jul 24, 2017 7:28:16 AM by  Stephan Linke [Paessler Support]

Last change on Jul 24, 2017 7:29:03 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

I'm confused. Did you want me to replace </prtg> with <p»tr«g>?

I replaced </prtg> with <p»tr«g> and got this error:

XML: Structural error in xml file, 2 open items. -- JSON: The returned JSON does not match the expected structure (Access violation at address 06B7F990. Execution of address 06B7F990). (code: PE231)

I replaced </prtg> with <prtg> and got this error:

XML: Structural error in xml file, 2 open items. -- JSON: The returned JSON does not match the expected structure (Invalid JSON.). (code: PE231)

The initial error message was this:

XML: XML Parser mismatch: Wanted </prtg>, got </ptrg> -- JSON: The returned JSON does not match the expected structure (Invalid JSON.). (code: PE231)

Created on Jul 24, 2017 1:18:16 PM by  justinkae (0) 1



Votes:

0

Your Vote:

Up

Down

Sorry for talking in riddles. I meant that its ending tag </ptrg> is wrong, it needs to be </prtg>.

Created on Jul 25, 2017 7:48:56 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

On my end, you said </prtg> twice.

"Sorry for talking in riddles. I meant that its ending tag </prtg> is wrong, it needs to be </prtg>."

Is this another riddle?

Created on Jul 25, 2017 1:02:32 PM by  justinkae (0) 1



Accepted Answer

Votes:

0

Your Vote:

Up

Down

We're talking past each other hehe. Please replace the Write-Host part with the following:

Write-Host @" <prtg> <result> <channel>hops</channel> <value>$count</value> </result> <result> <channel>latency</channel> <unit>ms</unit> <value>$response</value> </result> <text>$message</text> </prtg> "@

Created on Jul 25, 2017 1:28:21 PM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Working now! Thank you very much. Not sure what the issue was though...

Created on Jul 25, 2017 1:37:31 PM by  justinkae (0) 1



Votes:

0

Your Vote:

Up

Down

In your original script, it looked like this:
</ptrg>
"@

See the typo? It needs to be </prtg> ;)

Created on Jul 25, 2017 1:51:54 PM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Good afternoon sirs,

When updating my PRTG to Version 18.2.39.1661, some alarms with the extension in .py have stopped working, the error that returns me is the following:

XML: Structural error in xml file, 4 open items. - JSON: The returned JSON does not match the expected structure (Invalid JSON code PE231)

What can I do to correct this mistake?

Created on Apr 26, 2018 3:11:23 PM by  danielmoraism2g (0)



Votes:

0

Your Vote:

Up

Down

Do you have the actual output of the script for me?


Kind regards,
Stephan Linke, Tech Support Team

Created on Apr 27, 2018 7:28:59 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hi Sthephan,

Good afternoon,

This information appears in the PRTG log:

26/04/2018 16:49:08 Script Output (UTF8 Encoding): Traceback (most recent call last):[CR][LF]  File "C:\Program Files\PRTG Network Monitor\custom sensors\python\prtg_Mapeamento_Intelig.py", line 4, in <module>[CR][LF]    from dbMapIntelig import servidores, cfg[CR][LF]  File "C:\Program Files\PRTG Network Monitor\Python34\lib\site-packages\dbMapIntelig.py", line 1, in <module>[CR][LF]    import dataset, os[CR][LF]  File "C:\Program Files\PRTG Network Monitor\Python34\lib\site-packages\dataset\__init__.py", line 3, in <module>[CR][LF]    from dataset.persistence.database import Database[CR][LF]  File "C:\Program Files\PRTG Network Monitor\Python34\lib\site-packages\dataset\persistence\database.py", line 1, in <module>[CR][LF]    import logging[CR][LF]  File "C:\Program Files\PRTG Network Monitor\Python34\lib\logging\__init__.py", line 26, in <module>[CR][LF]    import sys, os, time, cStringIO, traceback, warnings, weakref, collections[CR][LF]  File "C:\Program Files\PRTG Network Monitor\Python34\lib\collections\__init__.py", line 6, in <module>[CR][LF]    from _collections_abc import *[CR][LF]  File "C:\Program Files\PRTG Network Monitor\Python34\lib\_collections_abc.py", line 57[CR][LF]    class Hashable(metaclass=ABCMeta):[CR][LF]                            ^[CR][LF]SyntaxError: invalid syntax[CR][LF]

This is output when we try to run the file from the windows command prompt:

  File "C:\Program Files\PRTG Network Monitor\custom sensors\python\prtg_Mapeame
nto_Intelig.py", line 3, in <module>
    from paepy.ChannelDefinition import CustomSensorResult
ImportError: No module named paepy.ChannelDefinition

Thanks for help.

Created on Apr 27, 2018 5:39:58 PM by  danielmoraism2g (0)

Last change on Apr 30, 2018 7:17:48 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hi Daniel,

Welp, something's wrong with your Python script - could you post it, without credentials?


Kind regards,
Stephan Linke, Tech Support Team

Created on Apr 30, 2018 7:19:40 AM by  Stephan Linke [Paessler Support]



Please log in or register to enter your reply.


Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.