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

PRTG Network Monitor

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

Free Download

Top Tags


View all Tags

Sensor HTTP XML/REST Value - JSON "node" not accepted if it contains number in name

Votes:

0

Your Vote:

Up

Down

I have the following json response on a website I monitor:

{"24hreward":55,"hashrate":66}

I use the sensor HTTP XML/REST value to parse some values from the JSON file: it doesn't work if I configure the sensor settings with node 24hreward. I get error message: Node 24hreward not found in xml result.

However, it works if I want to parse "hashrate". Maybe the leading number in the object name is the issue? Many thanks.

bug json xml-rest

Created on Apr 18, 2021 7:47:54 PM by  zoltan-yy (0) 1

Last change on Apr 19, 2021 5:54:40 AM by  Felix Wiesneth [Paessler Support]



1 Reply

Votes:

0

Your Vote:

Up

Down

Hello,

Thank you for your message.

Regarding JSON, the property name should effectively start with a letter, an underscore (_) or a dollar sign($) as indicated here: https://google.github.io/styleguide/jsoncstyleguide.xml

If you can't change the property name, then I recommend to use the EXE/Script or EXE/Script Advanced sensor with a custom script such as the following:

Param (
    #[Parameter(Mandatory)]
    [string]$url = ""
)

function Invoke-Request {
    Param(
        $url = $script:url
    )
    Invoke-RestMethod $url -Method Get
}

try {
    $r = Invoke-Request
    write-host @"
<prtg>
<result>
<channel>24h reward</channel>
<value>$($r."24hreward")</value>
</result>
<result>
<channel>Hash rate</channel>
<value>$($r.hashrate)</value>
</result>
</prtg>
"@
   
} catch {
    write-host "<prtg>"
    write-host "<error>1</error>"
    write-host "<text>$($_.exception.message) At line : $($_.InvocationInfo.ScriptLineNumber)</text>"
    write-host "</prtg>"
    Exit 1
}

Regards.

Created on Apr 20, 2021 1:02:02 PM by  Florian Lesage [Paessler Support]

Last change on Apr 20, 2021 1:03:06 PM by  Florian Lesage [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.