lib/logstash/outputs/charrington.rb in logstash-output-charrington-0.1.0 vs lib/logstash/outputs/charrington.rb in logstash-output-charrington-0.1.1
- old
+ new
@@ -105,10 +105,13 @@
config :enable_event_as_json_keyword, validate: :boolean, default: false
# The magic key used to convert the whole event to JSON. If you need this, and you have the default in your events, you can use this to change your magic keyword.
config :event_as_json_keyword, validate: :string, default: '@event'
+ # The database schema
+ config :schema, validate: :string, default: ''
+
def register
@logger.info('JDBC - Starting up')
load_jar_files!
@@ -212,13 +215,16 @@
table_name = create_table_name(event)
return "INSERT INTO #{table_name} #{columns} VALUES #{values}", hashed.keys
end
def create_table_name(event)
- if event.nil? || event.to_hash["event"].nil?
- raise TableNameNil.new("Table name is nil", event)
- end
- event.to_hash["event"].to_s.strip.gsub(/[ -]+/, "_").downcase
+ raise TableNameNil.new("Table name is nil", event) if event.nil?
+
+ event = event.to_hash["event"].to_s.strip
+ raise TableNameNil.new("Table name is nil", event) if event.empty?
+
+ schema = @schema.empty? ? '' : "#{@schema}."
+ "#{schema}#{event.gsub(/[ \-_]+/, "_").downcase}"
end
def prepared_statement(keys)
keys.map do |key|
turn_into_wrapped(key)