What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Error code PE231 Invalid JSON

Votes:

0

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

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



Best Answer

Accepted Answer

Votes:

0

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]



22 Replies

Votes:

0

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

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

Created on Jul 19, 2017 1:08:44 PM



Votes:

0

Please check the edit in my initial post :)

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



Votes:

0

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



Votes:

0

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

Still doesn't work. Same Error message.

Created on Jul 20, 2017 1:59:19 PM



Votes:

0

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

yes

Created on Jul 21, 2017 1:10:13 PM



Votes:

0

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

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



Votes:

0

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

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



Accepted Answer

Votes:

0

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

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

Created on Jul 25, 2017 1:37:31 PM



Votes:

0

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

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



Votes:

0

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

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

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



Votes:

0

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]



Votes:

0

I need help, I have an error on my script I don't understand where, can you help me XML ERROR CODE PE233 - JSON INVALID ERROR CODE PE231

My Scrit :

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
$exp_last_replication_file = Get-ChildItem '\\fr-iops\c$\ALIECOM\REPLICATION_LOG' | Where {$_.LastWriteTime} | select -last 1
$exp_last_replication_file_name= $exp_last_replication_file.Name

$exp_last_replication_file_name_noext = $exp_last_replication_file_name.split(".")[0]
$exp_last_replication_date = $exp_last_replication_file_name_noext.split("_")[0]
$exp_last_replication_hour = $exp_last_replication_file_name_noext.split("_")[1]
$exp_last_replication_status = $exp_last_replication_file_name_noext.split("_")[2]
$exp_last_replication_diff = [System.Math]::Round(((Get-Date) - ($exp_last_replication_file.LastWriteTime)).TotalMinutes, 0)
if($exp_last_replication_status -eq "OK"){$ext_last_replication_status_nb = 0} else{$ext_last_replication_status_nb = 1}

$imp_last_replication_file = Get-ChildItem '\\fr-iops-backup\c$\ALIECOM\REPLICATION_LOG' | Where {$_.LastWriteTime} | select -last 1
$imp_last_replication_file_name= $imp_last_replication_file.Name
$imp_last_replication_file_name_noext = $imp_last_replication_file_name.split(".")[0]
$imp_last_replication_date = $imp_last_replication_file_name_noext.split("_")[0]
$imp_last_replication_hour = $imp_last_replication_file_name_noext.split("_")[1]
$imp_last_replication_status = $imp_last_replication_file_name_noext.split("_")[2]
$imp_last_replication_diff = [System.Math]::Round(((Get-Date) - ($imp_last_replication_file.LastWriteTime)).TotalMinutes, 0)
if($imp_last_replication_status -eq "OK"){$imp_last_replication_status_nb = 0} else{$imp_last_replication_status_nb = 1}

Write-Host @"
<?xml version=`"1.0' encoding=`'Windows-1252' ?>
<prtg>
<result>
<channel>1. FR-IOPS Replication Error - Export</channel>
<value>$ext_last_replication_status_nb</value>
</result>
<result>
<channel>2. FR-IOPS Last time Replication - Export</channel>
<value>$exp_last_replication_diff</value>
</result>
<result>
<channel>3. FR-IOPS Replication Error - Import</channel>
<value>$imp_last_replication_status_nb</value>
</result>
<result>
<channel>4. FR-IOPS Last time Replication - Import</channel>
<value>$imp_last_replication_diff</value>
</result>
<text>FR-IOPS Replication check sensor</text>
</prtg>
"@

Created on Oct 11, 2022 9:28:25 AM

Last change on Oct 11, 2022 1:32:44 PM by  Felix Wiesneth [Paessler Support]



Votes:

0

The issue might be in the first line of the XML. Please remove

<?xml version=`"1.0' encoding=`'Windows-1252' ?> ...and run the script again. Do you get the same error? What's the actual output of the Script when running it manually?


Kind regards,
Stephan Linke, Paessler Technical Support Team

Created on Oct 12, 2022 9:22:46 AM by  Stephan Linke [Paessler Support]



Votes:

0

Hello,

here is the output of the script with a message of "Modifying the execution strategy"

"Modifying the execution strategy The execution policy helps guard against scripts that you consider untrustworthy. By modifying the execution strategy, you expose yourself to the security risks described in the help topic about_Execution_Policies. Do you want to modify the execution strategy?"

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
$exp_last_replication_file = Get-ChildItem "\\fr-iops\c$\ALIECOM\REPLICATION_LOG" | Where {$_.LastWriteTime} | select -last 1
$exp_last_replication_file_name= $exp_last_replication_file.Name

$exp_last_replication_file_name_noext = $exp_last_replication_file_name.split(".")[0]
$exp_last_replication_date = $exp_last_replication_file_name_noext.split("_")[0]
$exp_last_replication_hour = $exp_last_replication_file_name_noext.split("_")[1]
$exp_last_replication_status = $exp_last_replication_file_name_noext.split("_")[2]
$exp_last_replication_diff = [System.Math]::Round(((Get-Date) - ($exp_last_replication_file.LastWriteTime)).TotalMinutes, 0)
if($exp_last_replication_status -eq "OK"){$ext_last_replication_status_nb = 0} else{$ext_last_replication_status_nb = 1}

$imp_last_replication_file = Get-ChildItem "\\fr-iops-backup\c$\ALIECOM\REPLICATION_LOG" | Where {$_.LastWriteTime} | select -last 1
$imp_last_replication_file_name= $imp_last_replication_file.Name
$imp_last_replication_file_name_noext = $imp_last_replication_file_name.split(".")[0]
$imp_last_replication_date = $imp_last_replication_file_name_noext.split("_")[0]
$imp_last_replication_hour = $imp_last_replication_file_name_noext.split("_")[1]
$imp_last_replication_status = $imp_last_replication_file_name_noext.split("_")[2]
$imp_last_replication_diff = [System.Math]::Round(((Get-Date) - ($imp_last_replication_file.LastWriteTime)).TotalMinutes, 0)
if($imp_last_replication_status -eq "OK"){$imp_last_replication_status_nb = 0} else{$imp_last_replication_status_nb = 1}

Write-Host "<prtg><result><channel>1. FR-IOPS Replication Error - Export</channel><value>$ext_last_replication_status_nb</value></result><result><channel>2. FR-IOPS Last time Replication - Export</channel><value>$exp_last_replication_diff</value></result><result><channel>3. FR-IOPS Replication Error - Import</channel><value>$imp_last_replication_status_nb</value></result><result><channel>4. FR-IOPS Last time Replication - Import</channel><value>$imp_last_replication_diff</value></result><text>FR-IOPS Replication check sensor</text></prtg>"
Get-ExecutionPolicy -List
MachinePolicy                                                                   RemoteSigned
UserPolicy                                                                      Undefined
Process                                                                      Undefined
CurrentUser                                                                   RemoteSigned
LocalMachine                                                                   RemoteSigned

Created on Oct 17, 2022 9:26:16 AM

Last change on Oct 17, 2022 9:57:36 AM by  Felix Wiesneth [Paessler Support]




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.