mirror of
https://github.com/EDCD/EDDN.git
synced 2025-04-27 13:42:14 +03:00
Monitor: types pass
This commit is contained in:
parent
c0af9b1a97
commit
0400854390
@ -5,6 +5,7 @@ import collections
|
|||||||
import datetime
|
import datetime
|
||||||
import zlib
|
import zlib
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
from typing import OrderedDict
|
||||||
|
|
||||||
import gevent
|
import gevent
|
||||||
import mysql.connector as mariadb
|
import mysql.connector as mariadb
|
||||||
@ -58,13 +59,13 @@ def date(__format) -> datetime.datetime:
|
|||||||
|
|
||||||
|
|
||||||
@app.route('/ping', method=['OPTIONS', 'GET'])
|
@app.route('/ping', method=['OPTIONS', 'GET'])
|
||||||
def ping():
|
def ping() -> str:
|
||||||
"""Respond to a ping request."""
|
"""Respond to a ping request."""
|
||||||
return 'pong'
|
return 'pong'
|
||||||
|
|
||||||
|
|
||||||
@app.route('/getTotalSoftwares/', method=['OPTIONS', 'GET'])
|
@app.route('/getTotalSoftwares/', method=['OPTIONS', 'GET'])
|
||||||
def get_total_softwares():
|
def get_total_softwares() -> str:
|
||||||
"""Respond with data about total uploading software counts."""
|
"""Respond with data about total uploading software counts."""
|
||||||
response.set_header("Access-Control-Allow-Origin", "*")
|
response.set_header("Access-Control-Allow-Origin", "*")
|
||||||
db = mariadb.connect(
|
db = mariadb.connect(
|
||||||
@ -95,7 +96,7 @@ def get_total_softwares():
|
|||||||
|
|
||||||
|
|
||||||
@app.route('/getSoftwares/', method=['OPTIONS', 'GET'])
|
@app.route('/getSoftwares/', method=['OPTIONS', 'GET'])
|
||||||
def get_softwares():
|
def get_softwares() -> str:
|
||||||
"""Respond with hit stats for all uploading software."""
|
"""Respond with hit stats for all uploading software."""
|
||||||
response.set_header("Access-Control-Allow-Origin", "*")
|
response.set_header("Access-Control-Allow-Origin", "*")
|
||||||
db = mariadb.connect(
|
db = mariadb.connect(
|
||||||
@ -103,7 +104,7 @@ def get_softwares():
|
|||||||
password=Settings.MONITOR_DB['password'],
|
password=Settings.MONITOR_DB['password'],
|
||||||
database=Settings.MONITOR_DB['database']
|
database=Settings.MONITOR_DB['database']
|
||||||
)
|
)
|
||||||
softwares = collections.OrderedDict()
|
softwares: OrderedDict = collections.OrderedDict()
|
||||||
|
|
||||||
date_start = request.GET.get('dateStart', str(date('%Y-%m-%d'))).strip()
|
date_start = request.GET.get('dateStart', str(date('%Y-%m-%d'))).strip()
|
||||||
date_end = request.GET.get('dateEnd', str(date('%Y-%m-%d'))).strip()
|
date_end = request.GET.get('dateEnd', str(date('%Y-%m-%d'))).strip()
|
||||||
@ -129,7 +130,7 @@ def get_softwares():
|
|||||||
|
|
||||||
|
|
||||||
@app.route('/getTotalSchemas/', method=['OPTIONS', 'GET'])
|
@app.route('/getTotalSchemas/', method=['OPTIONS', 'GET'])
|
||||||
def get_total_schemas():
|
def get_total_schemas() -> str:
|
||||||
"""Respond with total hit stats for all schemas."""
|
"""Respond with total hit stats for all schemas."""
|
||||||
response.set_header("Access-Control-Allow-Origin", "*")
|
response.set_header("Access-Control-Allow-Origin", "*")
|
||||||
db = mariadb.connect(
|
db = mariadb.connect(
|
||||||
@ -156,7 +157,7 @@ def get_total_schemas():
|
|||||||
|
|
||||||
|
|
||||||
@app.route('/getSchemas/', method=['OPTIONS', 'GET'])
|
@app.route('/getSchemas/', method=['OPTIONS', 'GET'])
|
||||||
def get_schemas():
|
def get_schemas() -> str:
|
||||||
"""Respond with schema hit stats between given datetimes."""
|
"""Respond with schema hit stats between given datetimes."""
|
||||||
response.set_header("Access-Control-Allow-Origin", "*")
|
response.set_header("Access-Control-Allow-Origin", "*")
|
||||||
db = mariadb.connect(
|
db = mariadb.connect(
|
||||||
@ -164,7 +165,7 @@ def get_schemas():
|
|||||||
password=Settings.MONITOR_DB['password'],
|
password=Settings.MONITOR_DB['password'],
|
||||||
database=Settings.MONITOR_DB['database']
|
database=Settings.MONITOR_DB['database']
|
||||||
)
|
)
|
||||||
schemas = collections.OrderedDict()
|
schemas: OrderedDict = collections.OrderedDict()
|
||||||
|
|
||||||
date_start = request.GET.get('dateStart', str(date('%Y-%m-%d'))).strip()
|
date_start = request.GET.get('dateStart', str(date('%Y-%m-%d'))).strip()
|
||||||
date_end = request.GET.get('dateEnd', str(date('%Y-%m-%d'))).strip()
|
date_end = request.GET.get('dateEnd', str(date('%Y-%m-%d'))).strip()
|
||||||
@ -192,7 +193,7 @@ def get_schemas():
|
|||||||
class Monitor(Thread):
|
class Monitor(Thread):
|
||||||
"""Monitor thread class."""
|
"""Monitor thread class."""
|
||||||
|
|
||||||
def run(self):
|
def run(self) -> None:
|
||||||
"""Handle receiving Gateway messages and recording stats."""
|
"""Handle receiving Gateway messages and recording stats."""
|
||||||
context = zmq.Context()
|
context = zmq.Context()
|
||||||
|
|
||||||
@ -202,7 +203,7 @@ class Monitor(Thread):
|
|||||||
for binding in Settings.MONITOR_RECEIVER_BINDINGS:
|
for binding in Settings.MONITOR_RECEIVER_BINDINGS:
|
||||||
receiver.connect(binding)
|
receiver.connect(binding)
|
||||||
|
|
||||||
def monitor_worker(message):
|
def monitor_worker(message: bytes) -> None:
|
||||||
db = mariadb.connect(
|
db = mariadb.connect(
|
||||||
user=Settings.MONITOR_DB['user'],
|
user=Settings.MONITOR_DB['user'],
|
||||||
password=Settings.MONITOR_DB['password'],
|
password=Settings.MONITOR_DB['password'],
|
||||||
@ -210,16 +211,16 @@ class Monitor(Thread):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Separate topic from message
|
# Separate topic from message
|
||||||
message = message.split(' |-| ')
|
message_split = message.split(b' |-| ')
|
||||||
|
|
||||||
# Handle gateway not sending topic
|
# Handle gateway not sending topic
|
||||||
if len(message) > 1:
|
if len(message_split) > 1:
|
||||||
message = message[1]
|
message = message_split[1]
|
||||||
else:
|
else:
|
||||||
message = message[0]
|
message = message_split[0]
|
||||||
|
|
||||||
message = zlib.decompress(message)
|
message_text = zlib.decompress(message)
|
||||||
json = simplejson.loads(message)
|
json = simplejson.loads(message_text)
|
||||||
|
|
||||||
# Default variables
|
# Default variables
|
||||||
schema_id = json['$schemaRef']
|
schema_id = json['$schemaRef']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user