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

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

Votes:

0

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

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



1 Reply

Votes:

0

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]




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.