Hi,
May i know how to stop logstash from indexing when error found inside ruby filter?
i have following config file which will call external python script to process data and insert the records into elasticsearch.
It has no issue, except that when the ruby filter encounter error, logstash will not stop but continue to index empty records into elasticsearch. How to stop the process?
sample code:
input {
file {
path => "path/logfiledata.txt"
start_position => "beginning"
sincedb_path => "NUL"
}
}
filter {
if [message] =~ /.+/ {
ruby {
code => 'require "open3"
data = "\"" + event.get("message").strip + "\""
cmd = "python /path/pythonscritp.py #{data}"
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
begin
event.set("process_result", stdout.readline)
rescue StandardError => e
logger.error("Exception: " + "class name: " + e.class.name + " | " + "error message: " + stderr.read)
end
end'
}
}
mutate {
# to remove carrige return, new line, tab, double quote, square/curly brackets
gsub => ["process_result","[\t\n\r]", ""]
gsub => ['process_result', '"', "" ]
gsub => ["process_result", "[\{\}\[\]]", "" ]
}
kv {
source => "process_result"
field_split => ","
value_split => ":"
}
mutate {
remove_field => [ "process_result" ]
remove_field => [ "message" ]
remove_field => [ "path" ]
remove_field => [ "@version" ]
remove_field => [ "host" ]
}
}
output{
elasticsearch {
hosts => "localhost:9200"
index => "redemption_reason_%{+YYYY_MM_dd}"
user => "elastic"
password => "changeme"
ssl => true
ssl_certificate_verification => true
cacert => "certificate.crt"
}
stdout{}
}