Message format in logstash output plugin


(BHARATH MEKA) #1

Hi,

We have a custom logstash output plugin to post some messages to Slack. If I use a static message like "Testing from logstash", we are able to post it. But if I use logstash variables like %{message} or any other custom fields we defined, it is unable to resolve that field and is being as "%{message}". So for example, if I use the following output code, it is posted as "Trying from plugin: %{message}" . But I would need the actual log message to be posted to slack channel. Am I missing something here?

output {
if "alert" in [tags] {
if [alert_to] == "slack" {
slack {
channel => "#test-logstash-plugin"
description => "Trying from plugin: %{message}"
}
}
}
stdout { codec => rubydebug }
}


(Magnus B├Ąck) #2

To get %{varname} interpolation of strings, use e.g. event.sprintf(@desecription) instead of just @description.

(A public slack output plugin has been made available: https://github.com/cyli/logstash-output-slack.)


(BHARATH MEKA) #3

Thanks Magnus. It worked.

Regards,
Bharath


(system) #4