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

Json error

Votes:

0

Anyone can tell me why this json does not get recognized as valid?

Last mgs: lastmsg":"#Y2 @#O233 @#O231[Invalid JSON.] Full sensor log:

3/23/2023 3:28:08 PM Script File: huawei_backup_power.py
3/23/2023 3:28:08 PM Script Parameters: {"tlsexplicit_pop3":"","fastcount":"0","esxpassword":"","hostv6":"","blockedsens":"","secretaccesskeyid":"","tlsexplicit_default":"","isexesensor":"0","scriptplaceholder3":"","windowsloginpassword":"","privatekey":"","secret":"","resttoken":"","reboot":"45007.6443106829","pop3password":"","pythonscript":"huawei_backup_power.py","scriptplaceholder1":"","tlsexplicit_port":"","inerror":"1","scriptplaceholder4":"","smspassword":"","params":"","host":"*****","mailpassword":"","tlsexplicit_ftp":"","timeout":"59","elevationpass":"","momopersistent":"","notonpod":"0","linuxloginpassword":"","smtppassword2":"","smtppassword":"","lastuptime":"0","writeresult":"1","socksproxypass":"","prtg_linuxpassword":"","tlsexplicit_imap":"","sshelevationpass":"","uptimecount":"0","canlinux":"0","proxypassword":"","proxypass":"","mutexname":"","snmpencpass":"","authuserpwd":"","scriptplaceholder5":"","usednstime":"0","restpassword":"","httppassword":"","addomainpass":"","authtoken":"","oauthrefreshtoken":"","evapassword":"","oauthtoken":"","snmpcommv1":"","sensorid":"35509","ipversion":"0","xmlhttppassword":"","tlsexplicit_smtp":"","scriptplaceholder2":"","password":"","snmpcommv2":"","snmpauthpass":"","awssk":"","dbpassword":"","pingdompassword":"","usewindowsauthentication":"0","prtg_windowspassword":"","simulate":"0","lastmsg":"#Y2 @#O233 @#O231[Invalid JSON.]","imappassword":"","ftppassword":""}
3/23/2023 3:28:08 PM Script Parameters (escaped): {\"tlsexplicit_pop3\":\"\",\"fastcount\":\"0\",\"esxpassword\":\"\",\"hostv6\":\"\",\"blockedsens\":\"\",\"secretaccesskeyid\":\"\",\"tlsexplicit_default\":\"\",\"isexesensor\":\"0\",\"scriptplaceholder3\":\"\",\"windowsloginpassword\":\"\",\"privatekey\":\"\",\"secret\":\"\",\"resttoken\":\"\",\"reboot\":\"45007.6443106829\",\"pop3password\":\"\",\"pythonscript\":\"huawei_backup_power.py\",\"scriptplaceholder1\":\"\",\"tlsexplicit_port\":\"\",\"inerror\":\"1\",\"scriptplaceholder4\":\"\",\"smspassword\":\"\",\"params\":\"\",\"host\":\"*****\",\"mailpassword\":\"\",\"tlsexplicit_ftp\":\"\",\"timeout\":\"59\",\"elevationpass\":\"\",\"momopersistent\":\"\",\"notonpod\":\"0\",\"linuxloginpassword\":\"\",\"smtppassword2\":\"\",\"smtppassword\":\"\",\"lastuptime\":\"0\",\"writeresult\":\"1\",\"socksproxypass\":\"\",\"prtg_linuxpassword\":\"\",\"tlsexplicit_imap\":\"\",\"sshelevationpass\":\"\",\"uptimecount\":\"0\",\"canlinux\":\"0\",\"proxypassword\":\"\",\"proxypass\":\"\",\"mutexname\":\"\",\"snmpencpass\":\"\",\"authuserpwd\":\"\",\"scriptplaceholder5\":\"\",\"usednstime\":\"0\",\"restpassword\":\"\",\"httppassword\":\"\",\"addomainpass\":\"\",\"authtoken\":\"\",\"oauthrefreshtoken\":\"\",\"evapassword\":\"\",\"oauthtoken\":\"\",\"snmpcommv1\":\"\",\"sensorid\":\"35509\",\"ipversion\":\"0\",\"xmlhttppassword\":\"\",\"tlsexplicit_smtp\":\"\",\"scriptplaceholder2\":\"\",\"password\":\"\",\"snmpcommv2\":\"\",\"snmpauthpass\":\"\",\"awssk\":\"\",\"dbpassword\":\"\",\"pingdompassword\":\"\",\"usewindowsauthentication\":\"0\",\"prtg_windowspassword\":\"\",\"simulate\":\"0\",\"lastmsg\":\"#Y2 @#O233 @#O231[Invalid JSON.]\",\"imappassword\":\"\",\"ftppassword\":\"\"}
3/23/2023 3:28:08 PM Script Path: C:\Program Files (x86)\PRTG Network Monitor\custom sensors\python\huawei_backup_power.py
3/23/2023 3:28:08 PM Command Line: "C:\Program Files (x86)\PRTG Network Monitor\python\python.exe" -E "C:\Program Files (x86)\PRTG Network Monitor\custom sensors\python\huawei_backup_power.py" "{\"tlsexplicit_pop3\":\"\",\"fastcount\":\"0\",\"esxpassword\":\"\",\"hostv6\":\"\",\"blockedsens\":\"\",\"secretaccesskeyid\":\"\",\"tlsexplicit_default\":\"\",\"isexesensor\":\"0\",\"scriptplaceholder3\":\"\",\"windowsloginpassword\":\"\",\"privatekey\":\"\",\"secret\":\"\",\"resttoken\":\"\",\"reboot\":\"45007.6443106829\",\"pop3password\":\"\",\"pythonscript\":\"huawei_backup_power.py\",\"scriptplaceholder1\":\"\",\"tlsexplicit_port\":\"\",\"inerror\":\"1\",\"scriptplaceholder4\":\"\",\"smspassword\":\"\",\"params\":\"\",\"host\":\"****\",\"mailpassword\":\"\",\"tlsexplicit_ftp\":\"\",\"timeout\":\"59\",\"elevationpass\":\"\",\"momopersistent\":\"\",\"notonpod\":\"0\",\"linuxloginpassword\":\"\",\"smtppassword2\":\"\",\"smtppassword\":\"\",\"lastuptime\":\"0\",\"writeresult\":\"1\",\"socksproxypass\":\"\",\"prtg_linuxpassword\":\"\",\"tlsexplicit_imap\":\"\",\"sshelevationpass\":\"\",\"uptimecount\":\"0\",\"canlinux\":\"0\",\"proxypassword\":\"\",\"proxypass\":\"\",\"mutexname\":\"\",\"snmpencpass\":\"\",\"authuserpwd\":\"\",\"scriptplaceholder5\":\"\",\"usednstime\":\"0\",\"restpassword\":\"\",\"httppassword\":\"\",\"addomainpass\":\"\",\"authtoken\":\"\",\"oauthrefreshtoken\":\"\",\"evapassword\":\"\",\"oauthtoken\":\"\",\"snmpcommv1\":\"\",\"sensorid\":\"35509\",\"ipversion\":\"0\",\"xmlhttppassword\":\"\",\"tlsexplicit_smtp\":\"\",\"scriptplaceholder2\":\"\",\"password\":\"\",\"snmpcommv2\":\"\",\"snmpauthpass\":\"\",\"awssk\":\"\",\"dbpassword\":\"\",\"pingdompassword\":\"\",\"usewindowsauthentication\":\"0\",\"prtg_windowspassword\":\"\",\"simulate\":\"0\",\"lastmsg\":\"#Y2 @#O233 @#O231[Invalid JSON.]\",\"imappassword\":\"\",\"ftppassword\":\"\"}"
3/23/2023 3:28:08 PM Script Output (OEMCP Encoding): {'prtg': {'result': [{'Channel': 'Controller A', 'ValueLookup': 'oid.huawei-dorado-500-api.bbu.healthstatus', 'Value': '1'}, {'Channel': 'Controller B', 'ValueLookup': 'oid.huawei-dorado-500-api.bbu.healthstatus', 'Value': '1'}], 'text': 'Everything is ok'}}[CR][LF]
3/23/2023 3:28:08 PM Exit Code: 0
3/23/2023 3:28:08 PM RawStream Size: 260
3/23/2023 3:28:08 PM OutputStream Size: 260
3/23/2023 3:28:08 PM Script Output (UTF8 Encoding): {'prtg': {'result': [{'Channel': 'Controller A', 'ValueLookup': 'oid.huawei-dorado-500-api.bbu.healthstatus', 'Value': '1'}, {'Channel': 'Controller B', 'ValueLookup': 'oid.huawei-dorado-500-api.bbu.healthstatus', 'Value': '1'}], 'text': 'Everything is ok'}}[CR][LF]

Just the json output: 3/23/2023 3:28:08 PM Script Output (OEMCP Encoding): {'prtg': {'result': [{'Channel': 'Controller A', 'ValueLookup': 'oid.huawei-dorado-500-api.bbu.healthstatus', 'Value': '1'}, {'Channel': 'Controller B', 'ValueLookup': 'oid.huawei-dorado-500-api.bbu.healthstatus', 'Value': '1'}], 'text': 'Everything is ok'}}[CR][LF] 3/23/2023 3:28:08 PM Exit Code: 0 3/23/2023 3:28:08 PM RawStream Size: 260 3/23/2023 3:28:08 PM OutputStream Size: 260 3/23/2023 3:28:08 PM Script Output (UTF8 Encoding): {'prtg': {'result': [{'Channel': 'Controller A', 'ValueLookup': 'oid.huawei-dorado-500-api.bbu.healthstatus', 'Value': '1'}, {'Channel': 'Controller B', 'ValueLookup': 'oid.huawei-dorado-500-api.bbu.healthstatus', 'Value': '1'}], 'text': 'Everything is ok'}}[CR][LF]

Lookup file:

<xml version="1.0" encoding="UTF-8"?>
<ValueLookup id="oid.huawei-dorado-500-api.bbu.healthstatus" desiredValue="1" undefinedState="olsWarning">
  <Lookups>
    <SingleInt state="Unknown" value="0">
      Unknown
    </SingleInt>
    <SingleInt state="Ok" value="1">
      Normal
    </SingleInt>
    <SingleInt state="Error" value="2">
      Faulty
    </SingleInt>
    <SingleInt state="Warning" value="3">
      About to fail
    </SingleInt>
    <SingleInt state="Warning" value="12">
      Low battery
    </SingleInt>
  </Lookups>
</ValueLookup>

json python valuelookup xml

Created on Mar 24, 2023 10:09:18 AM



1 Reply

Accepted Answer

Votes:

2

Hello, JSON requires double quotes by definition Also the requests.json() method in the response module of python. This method, by design, only adds single quotes for readability.

Solved by using the JSON module with the dump method for printing the result – json.dumps(). This module/method adds double quotes to the output.

Created on Mar 31, 2023 2:20:59 AM by  Luis Quesada (Paessler Technical 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.