Created
February 14, 2017 22:08
-
-
Save zezuladp/9159a20b409a9f5f5a9fff585991626b to your computer and use it in GitHub Desktop.
a script that updates the templated variables to be the ones that I wanted within a specified timeframe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from influxdb import InfluxDBClient | |
import json | |
import requests | |
INFLUX_UN | |
INFLUX_PW | |
INFLUX_DB | |
INFLUX_PORT | |
INFLUX_HOST | |
INFLUX_MEASUREMENT | |
INFLUX_QUERY | |
GRAFANA_API_KEY | |
GRAFANA_HOST | |
GRAFANA_DB | |
client = InfluxDBClient(INFLUX_HOST, INFLUX_PORT, INFLUX_UN, INFLUX_PW, INFLUX_DB) | |
result = client.query('INFLUX_QUERY where time > now() - 1d') | |
userids = [] | |
for item in list(result[INFLUX_MEASUREMENT]): | |
userids.append(item[u'distinct']) | |
headers = {"Authorization": "Bearer GRAFANA_API_KEY"} | |
dashboard = requests.get("http://GRAFANA_HOST/api/dashboards/db/GRAFANA_DB", headers=headers).json() | |
dashboard['dashboard']['templating']['list'][1]['current'] = {u'text': ' + '.join(userids)} | |
dashboard['dashboard']['templating']['list'][1]['current']['value'] = userids | |
dashboard['overwrite'] = True | |
headers["Content-Type"] = 'application/json' | |
result = requests.post("http://GRAFANA_HOST/api/dashboards/db", headers=headers, data=json.dumps(dashboard)) | |
print result.json() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment