Created
December 2, 2020 19:18
-
-
Save CrashLaker/12eddd587124e4b41f82ba9a821a1423 to your computer and use it in GitHub Desktop.
medium-grafana-simplejson-query
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 flask import Flask, request, jsonify | |
from flask_cors import CORS | |
import dateutil.parser | |
app = Flask(__name__) | |
cors = CORS(app) | |
@app.route('/', methods=['GET', 'POST']) | |
def main(): | |
return "você acessou o /" | |
@app.route('/search', methods=['GET', 'POST']) | |
def r_search(): | |
return "você acessou o /search" | |
@app.route('/query', methods=['GET', 'POST']) | |
def r_query(): | |
req = request.json | |
from_ms = dateutil.parser.parse(req["range"]["from"]).timestamp()*1000 | |
to_ms = dateutil.parser.parse(req["range"]["to"]).timestamp()*1000 | |
response = [ | |
{ | |
"target": req["targets"][0]["target"], | |
"datapoints": [ | |
[100, from_ms], # valor 100 no inicio da range | |
[200, to_ms], # valor 200 no fim da range | |
] | |
} | |
] | |
return jsonify(response) | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', port=8081) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment