Skip to content

Commit 6d2773e

Browse files
committed
style: fix errors
1 parent 4bf1ad5 commit 6d2773e

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

caso/messenger/logstash.py

+10-17
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,16 @@
1616

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

19+
import json
20+
import datetime
1921
import socket
2022

2123
from oslo_config import cfg
2224
from oslo_log import log
23-
import six
2425

2526
from caso import exception
2627
import caso.messenger
27-
#add json lib
28-
import json
29-
#add datetime lib
30-
import datetime
28+
3129

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

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

62-
#Actual timestamp to be added on each record
63-
cdt = datetime.datetime.now()
59+
# Actual timestamp to be added on each record
6460
ct = int(datetime.datetime.now().timestamp())
6561

66-
#Open the connection with LS
62+
# Open the connection with LS
6763
self.sock.connect((self.host, self.port))
6864

69-
"""Push records to logstash using tcp."""
7065
try:
71-
for record in records:
72-
#serialization of record
73-
rec=record.serialization_message()
74-
#cASO timestamp added to each record
75-
rec['caso-timestamp']=ct
76-
#Send the record to LS
77-
self.sock.send((json.dumps(rec)+'\n').encode('utf-8'))
66+
for record in records:
67+
# serialization of record
68+
rec = record.serialization_message()
69+
rec["caso-timestamp"] = ct
70+
self.sock.send((json.dumps(rec) + "\n").encode("utf-8"))
7871
except socket.error as e:
7972
raise exception.LogstashConnectionError(
8073
host=self.host, port=self.port, exception=e

caso/record.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,14 @@ def ssm_message(self):
4848
"""Render record as the expected SSM message."""
4949
raise NotImplementedError("Method not implemented")
5050

51-
5251
def serialization_message(self):
5352
"""Render record as the expected logstash message."""
5453
opts = {
5554
"by_alias": True,
5655
"exclude_none": True,
5756
}
58-
# NOTE(acostatnini): part related to the definition of the logstash message to be
59-
# serialized before to send data
57+
# NOTE(acostatnini): part related to the definition of the logstash message to
58+
# be serialized before to send data
6059
# NOTE(aloga): do not iter over the dictionary returned by record.dict() as this
6160
# is just a dictionary representation of the object, where no serialization is
6261
# done. In order to get objects correctly serialized we need to convert to JSON,

0 commit comments

Comments
 (0)