From b3ccedc34a1a0a2c007cf833ab62da1f3f47700a Mon Sep 17 00:00:00 2001 From: Lance O'Connor Date: Mon, 24 Feb 2014 20:35:07 +0000 Subject: [PATCH 1/3] Close LOGSTASH-1933: Add two (2) new config stanzas to IRC output: pre_string: Message you want emitted to IRC server before the event text post_string: Message you want emitted to the IRC server after the event text [12:32] This is a pre message [12:32] This is the actual message [12:32] Tis is a post message In both cases, they are sent as seperate messages to the IRC server, leaving the event text unmodified. (N.B. My 1st real modification to the ruby codebase, so someone who knows ruby should really validate I did this correctly.) --- lib/logstash/outputs/irc.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/logstash/outputs/irc.rb b/lib/logstash/outputs/irc.rb index cd1d527db..99687d4c7 100644 --- a/lib/logstash/outputs/irc.rb +++ b/lib/logstash/outputs/irc.rb @@ -43,6 +43,12 @@ class LogStash::Outputs::Irc < LogStash::Outputs::Base # Limit the rate of messages sent to IRC in messages per second. config :messages_per_second, :validate => :number, :default => 0.5 + # Static string before event + config :pre_string, :validate => :string, :required => false + + # Static string before event + config :post_string, :validate => :string, :required => false + public def register require "cinch" @@ -74,7 +80,13 @@ class LogStash::Outputs::Irc < LogStash::Outputs::Base text = event.sprintf(@format) @bot.channels.each do |channel| @logger.debug("Sending to...", :channel => channel, :text => text) + if !@pre_string.nil? + channel.msg(pre_string) + end channel.msg(text) + if !@post_string.nil? + channel.msg(post_string) + end end # channels.each end # def receive end # class LogStash::Outputs::Irc From fe87534dd990243ae04cce7f73ef4cde93554abf Mon Sep 17 00:00:00 2001 From: Lance O'Connor Date: Mon, 24 Feb 2014 21:09:16 +0000 Subject: [PATCH 2/3] Modified syntax as per suggestion --- lib/logstash/outputs/irc.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/logstash/outputs/irc.rb b/lib/logstash/outputs/irc.rb index 99687d4c7..3c9e065f4 100644 --- a/lib/logstash/outputs/irc.rb +++ b/lib/logstash/outputs/irc.rb @@ -80,13 +80,9 @@ class LogStash::Outputs::Irc < LogStash::Outputs::Base text = event.sprintf(@format) @bot.channels.each do |channel| @logger.debug("Sending to...", :channel => channel, :text => text) - if !@pre_string.nil? - channel.msg(pre_string) - end + channel.msg(pre_string) if !@pre_string.nil? channel.msg(text) - if !@post_string.nil? - channel.msg(post_string) - end + channel.msg(post_string) if !@post_string.nil? end # channels.each end # def receive end # class LogStash::Outputs::Irc From 0ba3cc2eb3de55f9e04826ed0a407c4b297dc6e0 Mon Sep 17 00:00:00 2001 From: Lance O'Connor Date: Mon, 24 Feb 2014 21:18:31 +0000 Subject: [PATCH 3/3] Fix the 2yyp typo, and properly attribute post_string to come *after* the event --- lib/logstash/outputs/irc.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/logstash/outputs/irc.rb b/lib/logstash/outputs/irc.rb index 3c9e065f4..7a5791eaf 100644 --- a/lib/logstash/outputs/irc.rb +++ b/lib/logstash/outputs/irc.rb @@ -46,7 +46,7 @@ class LogStash::Outputs::Irc < LogStash::Outputs::Base # Static string before event config :pre_string, :validate => :string, :required => false - # Static string before event + # Static string after event config :post_string, :validate => :string, :required => false public