Cannot figure out web service DCI

Started by jds, March 29, 2021, 07:04:47 PM

Previous topic - Next topic

jds

Hello all,

We are trying to create a DCI that will read an Rest API json response for a value. We set up a web definition called "Test" with the api url, we added the authorization token and application/json headers. I set up the DCI according to the admin guide with "Test:/cellularBandwidth/values/total_usage" but the DCI returns <ERROR>. Here is an example of the json response:

{"cellularRssi":{"unit":"dBm","values":[{"name":"AT\u0026T","data":[{"timestamp":1616719359000,"value":"-27.0"},{"timestamp":1616721157000,"value":"-55.0"},{"timestamp":1616722951000,"value":"-48.0"},{"timestamp":1616724761000,"value":"-36.0"},{"timestamp":1616726556000,"value":"-45.0"},{"timestamp":1616728358000,"value":"-63.0"},{"timestamp":1616730161000,"value":"-52.0"},{"timestamp":1616731961000,"value":"-68.0"},{"timestamp":1616733762000,"value":"-32.0"},{"timestamp":1616735576000,"value":"-39.0"}]}]},"cellularBandwidth":{"unit":"MB","values":[{"name":"AT\u0026T","total_usage":"42.88 MB","data":[{"timestamp":1616722200000,"value":8.62},{"timestamp":1616725800000,"value":9.51},{"timestamp":1616729400000,"value":8.98},{"timestamp":1616733000000,"value":10.82},{"timestamp":1616736600000,"value":4.94}]}]}}

I think it's going to be something simple but I can't seem to find what we are doing wrong. Any help would be appreciated. Thank you!

Filipp Sudanov

Chances are that you are missing EnableWebServiceProxy=yes in config file of the agent (web services are collected via the agent that runs on the machine where the server runs, or via proxies if zoning is used).
Also make sure that "Use text parsing..." checkbox is not set.

You can use nxwsget utility to test, e.g.
nxwsget 127.0.0.1 http://api.open-notify.org/astros.json number

Ah, and there's probably the reason - json parser currently does not support arrays (the company that ordered web service functionality did not need this so it was not implemented).
This means that you can request e.g. /cellulareRssi/unit and it should return dBm, but parts in [] are not available for parsing.

jds

Thank you Filipp, I changed the DCI to request /cellularBandwidth/unit and it immediately pulled the value down in that field so it is the array that is stopping it. I'll go with plan b and create a powershell script that uses nxpush to import the values into the DCIs.