2021-11-16 20:40:17 +01:00
|
|
|
#!/usr/bin/env python3
|
2021-12-02 23:08:25 +01:00
|
|
|
from flask import request, current_app, Response
|
|
|
|
from flask_classful import FlaskView, route
|
2021-11-17 23:07:46 +01:00
|
|
|
from utils import json_required, influxdb_instance
|
|
|
|
from influxdb_client import Point
|
2021-11-16 20:40:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ReportView(FlaskView):
|
2021-11-17 23:07:46 +01:00
|
|
|
|
2021-12-02 23:08:25 +01:00
|
|
|
@route("/link", methods=['POST'])
|
2021-11-17 23:07:46 +01:00
|
|
|
@json_required
|
2021-12-02 23:08:25 +01:00
|
|
|
def link(self):
|
2021-11-17 23:07:46 +01:00
|
|
|
data = request.json
|
|
|
|
|
|
|
|
points = []
|
|
|
|
|
2021-12-02 23:08:25 +01:00
|
|
|
for type_ in ['latency', 'rate']:
|
2021-11-17 23:07:46 +01:00
|
|
|
if type_ in data['measurements']:
|
|
|
|
points.append(
|
2021-12-02 23:08:25 +01:00
|
|
|
Point(f"link_{type_}")
|
2021-11-17 23:07:46 +01:00
|
|
|
.tag("client", data['client'])
|
2021-12-02 23:08:25 +01:00
|
|
|
.tag("site", data['site'])
|
|
|
|
.field("value", data['measurements'][type_])
|
2021-11-17 23:07:46 +01:00
|
|
|
)
|
|
|
|
|
2021-12-02 23:08:25 +01:00
|
|
|
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)
|
2021-11-17 23:07:46 +01:00
|
|
|
return Response(status=201)
|