JSON Path capability in a Webpage DataSource
I think the answer to this is gonna be “You need to script it, dummy”, but figured I’d check anyway...
I'm working on a new DataSource that pulls/interprets JSON data from a peudo-custom system via HTTP.
The system has a status page that lists the status of various components using JSON elements that have this general format:
Initial idea was that I could use the Webpage collector since it supports JSON/BSON parsing.
Issue I’m running into is that the values on most of these JSON elements are string (i.e. “true”/”false”).
I set up a DataPoint that can extract that value by putting in the JSON Path like so:
...and I can see that I’m getting the “true”/”false” values back when I do a Poll Now. But - as we know - LM won’t deal with strings natively.
Workaround I came up with was to get length of the string since true/false are different lenghts.
According to sources online, JSON Path should support a calculation of string length.
I've also verified that I can do this by pasting my data and my JSON Path expression:
...into https://jsonpath.com/
In this parser, the .length function works as expected, and returns the length of the JSON value.
However, in LogicMonitor, I'm just getting this (example failure):
NAN after processing with json
(postProcessParam: $.[ComponentName].[ParameterName&ParameterType].length, reference=, useValue=body)
Anyone know if there is a way to make this JSON Path length function work?
marting
OP3 years agoThanks for the input @Isaac Paramo and @Stuart Weenig. Going to give this a go in the near future.
LM User
·3 years agoThere’s an easier way than this:
It uses the ternary operator:
This is exactly equivalent to:
No need for a function at all, it’s overkill.
Isaac Paramo
·3 years agoHi @marting --
I’m thinking you might actually need to script this to where you’re mapping the expected string values (true/false) to integer values, such as --
Can’t fully vouch if this script will work specifically for you, but maybe something like this for some ideas --
In the above boilerplate, you would of course need to replace the
urlvariable with the URL of your JSON data source and modify theexpressionsvariable to match the structure of your JSON data source.I hope this helps to stir some new ideas for you!