Dynamically adding fields for all JSON properties
lennart-m opened this issue · 1 comments
Hi, I am using your datasource plugin to connect to an OData v4 service that returns sensor data. Each entity is a Measurement
having several fields for temp1_c
, temp5_c
, etc. It works great but I would like to have a multi-valued variable sensorId
with values 1
, 5
, 6
, 7
, In
so the user can select which data to display.
Maybe this is already implemented and I am just not able to see how to set this up 🙈
My problem is that I have to explicitly define the fields in the plugin. I have not found a way to make it automatically add all the fields from my JSON data, or to specify which fields to use.
Defining a parameter $select=date,${sensorId}
I am able to retrieve the backend data only for the selected sensors. But now I would like to have it output 'all the fields'.
I tried adding all the fields in the UI and using the above $select
param but then I get a 'Fields have different length' error.
Alternatively it would be OK if I could $select
all the fields from the backend, and setup to dynamically only use the fields defined in sensorId
.
Example JSON data:
{
"@odata.context": "$metadata#Measurements(ID,date,temp1_c,temp5_c,temp6_c,temp7_c,tempIn_c,humidity1,humidity5)",
"value": [
{
"ID": "0000d73f-cc93-4702-b8e5-8e78e97d7ab4",
"date": "2023-07-22T07:29:20Z",
"temp1_c": 15,
"temp5_c": 21.2,
"temp6_c": 22.1,
"temp7_c": 22.4,
"tempIn_c": 22.1,
"humidity1": 78,
"humidity5": 57
},
{
"ID": "0003a625-d67d-4e69-94dd-951df17f7e58",
"date": "2023-09-12T03:39:58Z",
"temp1_c": 17.8,
"temp5_c": 22.5,
"temp6_c": 23.4,
"temp7_c": 23.2,
"tempIn_c": 22,
"humidity1": 84,
"humidity5": 67
},
{
"ID": "000455a8-68d8-4221-8790-9f996a77f8e6",
"date": "2023-08-15T01:42:58Z",
"temp1_c": 19.4,
"temp5_c": 23.1,
"temp6_c": 23.2,
"temp7_c": 23.1,
"tempIn_c": 23.4,
"humidity1": 87,
"humidity5": 59
}
]
}
I tried a few field configurations which did not work. E.g.:
$.value[*].[/temp${sensorId}_c/]
seems to return all the JSON data of the fields in one array. I compared with this:$.value[*].[temp1_c,temp5_c]
and the array contained 6 elements for those 3 entities. So it gives another 'Fields have different length' error.
Can you tell me if this is implemented in the current version? I am using 1.3.8
of your plugin and grafana 10.1.5
.
Thanks a lot!
Lennart
Can you try using Infinity datasource plugin and you can achieve the same as seen here.
Option 1
Option 2
In infinity Instead of adding the field names by yourself, you can remove them and just have the value
as root selector. But you need to add "convert field type" transformation to change the date
field to timestamp. Otherwise grafana doesn't know about the field type and consider that as a string.
Let's know how the testing goes and recommend you to switch to Infinity plugin.