Class: Fluentd::Setting::InSql
- Inherits:
-
Object
- Object
- Fluentd::Setting::InSql
- Includes:
- ActiveModel::Model, Common
- Defined in:
- lib/fluent/plugin/in_sql.rb
Constant Summary collapse
- KEYS =
[ :host, :port, :database, :adapter, :username, :password, :tag_prefix, :select_interval, :select_limit, :state_file, :table, :all_tables ].freeze
Instance Attribute Summary collapse
-
#fields_descriptions ⇒ Object
Returns the value of attribute fields_descriptions.
Class Method Summary collapse
Instance Method Summary collapse
- #advanced_options ⇒ Object
- #common_options ⇒ Object
- #plugin_name ⇒ Object
- #table ⇒ Object
- #table=(value) ⇒ Object
- #table_fields ⇒ Object
- #to_config ⇒ Object
Instance Attribute Details
#fields_descriptions ⇒ Object
Returns the value of attribute fields_descriptions.
23 24 25 |
# File 'lib/fluent/plugin/in_sql.rb', line 23 def fields_descriptions @fields_descriptions end |
Class Method Details
.create_from_config(config) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/fluent/plugin/in_sql.rb', line 155 def self.create_from_config config @setting = {} @tables = [] table = {} to_table = false str_params = config.split("\r\n").map{|str| str.squish} str_params.each do |str| case str when '<source>', '</source>' next when '<table>' to_table = true when '</table>' to_table = false @tables << table table = {} when 'all_tables' @setting[:all_tables] = true else param = str.split(' ') if to_table table[param.first] = param.second else @setting[param.first] = param.second unless param.first == 'type' end end if @tables.present? @setting[:table] = @tables end end self.new @setting end |
.initial_params ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fluent/plugin/in_sql.rb', line 32 def self.initial_params { host: 'localhost', database: 'rdb_database', adapter: 'mysql2', username: 'myusername', password: 'mypassword', tag_prefix: 'my.rdb', select_interval: '60s', select_limit: '500', state_file: "/tmp/data_enchilada-sql-#{Fluentd.instance.id}-#{Time.now.to_i}.pos", table: [ { table: 'rdb_table', tag: 'rdb_table_tag', update_column: 'updated_at', time_column: 'updated_at', primary_key: '' } ] } end |
Instance Method Details
#advanced_options ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/fluent/plugin/in_sql.rb', line 90 def [ :select_interval, :select_limit, :state_file ] end |
#common_options ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/fluent/plugin/in_sql.rb', line 78 def [ :host, :port, :database, :adapter, :username, :password, :tag_prefix ] end |
#plugin_name ⇒ Object
188 189 190 |
# File 'lib/fluent/plugin/in_sql.rb', line 188 def plugin_name "sql" end |
#table ⇒ Object
104 105 106 |
# File 'lib/fluent/plugin/in_sql.rb', line 104 def table @tables end |
#table=(value) ⇒ Object
98 99 100 101 102 |
# File 'lib/fluent/plugin/in_sql.rb', line 98 def table=(value) @tables = value.map do |t| t.map{|field, value| ([field.to_sym, value] if table_fields.include?(field.to_sym))}.to_h end end |
#table_fields ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'lib/fluent/plugin/in_sql.rb', line 108 def table_fields [ :table, :tag, :update_column, :time_column, :primary_key ] end |
#to_config ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/fluent/plugin/in_sql.rb', line 118 def to_config indent = " " config = "<source>\n" config << "#{indent}type #{plugin_type_name}\n" self.class.const_get(:KEYS).each do |key| next if key == :table next if key == :all_tables config << indent config << conf(key) config << "\n" end tables = send(:table).reject{|t| t.values.join('') == ''} rescue [] if tables.present? && all_tables != '1' tables.each do |tab| config << "\n" config << indent config << "<table>\n" tab.each do |key, value| config << indent config << indent config << "#{key} #{value}" config << "\n" end config << indent config << "</table>\n" end else config << indent config << 'all_tables' config << "\n" end config << "</source>\n" config.gsub(/^[ ]*\n/m, "") end |