add label to docker network and convert timestamps for elastic (#2009)

Co-authored-by: burnettk <burnettk@users.noreply.github.com>
This commit is contained in:
Kevin Burnett 2024-07-30 13:58:03 +00:00 committed by GitHub
parent 70c0d51a0f
commit d4ecd3462d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 1 deletions

View File

@ -49,6 +49,9 @@ dev-env: stop-dev build-images poetry-i be-poetry-i be-db-clean fe-npm-i
start-dev: stop-dev
$(DOCKER_COMPOSE) up -d
start-event-stream:
$(DOCKER_COMPOSE) up -d event-stream
stop-dev:
$(DOCKER_COMPOSE) down

View File

@ -7,7 +7,7 @@ KIBANA_PASSWORD ?= kibana
net-start:
docker network create $(NETWORK) || true
docker network create --label com.docker.compose.network=default $(NETWORK) || true
net-stop:
docker network rm $(NETWORK) || true

View File

@ -1,3 +1,5 @@
from datetime import datetime
import pytz
import json
import os, os.path
import socket
@ -42,6 +44,13 @@ def init_urllib():
urllib.request.install_opener(opener)
def send_event(event):
if 'timestamp' in event:
timestamp_value = event['timestamp']
# if timestamp is an integer or a float (any numeric type), convert to a iso8601 string so that elastic will index it as a date
if isinstance(timestamp_value, (int, float)):
utc_time = datetime.fromtimestamp(timestamp_value, tz=pytz.UTC)
event['timestamp'] = utc_time.isoformat()
try:
post_body = json.dumps(event).encode("utf-8")
request = urllib.request.Request(ELASTICSEARCH_URL)