64 lines
2.0 KiB
Python
64 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
from flask import request, current_app, Response
|
|
from flask_classful import FlaskView, route
|
|
from utils import json_required, influxdb_instance
|
|
from influxdb_client import Point
|
|
|
|
|
|
class ReportView(FlaskView):
|
|
|
|
@route("/link", methods=['POST'])
|
|
@json_required
|
|
def link(self):
|
|
data = request.json
|
|
|
|
points = []
|
|
|
|
for type_ in ['latency', 'rate']:
|
|
if type_ in data['measurements']:
|
|
points.append(
|
|
Point(f"link_{type_}")
|
|
.tag("client", data['client'])
|
|
.tag("site", data['site'])
|
|
.field("value", data['measurements'][type_])
|
|
)
|
|
|
|
influxdb_instance.connection.write_api().write("alma", current_app.config['INFLUXDB_V2_ORG'], points)
|
|
return Response(status=201)
|
|
|
|
@route("/client", methods=['POST'])
|
|
@json_required
|
|
def client(self):
|
|
data = request.json
|
|
|
|
points = []
|
|
|
|
for type_ in ['queue']:
|
|
if type_ in data['measurements']:
|
|
points.append(
|
|
Point(f"client_{type_}")
|
|
.tag("client", data['client'])
|
|
.field("value", data['measurements'][type_])
|
|
)
|
|
|
|
influxdb_instance.connection.write_api().write("alma", current_app.config['INFLUXDB_V2_ORG'], points)
|
|
return Response(status=201)
|
|
|
|
@route("/site", methods=['POST'])
|
|
@json_required
|
|
def site(self):
|
|
data = request.json
|
|
|
|
points = []
|
|
|
|
for type_ in ['queue']:
|
|
if type_ in data['measurements']:
|
|
points.append(
|
|
Point(f"site_{type_}")
|
|
.tag("site", data['site'])
|
|
.field("value", data['measurements'][type_])
|
|
)
|
|
|
|
influxdb_instance.connection.write_api().write("alma", current_app.config['INFLUXDB_V2_ORG'], points)
|
|
return Response(status=201)
|