Module: NewRelic::Security::Instrumentation::ActiveRecord::ConnectionAdapters::SQLite3Adapter

Included in:
Prepend
Defined in:
lib/newrelic_security/instrumentation-security/active_record/sqlite3_adapter/chain.rb,
lib/newrelic_security/instrumentation-security/active_record/sqlite3_adapter/prepend.rb,
lib/newrelic_security/instrumentation-security/active_record/sqlite3_adapter/instrumentation.rb

Defined Under Namespace

Modules: Chain, Prepend

Instance Method Summary collapse

Instance Method Details

#exec_delete_on_enter(*var, **key_vars) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/newrelic_security/instrumentation-security/active_record/sqlite3_adapter/instrumentation.rb', line 145

def exec_delete_on_enter(*var, **key_vars)
  event = nil
  NewRelic::Security::Agent.logger.debug "OnEnter : #{self.class}.#{__method__}"
  type_casted_binds = []
  binds = var[2] #third arg
  if !binds.nil? && !binds.empty? #if bind params present
    binds.each { |x|
      if x.is_a? Integer or x.is_a? String
        type_casted_binds << x
      elsif x.is_a? Array and x[0].is_a? ::ActiveRecord::ConnectionAdapters::Column
        type_casted_binds << x[1].to_s
      else
        type_casted_binds << x.value_before_type_cast.to_s
      end
    }
    # binds_copy = binds.clone  #it is a shallow copy
    # type_casted_binds = type_casted_binds(binds_copy.to_s)
  end
  hash = {}
  hash[:sql] = var[0]  #sql query
  hash[:parameters] = type_casted_binds #bind params
  event = NewRelic::Security::Agent::Control::Collector.collect(SQL_DB_COMMAND, [hash], SQLITE) 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

#exec_delete_on_exit(event) ⇒ Object



174
175
176
177
178
179
180
181
# File 'lib/newrelic_security/instrumentation-security/active_record/sqlite3_adapter/instrumentation.rb', line 174

def exec_delete_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

#exec_query_on_enter(*var, **key_vars) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/newrelic_security/instrumentation-security/active_record/sqlite3_adapter/instrumentation.rb', line 31

def exec_query_on_enter(*var, **key_vars)
  event = nil
  NewRelic::Security::Agent.logger.debug "OnEnter : #{self.class}.#{__method__}"
  type_casted_binds = []
  binds = var[2] #third arg
  if !binds.nil? && !binds.empty? #if bind params present
    binds.each { |x|
      if x.is_a? Integer or x.is_a? String
        type_casted_binds << x
      elsif x.is_a? Array and x[0].is_a? ::ActiveRecord::ConnectionAdapters::Column
        type_casted_binds << x[1].to_s
      else
        type_casted_binds << x.value_before_type_cast.to_s
      end
    }
    # binds_copy = binds.clone  #it is a shallow copy
    # type_casted_binds = type_casted_binds(binds_copy.to_s)
  end
  hash = {}
  hash[:sql] = var[0]  #sql query
  hash[:parameters] = type_casted_binds #bind params
  event = NewRelic::Security::Agent::Control::Collector.collect(SQL_DB_COMMAND, [hash], SQLITE) 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

#exec_query_on_exit(event) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/newrelic_security/instrumentation-security/active_record/sqlite3_adapter/instrumentation.rb', line 60

def exec_query_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

#exec_update_on_enter(*var, **key_vars) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/newrelic_security/instrumentation-security/active_record/sqlite3_adapter/instrumentation.rb', line 107

def exec_update_on_enter(*var, **key_vars)
  event = nil
  NewRelic::Security::Agent.logger.debug "OnEnter : #{self.class}.#{__method__}"
  type_casted_binds = []
  binds = var[2] #third arg
  if !binds.nil? && !binds.empty? #if bind params present
    binds.each { |x|
      if x.is_a? Integer or x.is_a? String
        type_casted_binds << x
      elsif x.is_a? Array and x[0].is_a? ::ActiveRecord::ConnectionAdapters::Column
        type_casted_binds << x[1].to_s
      else
        type_casted_binds << x.value_before_type_cast.to_s
      end
    }
    # binds_copy = binds.clone  #it is a shallow copy
    # type_casted_binds = type_casted_binds(binds_copy.to_s)
  end
  hash = {}
  hash[:sql] = var[0]  #sql query
  hash[:parameters] = type_casted_binds #bind params
  event = NewRelic::Security::Agent::Control::Collector.collect(SQL_DB_COMMAND, [hash], SQLITE) 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

#exec_update_on_exit(event) ⇒ Object



136
137
138
139
140
141
142
143
# File 'lib/newrelic_security/instrumentation-security/active_record/sqlite3_adapter/instrumentation.rb', line 136

def exec_update_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

#execute_on_enter(sql, name) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/newrelic_security/instrumentation-security/active_record/sqlite3_adapter/instrumentation.rb', line 8

def execute_on_enter(sql, name)
  event = nil
  NewRelic::Security::Agent.logger.debug "OnEnter : #{self.class}.#{__method__}"
  hash = {}
  hash[:sql] = sql  #sql query
  hash[:parameters] = []
  event = NewRelic::Security::Agent::Control::Collector.collect(SQL_DB_COMMAND, [hash], SQLITE) 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

#execute_on_exit(event) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/newrelic_security/instrumentation-security/active_record/sqlite3_adapter/instrumentation.rb', line 22

def execute_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

#internal_exec_query_on_enter(*var, **key_vars) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/newrelic_security/instrumentation-security/active_record/sqlite3_adapter/instrumentation.rb', line 69

def internal_exec_query_on_enter(*var, **key_vars)
  event = nil
  NewRelic::Security::Agent.logger.debug "OnEnter : #{self.class}.#{__method__}"
  type_casted_binds = []
  binds = var[2] #third arg
  if !binds.nil? && !binds.empty? #if bind params present
    binds.each { |x|
      if x.is_a? Integer or x.is_a? String
        type_casted_binds << x
      elsif x.is_a? Array and x[0].is_a? ::ActiveRecord::ConnectionAdapters::Column
        type_casted_binds << x[1].to_s
      else
        type_casted_binds << x.value_before_type_cast.to_s
      end
    }
    # binds_copy = binds.clone  #it is a shallow copy
    # type_casted_binds = type_casted_binds(binds_copy.to_s)
  end
  hash = {}
  hash[:sql] = var[0]  #sql query
  hash[:parameters] = type_casted_binds #bind params
  event = NewRelic::Security::Agent::Control::Collector.collect(SQL_DB_COMMAND, [hash], SQLITE) 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

#internal_exec_query_on_exit(event) ⇒ Object



98
99
100
101
102
103
104
105
# File 'lib/newrelic_security/instrumentation-security/active_record/sqlite3_adapter/instrumentation.rb', line 98

def internal_exec_query_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