How can I get the 'value' for 'RecentRequestsPerSecond' using XPath on the XML below using the HTTP XML/REST Value sensor?
<xxxxresponse> <action>GETSTATISTICS</action> <response>Success</response> <responsedata xmlns:x="http://schemas.xxxxxxxx.com/xxx/"> <xxxx:stat class="Service" xxxxid="Statistics" name="RecentResponseAverage" metric="9" value="1"/> <xxxx:stat class="Service" xxxxid="Statistics" name="RecentRequestsPerSecond" metric="3" value="0.2"/> <xxxx:stat class="Service" xxxxid="Statistics" name="RecentPeakRequestsPerSecond" metric="3" value="0.8"/> <xxxx:stat class="Service" xxxxid="Statistics" name="RecentRequests" metric="5" value="40"/> <xxxx:stat class="Service" xxxxid="Statistics" name="TotalRequests" metric="5" value="42935"/> </responsedata> </xxxxresponse>
I have validated the following will retrieve the value in an XPath validator, but it won't work for the HTTP XML/REST Value sensor. What am I doing wrong?
*[@name="RecentRequestsPerSecond"]/@value
Article Comments
<autnresponse> <action>GETSTATISTICS</action> <response>Success</response> <responsedata xmlns:autn="http://schemas.autonomy.com/aci/"> <autn:stat class="Service" autnid="Statistics" name="ServiceDuration" metric="8" value="385194"/> <autn:stat class="Service" autnid="Statistics" name="10SecondResponseAverage" metric="0" value="N/A"/> <autn:stat class="Service" autnid="Statistics" name="10SecondRequestsPerSecond" metric="3" value="0.0"/> <autn:stat class="Service" autnid="Statistics" name="10SecondRequests" metric="5" value="0"/> <autn:stat class="Service" autnid="Statistics" name="60SecondResponseAverage" metric="9" value="24"/> <autn:stat class="Service" autnid="Statistics" name="60SecondRequestsPerSecond" metric="3" value="0.2"/> <autn:stat class="Service" autnid="Statistics" name="60SecondPeakRequestsPerSecond" metric="3" value="0.5"/> <autn:stat class="Service" autnid="Statistics" name="60SecondRequests" metric="5" value="12"/> <autn:stat class="Service" autnid="Statistics" name="1HourResponseAverage" metric="9" value="36"/> <autn:stat class="Service" autnid="Statistics" name="1HourRequestsPerSecond" metric="3" value="0.2"/> <autn:stat class="Service" autnid="Statistics" name="1HourPeakRequestsPerSecond" metric="3" value="1.1"/> <autn:stat class="Service" autnid="Statistics" name="1HourRequests" metric="5" value="759"/> <autn:stat class="Service" autnid="Statistics" name="24HourResponseAverage" metric="9" value="17"/> <autn:stat class="Service" autnid="Statistics" name="24HourRequestsPerSecond" metric="3" value="0.2"/> <autn:stat class="Service" autnid="Statistics" name="24HourPeakRequestsPerSecond" metric="3" value="1.4"/> <autn:stat class="Service" autnid="Statistics" name="24HourRequests" metric="5" value="16139"/> <autn:stat class="Service" autnid="Statistics" name="RecentResponseAverage" metric="0" value="N/A"/> <autn:stat class="Service" autnid="Statistics" name="RecentRequestsPerSecond" metric="3" value="0.0"/> <autn:stat class="Service" autnid="Statistics" name="RecentPeakRequestsPerSecond" metric="3" value="0.0"/> <autn:stat class="Service" autnid="Statistics" name="RecentRequests" metric="5" value="0"/> <autn:stat class="Service" autnid="Statistics" name="TotalRequests" metric="5" value="70933"/> </responsedata> </autnresponse>
The sensor is set to ignore namespaces.
Oct, 2020 - Permalink
This should do:
string((//autn:stat[@name="RecentRequestsPerSecond"])/@value)
Note that "Use the value of the selected XML node" would require the node to have an actual value. You're looking for a property value of that specific node :)
Oct, 2020 - Permalink
Thank you. I did try that before asking, as that is another form I would expect to work. I wondered if the 'XML Node' was the problem, and it only worked for a node, whereas I need to get attribute values.
I tried your response (string((autn:stat[@name="RecentRequestsPerSecond"])/@value)) and still get error "stat[@name=RecentRequestsPerSecond])/@value)' has an invalid token.".
I tried it with and without namespaces.
I have settings: Sensor Value - Use the value of the selected XML node Namespaces - Use namespaces Content Type in Header - Enable (recommended)
Which part is it saying is invalid?
Oct, 2020 - Permalink
Indeed, can't get it to work either :( Perhaps the REST Custom Sensor would be more suited for this. It will retrieve the XML, convert it to JSON and then build the Sensor according to the template. The syntax/building of the template is a bit tricky, though. It will require some tinkering with https://jsonpath.com/ and XPath. https:stackoverflow.com/questions/12585968/how-to-filter-by-string-in-jsonpath might also be helpful. Sorry that this turned out trickier than I initially thought.
With kind regards,
Stephan Linke
Technical Support Team
Oct, 2020 - Permalink
I've raised this and it has become a blocker for us using PRTG. Our existing licensing has been increased to Unlimited to facilitate my team using it (we will easily become the biggest user here), but working in a sensitive and secure environment, don't have any admin rights, or access to the configuration files. So we can't just store REST configuration files in the probe system, which will make it very difficult and time consuming to develop working bespoke REST sensors.
I wondered myself, and the question has been raised by others... if we are using the HTTP XML/REST Value sensor, and have used valid XPath syntax on valid Xml, why does this PRTG sensor not accept it? Is PRTG re-implementing it's own bespoke version of XPath?
It would be much easier all round if we could get the HTTP XML/REST Value sensor working with the valid XPath and valid Xml posted above.
Oct, 2020 - Permalink
What does xxxx usually stand for in an actual XML result? I can't verify it as it says:
Unable to perform XPath operation. The prefix "xxxx" for element "xxxx:stat" is not bound.
....when using your xpath :(
Oct, 2020 - Permalink