From 354798583ed45c8d3ef773a8f674fd744fe945d8 Mon Sep 17 00:00:00 2001 From: Michaela Date: Sat, 9 Oct 2021 09:50:03 +1100 Subject: [PATCH] fix some listener bugs --- es.tf | 65 +++++++++++++ main.tf | 106 --------------------- query/lambda_function.py | 102 +------------------- station-api-to-iot-core/lambda_function.py | 14 ++- 4 files changed, 77 insertions(+), 210 deletions(-) diff --git a/es.tf b/es.tf index 73b6cc0..be247be 100644 --- a/es.tf +++ b/es.tf @@ -283,3 +283,68 @@ EOF resource "aws_iam_service_linked_role" "IAMServiceLinkedRole" { aws_service_name = "es.amazonaws.com" } + + +resource "aws_iam_role_policy" "IAMPolicy" { + policy = <
\n - Radio: {html.escape(listener["1"]["hits"]["hits"][0]["fields"]["software_name.keyword"][0])}-{html.escape(listener["1"]["hits"]["hits"][0]["fields"]["software_version.keyword"][0])}
\n - Antenna: {html.escape(listener["1"]["hits"]["hits"][0]["fields"]["uploader_antenna.keyword"][0])}
\n - Last Contact: {html.escape(listener["1"]["hits"]["hits"][0]["fields"]["ts"][0])}
\n - \n - """, - } - for listener in results["aggregations"]["2"]["buckets"] - ] - return json.dumps(output) - def es_request(payload, path, method): # get aws creds diff --git a/station-api-to-iot-core/lambda_function.py b/station-api-to-iot-core/lambda_function.py index 62fc6d3..3760cd2 100644 --- a/station-api-to-iot-core/lambda_function.py +++ b/station-api-to-iot-core/lambda_function.py @@ -44,14 +44,20 @@ def lambda_handler(event, context): payload["user-agent"] = event["headers"]["user-agent"] if time_delta: payload["upload_time_delta"] = time_delta - (payload["uploader_alt"], payload["uploader_position_elk"]) = ( + + payload.pop("uploader_contact_email", None) + + # clean up None reports + + if "uploader_position" in payload and None in payload["uploader_position"]: + payload.pop("uploader_position", None) + + if "uploader_position" in payload: + (payload["uploader_alt"], payload["uploader_position_elk"]) = ( payload["uploader_position"][2], f"{payload['uploader_position'][0]},{payload['uploader_position'][1]}", ) - payload.pop("uploader_contact_email", None) index = datetime.datetime.utcnow().strftime("listeners-%Y-%m") - print(payload) - print(index) payload["ts"] = datetime.datetime.utcnow().isoformat() es_request(json.dumps(payload),f"{index}/_doc","POST")