|
33 | 33 |
|
34 | 34 | # password => 'super-secret'
|
35 | 35 | # security_token => 'SECURITY TOKEN FOR THIS USER'
|
36 |
| -# sfdc_object_name => 'Opportunity' |
| 36 | +# sfdc_soql_query => 'SELECT Id FROM Account' |
37 | 37 | # }
|
38 | 38 | # }
|
39 | 39 | #
|
@@ -85,29 +85,20 @@ class LogStash::Inputs::Salesforce < LogStash::Inputs::Base
|
85 | 85 | # generting a security token, see:
|
86 | 86 | # https://help.salesforce.com/apex/HTViewHelpDoc?id=user_security_token.htm
|
87 | 87 | config :security_token, :validate => :string, :required => true
|
88 |
| - # The name of the salesforce object you are creating or updating |
89 |
| - config :sfdc_object_name, :validate => :string, :required => true |
90 |
| - # These are the field names to return in the Salesforce query |
91 |
| - # If this is empty, all fields are returned. |
92 |
| - config :sfdc_fields, :validate => :array, :default => [] |
93 |
| - # These options will be added to the WHERE clause in the |
94 |
| - # SOQL statement. Additional fields can be filtered on by |
95 |
| - # adding field1 = value1 AND field2 = value2 AND... |
96 |
| - config :sfdc_filters, :validate => :string, :default => "" |
| 88 | + # Plain SOQL query |
| 89 | + config :sfdc_soql_query, :validate => :string, :required => true |
97 | 90 | # Setting this to true will convert SFDC's NamedFields__c to named_fields__c
|
98 | 91 | config :to_underscores, :validate => :boolean, :default => false
|
99 | 92 |
|
100 | 93 | public
|
101 | 94 | def register
|
102 | 95 | require 'restforce'
|
103 |
| - obj_desc = client.describe(@sfdc_object_name) |
104 |
| - @sfdc_field_types = get_field_types(obj_desc) |
105 |
| - @sfdc_fields = get_all_fields if @sfdc_fields.empty? |
| 96 | + @sfdc_fields = get_sfdc_fields |
106 | 97 | end # def register
|
107 | 98 |
|
108 | 99 | public
|
109 | 100 | def run(queue)
|
110 |
| - results = client.query(get_query()) |
| 101 | + results = client.query(@sfdc_soql_query) |
111 | 102 | @logger.debug("Query results:", :results => results)
|
112 | 103 | if results && results.first
|
113 | 104 | results.each do |result|
|
@@ -162,29 +153,12 @@ def client_options
|
162 | 153 | end
|
163 | 154 |
|
164 | 155 | private
|
165 |
| - def get_query() |
166 |
| - query = ["SELECT",@sfdc_fields.join(','), |
167 |
| - "FROM",@sfdc_object_name] |
168 |
| - query << ["WHERE",@sfdc_filters] unless @sfdc_filters.empty? |
169 |
| - query << "ORDER BY LastModifiedDate DESC" if @sfdc_fields.include?('LastModifiedDate') |
170 |
| - query_str = query.flatten.join(" ") |
171 |
| - @logger.debug? && @logger.debug("SFDC Query", :query => query_str) |
172 |
| - return query_str |
173 |
| - end |
174 |
| - |
175 |
| - private |
176 |
| - def get_field_types(obj_desc) |
177 |
| - field_types = {} |
178 |
| - obj_desc.fields.each do |f| |
179 |
| - field_types[f.name] = f.type |
180 |
| - end |
181 |
| - @logger.debug? && @logger.debug("Field types", :field_types => field_types.to_s) |
182 |
| - return field_types |
183 |
| - end |
184 |
| - |
185 |
| - private |
186 |
| - def get_all_fields |
187 |
| - return @sfdc_field_types.keys |
| 156 | + def get_sfdc_fields |
| 157 | + extracted_fields = sfdc_soql_query.gsub(/SELECT (.+) FROM.+/i, '\1') |
| 158 | + extracted_fields_as_array = extracted_fields.split(',').collect { |item| item.strip } |
| 159 | + logger.debug("Extracted fields: ", :extracted_fields_as_array => extracted_fields_as_array.to_s) |
| 160 | + |
| 161 | + return extracted_fields_as_array; |
188 | 162 | end
|
189 | 163 |
|
190 | 164 | private
|
|
0 commit comments