Good Day,
How do you output new line with a break within Logstash. I am currently trying to do this with the following line from my filter:
event.set('sender_domain', sender_domain.join('\n'))
I want to the output of the filter to show the data as
example.com
example1.com
example2.com
example3.com
when sending to STDOUT it outputs as per below:
{
"sender_domain" => "example.com\\example1.com\\example2.com\\example3.com"
}
When its sent via the http output plugin its sent as:
[DEBUG] 2024-11-13 13:34:04.406 [[main]>worker1] wire - http-outgoing-1 >> "example.com\example1.com\example2.com\example3.com\n"
Even when outputting to a text file as a test its comming in as:
example.com\example1.com\example2.com\example3.com\
I have the following filter:
filter {
ruby {
code => "
sender_domain = []
# Get the 'objects' array from the event
objects = event.get('objects')
if objects
# Iterate through each object in the 'objects' array
objects.each do |object|
# Check if the type is 'domain'
type = object['type']
if type == 'domain'
# Extract the IP address value and confidence if the type is 'domain'
value = object['value']
confidence = object['source_reported_confidence']
if value
# Determine the risk level based on the confidence value
risk = case confidence
when 1..50 then 'Low'
when 51..70 then 'Medium'
when 71..89 then 'High'
when 100..100 then 'Critical'
else 'Unknown' # Default to Unknown if confidence is outside expected range
end
# Only add the domain if the risk level is 'Critical'
if risk == 'Critical'
# Add the domain to the sender_domain array
sender_domain << value
end
end
end
end
end
# Join the sender_domain array into a single string with new lines and set it in the event
event.set('sender_domain', sender_domain.join('\n'))
"
}
mutate {
remove_field => ["objects"]
remove_field => ["@version"]
remove_field => ["@timestamp"]
remove_field => ["meta"]
}
}
output {
stdout {
codec => rubydebug
}
file {
path => "/usr/share/logstash/bin/domain.txt"
codec => plain { format => "%{sender_domain}\n" }
}
http {
url => "https://test.com/hx/api/v3/indicators/custom/indicator/conditions"
http_method => "patch"
format => "message"
headers => {
"accept" => "application/json, text/plain, application/json, application/json"
"authorization" => "Basic <password>"
"content_type" => "plain/text"
}
message => "%{sender_domain}\n"
}
}
I have played around with the below but it never seems to be able to actually add the new line break .
event.set('sender_domain', sender_domain.join('\n'))
I the output to be structured as:
example.com
example1.com
example2.com
example3.com
Thanks