Skip to content

Commit

Permalink
style: fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarolopez committed Sep 27, 2024
1 parent 4bf1ad5 commit 6d2773e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
27 changes: 10 additions & 17 deletions caso/messenger/logstash.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@

"""Module containing a Logstask cASO messenger."""

import json
import datetime
import socket

from oslo_config import cfg
from oslo_log import log
import six

from caso import exception
import caso.messenger
#add json lib
import json
#add datetime lib
import datetime


opts = [
cfg.StrOpt("host", default="localhost", help="Logstash host to send records to."),
Expand Down Expand Up @@ -55,26 +53,21 @@ def push(self, records):

# NOTE(acostantini): code for the serialization and push of the
# records in logstash. JSON format to be used and encoding UTF-8
"""Serialization of records to be sent to logstash"""
if not records:
return

#Actual timestamp to be added on each record
cdt = datetime.datetime.now()
# Actual timestamp to be added on each record
ct = int(datetime.datetime.now().timestamp())

#Open the connection with LS
# Open the connection with LS
self.sock.connect((self.host, self.port))

"""Push records to logstash using tcp."""
try:
for record in records:
#serialization of record
rec=record.serialization_message()
#cASO timestamp added to each record
rec['caso-timestamp']=ct
#Send the record to LS
self.sock.send((json.dumps(rec)+'\n').encode('utf-8'))
for record in records:
# serialization of record
rec = record.serialization_message()
rec["caso-timestamp"] = ct
self.sock.send((json.dumps(rec) + "\n").encode("utf-8"))
except socket.error as e:
raise exception.LogstashConnectionError(
host=self.host, port=self.port, exception=e
Expand Down
5 changes: 2 additions & 3 deletions caso/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,14 @@ def ssm_message(self):
"""Render record as the expected SSM message."""
raise NotImplementedError("Method not implemented")


def serialization_message(self):
"""Render record as the expected logstash message."""
opts = {
"by_alias": True,
"exclude_none": True,
}
# NOTE(acostatnini): part related to the definition of the logstash message to be
# serialized before to send data
# NOTE(acostatnini): part related to the definition of the logstash message to
# be serialized before to send data
# NOTE(aloga): do not iter over the dictionary returned by record.dict() as this
# is just a dictionary representation of the object, where no serialization is
# done. In order to get objects correctly serialized we need to convert to JSON,
Expand Down

0 comments on commit 6d2773e

Please sign in to comment.