Hi All,
I'm trying logstash with python TCP input, I followed some sample code here:
Adapted a bit the code, but I'm sending the exact same message through tcp.
From python output:
(MainThread) 2017-08-21 12:07:35,688 INFO b'{"@message": "Python test message", "@tags": ["python", "test"]}'
here is my logstash pipeline config file:
input {
tcp {
port => "9563"
host => "127.0.0.1"
codec => "json_lines"
}
I turned on logstash logging into debug, and found out this log every time I execute the code:
[2017-08-21T12:07:35,691][DEBUG][logstash.inputs.tcp ] Accepted connection {:client=>"127.0.0.1:58256", :server=>"127.0.0.1:9563"}
[2017-08-21T12:07:35,694][DEBUG][logstash.codecs.jsonlines] config LogStash::Codecs::JSONLines/@id = "json_lines_4e6cdf95-0891-4c7f-90a1-c30fb1804c45"
[2017-08-21T12:07:35,694][DEBUG][logstash.codecs.jsonlines] config LogStash::Codecs::JSONLines/@enable_metric = true
[2017-08-21T12:07:35,695][DEBUG][logstash.codecs.jsonlines] config LogStash::Codecs::JSONLines/@charset = "UTF-8"
[2017-08-21T12:07:35,695][DEBUG][logstash.codecs.jsonlines] config LogStash::Codecs::JSONLines/@delimiter = "\n"
`[2017-08-21T12:07:35,697][DEBUG][logstash.inputs.tcp ] Connection closed {:client=>"127.0.0.1:58256"}
But after that, nothing happened, there is no stdout output, no log file generated, neither does any elasticsearch record created.
After hours of trying, kind of solved issue, I tried with http input, using request lib in python , now Logstash can receive all the data properly and log them into the file properly.
For other new user as reference:
Here is the python code:
def __sendContentHTTP(self, content):
payload = {
'@message': content,
'@tags': ['your tag']
}
headers = {
'Content-Type': 'application/json'
}
r = requests.post('http://yourserver:yourport', data=json.dumps(payload), headers=headers)
Thanks
Probably that's the issue. The message I sent was about an object array with about 100 element in there, after json dumps from python, it probably became 1 line.
I might try a bit more and see
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.