I utilize the GET/POST functionality very heavily to update queries, alerting criteria and thresholds for my dashboards. I’m finding a very interesting issue specific to templating though. I am attempting to simply change the selected value of a template and grafana seems to ignore my POST even though I receive a 200 response. Here is my methodology:
-
Python script monitors a consul key-value pair, upon seeing a change in value it will trigger my grafana update logic
-
Python script performs a GET against my dashboard
-
Reads the current selection for my template:
-CurrentColor = json_data_string[‘dashboard’][‘templating’][‘list’][k][‘current’][‘value’] -
Performs a simple bit of logic to replace the entire template string with the newly updated one
-RedQuery = ‘{“allValue”:null,“current”:{“selected”:false,“tags”:[],“text”:“red”,“value”:“red”},“hide”:0,“includeAll”:false,“label”:null,“multi”:false,“name”:“ATP”,“options”:[{“selected”:true,“text”:“red”,“value”:“red”},{“selected”:false,“text”:“black”,“value”:“black”}],“query”:“red, black”,“type”:“custom”}’
-BlackQuery = ‘{“allValue”:null,“current”:{“selected”:false,“tags”:[],“text”:“black”,“value”:“black”},“hide”:0,“includeAll”:false,“label”:null,“multi”:false,“name”:“ATP”,“options”:[{“selected”:false,“text”:“red”,“value”:“red”},{“selected”:true,“text”:“black”,“value”:“black”}],“query”:“red, black”,“type”:“custom”}’
-response_data=response_data.replace(atpv2RedQuery,atpv2BlackQuery) -
Python POST’s back to Grafana with the response data as the payload.
Few caveats: There are more elegant ways to replace the above data but i’ve been reduced to simplifying to the very basics to validate I am matching the strings exactly, and I can confirm that I am.
My POSTS actually include other updates which take effect, so I can guarantee that they are landing with grafana without error.
My template is simply a custom template with values of: red, black (in this case)
We are running Grafana 4.4.3 and my datasources are both Graphite and Influx
I’m hoping someone can either confirm they experience the same type of issue/spot a flow in my logic or if there is just a more direct/better way of going about this.