Skip to content

Feat: support nested fields, add timeout configuration #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 3.3.0
- feat: Added `timeout` configuration to control RESTForce timeout settings (defaults to `60`)
- feat: Added support for reference fields (`parent__r.child`)
- feat: Added support for built-in SOQL functions (etc. `toLabel(field__c) field`)
- refactor: Removed field_type inferring (elastic can infer it / logstash mapping can be configured for special cases)
- fix: update Apache licence to suppress compiling warning

## 3.2.0
- Added `use_tooling_api` configuration to connect to the Salesforce Tooling API instead of the regular Rest API. [#26](https://github.com/logstash-plugins/logstash-input-salesforce/pull/26)

Expand Down
21 changes: 12 additions & 9 deletions lib/logstash/inputs/salesforce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class LogStash::Inputs::Salesforce < LogStash::Inputs::Base
# By default, this uses the default Restforce API version.
# To override this, set this to something like "32.0" for example
config :api_version, :validate => :string, :required => false
# RESTForce request timeout in seconds.
config :timeout, :validate => :number, :required => false
# Consumer Key for authentication. You must set up a new SFDC
# connected app with oath to use this output. More information
# can be found here:
Expand Down Expand Up @@ -106,22 +108,22 @@ def register
public
def run(queue)
results = client.query(get_query())
@logger.debug("Query results:", :results => results)
if results && results.first
results.each do |result|
event = LogStash::Event.new()
decorate(event)
@sfdc_fields.each do |field|
field_type = @sfdc_field_types[field]
# PARENT.CHILD => PARENT
# function(field) field => field
field = field.split(/\./).first.split(/\s/).last
value = result.send(field)

# Remove RESTForce's nested 'attributes' field for reference fields
value.is_a?(Hash) ? value = value.tap { |hash| hash.delete(:attributes)} : value

event_key = @to_underscores ? underscore(field) : field
if not value.nil?
case field_type
when 'datetime', 'date'
event.set(event_key, format_time(value))
else
event.set(event_key, value)
end
end
event.set(event_key, value)
end
queue << event
end
Expand Down Expand Up @@ -155,6 +157,7 @@ def client_options
options.merge!({ :host => "test.salesforce.com" })
end
options.merge!({ :api_version => @api_version }) if @api_version
options.merge!({ :timeout => @timeout }) if @timeout
return options
end

Expand Down
6 changes: 3 additions & 3 deletions logstash-input-salesforce.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.name = 'logstash-input-salesforce'
s.version = '3.2.0'
s.licenses = ['Apache License (2.0)']
s.version = '3.3.0'
s.licenses = ['Apache-2.0']
s.summary = "Creates events based on a Salesforce SOQL query"
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
s.authors = ["Russ Savage"]
Expand All @@ -20,7 +20,7 @@ Gem::Specification.new do |s|
# Gem dependencies
s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
s.add_runtime_dependency "logstash-codec-plain"
s.add_runtime_dependency "restforce", ">= 5", "< 5.2"
s.add_runtime_dependency "restforce", ">= 5", "< 5.3"
s.add_development_dependency 'logstash-devutils'
s.add_development_dependency 'vcr'
s.add_development_dependency 'webmock'
Expand Down