# encoding: utf-8
require "logstash/filters/base"
require "logstash/namespace"
require "base62-rb"
# This example filter will replace the contents of the default
# message field with whatever you specify in the configuration.
#
# It is only intended to be used as an example.
class LogStash::Filters::Kannel < LogStash::Filters::Base
# Setting the config_name here is required. This is how you
# configure this filter from your Logstash config.
#
# filter {
# kannel {
# message => "My message..."
# }
# }
#
config_name "kannel"
# Replace the message with this value.
config :message, :validate => :string, :default => "Hello World!"
public
def register
# Add instance variables
end # def register
public
def filter(event)
if @message
dec = self.get_campaign_id("RTDM aaaSd2.P.f1", "Receive SMS")
# using the event.set API
event.set("message", dec)
# correct debugging log statement for reference
# using the event.get API
@logger.debug? && @logger.debug("Message is now: #{event.get("message")}")
end
# filter_matched should go in the last line of our successful code
filter_matched(event)
end # def filter
public
def is_printable(str)
return str.match(/^[\x20-\x7E]*$/)
end
public
def get_campaign_id(text, action)
if action == "Receive SMS"
if is_printable(text)
if text != "ACTIM3GP"
if match = text.match(/^(?<keyword>[a-zA-Z0-9]+ )?(?<base62>[a-zA-Z0-9]+).*$/)
keyword, base62 = match.captures
return Base62.decode(base62)
end
end
end
end
return 0
end
end
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}