Skip to content

Commit ff6a7e5

Browse files
committed
Merge pull request offensity#1 from moniker-dns/source-conventions
Update @source fields per logstash conventions
2 parents 3323db9 + fc7a84f commit ff6a7e5

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

logstash/handler.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ class LogstashHandler(DatagramHandler):
1313
:param fqdn; Indicates whether to show fully qualified domain name or not (default False).
1414
"""
1515

16-
def __init__(self, host, port=5959, message_type='logstash', fqdn=False):
16+
def __init__(self, host, port=5959, message_type='logstash',
17+
message_path='logstash', fqdn=False):
1718
self.message_type = message_type
19+
self.message_path = message_path
1820
self.fqdn = fqdn
1921
DatagramHandler.__init__(self, host, port)
2022

@@ -36,7 +38,9 @@ def build_message(self, record):
3638
'logger': record.name,
3739
},
3840
'@message': record.getMessage(),
39-
'@source': host,
41+
'@source': self.format_source(host),
42+
'@source_host': host,
43+
'@source_path': self.message_path,
4044
'@tags': [],
4145
'@timestamp': self.format_timestamp(record.created),
4246
'@type': self.message_type,
@@ -84,4 +88,7 @@ def format_exception(self, exc_info):
8488
return ''.join(traceback.format_exception(*exc_info)) if exc_info else ''
8589

8690
def format_timestamp(self, time):
87-
return datetime.utcfromtimestamp(time).isoformat()
91+
return datetime.utcfromtimestamp(time).isoformat()
92+
93+
def format_source(self, host):
94+
return "%s://%s/%s" % (self.message_type, host, self.message_path)

0 commit comments

Comments
 (0)