We have a Python script to collect data and ship to Logstash. Please find the python script and logstash config below.
import socket
import json
import logging
from datetime import datetime
import sys
print("starting to send data to Elastic search")
# Create TCP/IP socket
print("Creating TCP/IP socket")
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
message = []
try:
# Connect to port where server is running
server_address = ('<host>', 50504)
sock.connect(server_address)
data = {'@test' : 'test1', '@message': 'python test message', '@tags': ['python', 'test']}
sock.sendall(json.dumps(data).encode())
print("Sent")
except socket.error as e:
sys.stderr.write(str(e))
finally:
sock.close()
Logstash conf looks like the following:
input {
tcp {
port => 50504
type => "xxx"
id => "yyy"
codec => json
}
}
filter {
if [type] == "xxx" {
json {
source => "message"
}
}
date {
match => ["time", "yyyy-MM-dd'T'HH:mm:ss.SSSSSSZ", "ISO8601", "MMM d HH:mm:ss", "MMM dd HH:mm:ss"]
}
}
output {
elasticsearch {
hosts => ["<hosts>:4080"]
index => "logstash-%{[type]}-s3-%{+YYYY.MM.dd}"
id => "zzz"
}
}
Getting the following error on logstash log:
[2020-07-02T16:08:12,176][WARN ][logstash.outputs.elasticsearch] Could not index event to Elasticsearch. {:status=>400, :action=>["index", {:_id=>nil, :_index=>"logstash-xxx-s3-2020.07.02", :_type=>"_doc", :routing=>nil}, #<LogStash::Event:0x119d0bf>], :response=>{"index"=>{"_index"=>"logstash-convergence-status-s3-2020.07.02", "_type"=>"_doc", "_id"=>nil, "status"=>400, "error"=>{"type"=>"illegal_argument_exception", "reason"=>"[_default_] mappings are not allowed on new indices and should no longer be used. See [https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking-changes-7.0.html#default-mapping-not-allowed] for more information."}}}}
Wanted to check if python could be used for shipping logs to logstash from version 6.8 and above.
You have an index template that includes a _default_ mapping, which was deprecated in 6.0 and results in an error in 7.0 or above. Update the template and remove the _default_ mapping.
[2020-07-02T18:30:07,054][WARN ][logstash.outputs.elasticsearch] Could not index event to Elasticsearch. {:status=>400, :action=>["index", {:_id=>nil, :_index=>"logstash-xxx-s3-2020.07.02", :_type=>"_doc", :routing=>nil}, #<LogStash::Event:0x62492c0f>], :response=>{"index"=>{"_index"=>"logstash-xxx-s3-2020.07.02", "_type"=>"_doc", "_id"=>nil, "status"=>400, "error"=>{"type"=>"illegal_argument_exception", "reason"=>"[_default_] mappings are not allowed on new indices and should no longer be used. See [https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking-changes-7.0.html#default-mapping-not-allowed] for more information."}}}}
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.