I am trying to send data from python script over TCP and receive the same in the logstash. But there is no exchange of data happening.
logstash.conf
input {
tcp {
port => 5959
codec => json
}
}
filter{
}
output {
stdout {codec => rubydebug}
}
python :
import json
import socket
import sys
HOST = "127.0.0.1"
PORT = 5959
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error, msg:
sys.stderr.write("[ERROR] %s\n" % msg[1])
sys.exit(1)
try:
sock.connect((HOST, PORT))
except socket.error, msg:
sys.stderr.write("[ERROR] %s\n" % msg[1])
sys.exit(2)
msg = {'@message': 'python test message', '@tags': ['python', 'test']}
sock.sendall(json.dumps(msg))
sock.send('\n')
sock.close()
sys.exit(0)
After executing both the scripts I am neither getting any error nor data in the logstash so can someone help like what can be causing the issue.
I just added sock.send('\n') after sock.sendall(json.dumps(msg)) and it worked. It seems that there is an open issue with logstash-codec-json as1 :
The logstash 'json' plugin still requires a newline '\n' to terminate json logs being sent over a TCP input.2
References :
TCP data sending from pyton to logstash fails.
The logstash 'json' codec still requires a newline '\n' as a delimiter to terminate json logs being sent over a TCP input.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With