-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for elasticsearch database
- Loading branch information
1 parent
6633f52
commit 7ea2cf5
Showing
4 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
lib/newrelic_security/instrumentation-security/elasticsearch/chain.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module NewRelic::Security | ||
module Instrumentation | ||
module Elasticsearch | ||
module Chain | ||
|
||
def self.instrument! | ||
::Elastic::Transport.Client.class_eval do | ||
include NewRelic::Security::Instrumentation::Elasticsearch | ||
|
||
alias_method :perform_request_without_security, :perform_request | ||
|
||
def perform_request(*args) | ||
retval = nil | ||
event = perform_request_on_enter(*args) { retval = perform_request_without_security(*args) } | ||
perform_request_on_exit(event) { return retval } | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
38 changes: 38 additions & 0 deletions
38
lib/newrelic_security/instrumentation-security/elasticsearch/instrumentation.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require_relative 'prepend' | ||
require_relative 'chain' | ||
|
||
module NewRelic::Security | ||
module Instrumentation | ||
module Elasticsearch | ||
|
||
def perform_request_on_enter(*args) | ||
event = nil | ||
NewRelic::Security::Agent.logger.debug "OnEnter : #{self.class}.#{__method__}" | ||
hash = {} | ||
hash[:method] = args[0] | ||
hash[:path] = args[1] | ||
hash[:params] = args[2] | ||
hash[:body] = args[3].to_json | ||
hash[:headers] = args[4] | ||
event = NewRelic::Security::Agent::Control::Collector.collect(NOSQL_DB_COMMAND, [hash], ES) unless NewRelic::Security::Instrumentation::InstrumentationUtils.sql_filter_events?(hash[:sql]) | ||
rescue => exception | ||
NewRelic::Security::Agent.logger.error "Exception in hook in #{self.class}.#{__method__}, #{exception.inspect}, #{exception.backtrace}" | ||
ensure | ||
yield | ||
return event | ||
end | ||
|
||
def perform_request_on_exit(event) | ||
NewRelic::Security::Agent.logger.debug "OnExit : #{self.class}.#{__method__}" | ||
NewRelic::Security::Agent::Utils.create_exit_event(event) | ||
rescue => exception | ||
NewRelic::Security::Agent.logger.error "Exception in hook in #{self.class}.#{__method__}, #{exception.inspect}, #{exception.backtrace}" | ||
ensure | ||
yield | ||
end | ||
|
||
end | ||
end | ||
end | ||
|
||
NewRelic::Security::Instrumentation::InstrumentationLoader.install_instrumentation(:elasticsearch, ::Elastic::Transport::Client, ::NewRelic::Security::Instrumentation::Elasticsearch) |
16 changes: 16 additions & 0 deletions
16
lib/newrelic_security/instrumentation-security/elasticsearch/prepend.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module NewRelic::Security | ||
module Instrumentation | ||
module Elasticsearch | ||
module Prepend | ||
include NewRelic::Security::Instrumentation::Elasticsearch | ||
|
||
def perform_request(*args) | ||
retval = nil | ||
event = perform_request_on_enter(*args) { retval = super } | ||
perform_request_on_exit(event) { return retval } | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |