I was given some inline ruby code to do some work for me. I've put it to good use but it makes my pipeline very messy and had a couple questions. First, here's what this part of the pipe looks like right now:
if [extended_tweet][full_text] {
ruby {
code => "event.set('hashtags', event.get('[extended_tweet][full_text]').scan(/\#[a-z]*/i))"
}
ruby {
code => "event.set('links', event.get('[extended_tweet][full_text]').scan(/https?:\/\/\S*/))"
}
ruby {
code => "event.set('mentioned', event.get('[extended_tweet][full_text]').scan(/\@\S*/i))"
}
mutate {
add_field => { "extended_tweet_original" => "%{[extended_tweet][full_text]}" }
}
mutate {
gsub => [
"[extended_tweet][full_text]", "\@\S*|\#\S*,?|https?:\/\/\S*,?", "",
"[extended_tweet][full_text]", "&", "and",
"text", "\@\S*|\#\S*,?|https?:\/\/\S*,?", "",
"mentioned", "@", ""
]
lowercase => ["hashtags"]
}
} else {
ruby {
code => "event.set('hashtags', event.get('text').scan(/\#[a-z]*/i))"
}
ruby {
code => "event.set('links', event.get('text').scan(/https?:\/\/\S*/))"
}
ruby {
code => "event.set('mentioned', event.get('text').scan(/\@\S*/))"
}
mutate {
gsub => [
"text", "\@\S*|\#\S*,?|https?:\/\/\S*,?", "",
"text", "&", "and",
"mentioned", "@", ""
]
lowercase => ["hashtags"]
}
}
- Would it be more efficient to drop the code into two separate script files and have them called when appropriate vs the way I am currently doing it?
- How do I convert the inline into ruby? Anyone willing to convert one of these lines and then I can work my way backwards for the rest?
- If not into a script file, is there a way to condense all three inline scripts to run in a single ruby filter?