...
Code Block | ||||
---|---|---|---|---|
| ||||
import requests import jwt from datetime import datetime, timedelta, timezone def get_jwt(username, secret, algorithm): payload_data = { "username": username, "exp": datetime.now(tz=timezone.utc) + timedelta(minutes=15) } encoded = jwt.encode( payload=payload_data, key=secret, algorithm=algorithm ) return encoded url = "http://localhost:8085/query" username = "influxadmin" secret = 'my super secret pass phrase' algorithm="HS256" jwt = get_jwt(username, secret, algorithm) headers = { "Authorization": "Bearer "+jwt.decode('utf-8') } querystring = {"pretty": "true", "db": "ts_pms_metrics", "q": "SELECT \"eventName\", \"domain\", \"sourceName\", \"measuredEntityUserName\", \"startEpochMicrosec\", \"startEpochDate\", \"lastEpochMicrosec\", \"lastEpochDate\", \"measuredEntityDn\", \"measObjInstId\", \"sMeasType\" ,\"sValue\", \"suspectFlag\" FROM \"pms_data\" WHERE \"time\" > now()-20s"} response = requests.request("GET", url=url, headers=headers, params=querystring) print(response.text) |
To create a new user in influxdb v1 use the following commands:
Code Block | ||||
---|---|---|---|---|
| ||||
/ # influx -username influxadmin -password influxadmin -execute 'SHOW DATABASES'
name: databases
name
----
_internal
ts_db
ts_db1
ts_test
ts_host_metrics
ts_pms_metrics
ts_pms_metrics2
null
ts_pms_bucket
ts_pms_bucket2
ts_pms_bucket3
ts_pms_bucket4
ts_pms_metrics3
telegraf
ts_pms_metrics_v1
/ # influx -username influxadmin -password influxadmin -database ts_pms_metrics
Connected to http://localhost:8086 version 1.7.11
InfluxDB shell version: 1.7.11
> CREATE USER influxweb WITH PASSWORD 'influxweb' WITH ALL PRIVILEGES |
The first command shows the available databases
The second one logs into the ts_pms_metrics database using the admin user.
The last command creates a new user "influxweb"
Note: JWT authorization is no longer supported in Influxdb v. 2
...