some validation
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Torma Kristóf 2020-07-30 15:36:09 +02:00
parent 46169a54bd
commit fc80c1cbe2
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047

View File

@ -53,9 +53,13 @@ def setup_rabbit() -> None:
def on_message(channel, method_frame, header_frame, body): def on_message(channel, method_frame, header_frame, body):
msg_json = json.loads(body) msg_json = json.loads(body)
if 'probability' not in msg_json:
logging.error("Malformed message from broker")
if msg_json['probability'] > 0.5: if msg_json['probability'] > 0.5:
r = requests.get(f"http://{config.INPUT_HOSTNAME}/sample/{msg_json['tag']}") r = requests.get(f"http://{config.INPUT_HOSTNAME}/sample/{msg_json['tag']}")
r.raise_for_status() r.raise_for_status()
if 'device_id' not in r.json():
logging.error("Input-service response invalid")
mqtt.publish(subtopic=r.json()['device_id'], mqtt.publish(subtopic=r.json()['device_id'],
message=json.dumps({"command": "doAlert"})) message=json.dumps({"command": "doAlert"}))