Class: ManageEngine::APMConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/agent/configuration/am_configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAPMConfig

Returns a new instance of APMConfig.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/agent/configuration/am_configuration.rb', line 14

def initialize
@obj = ManageEngine::APMObjectHolder.instance

    #@config = @obj.util.readProperties(@obj.constants.apm_conf)
configureFile
@agenthost = Socket.gethostname
assignConfig
@obj.log.setLevel @config["apminsight.log.level"]
@instance_id  = 0
@agent_enabled = false
@alreadyconnected = checkAgentInfo
@site24x7 = checkLicenseFile
if (@site24x7)
  @site24x7url = @license_key.start_with?('eu_') ? @obj.constants.site24x7EUurl : @license_key.start_with?('cn_') ? @obj.constants.site24x7CNurl : @license_key.start_with?('au_') ? @obj.constants.site24x7AUurl : @license_key.start_with?('in_') ? @obj.constants.site24x7INurl : @license_key.start_with?('gd_') ? @obj.constants.site24x7GDurl : @license_key.start_with?('jp_') ? @obj.constants.site24x7JPurl : @obj.constants.site24x7USurl
end
@db_operations =["select","insert","update","delete"]
urlMergePattern
@hostType = getHostType
@obj.log.info "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
@obj.log.info "APP HOME #{File.absolute_path(".")} "
@obj.log.info "APP HOME #{Dir.pwd} "
@obj.log.info "Agent Version : #{ManageEngine::APMInsight::VERSION}"
#@obj.log.info "Configuration : "
#@obj.log.info "Hostname : #{@agenthost}"
@obj.log.info "Host Type: #{@hostType}"
@obj.log.info "Agent Already Connected : #{@alreadyconnected}"
@obj.log.info "Agent Enabled : #{@agent_enabled}"
@obj.log.info "Allowed DB Operations : #{@db_operations}"
#     @config.each do|key,val|
#     @obj.log.info "#{key} => #{val}"
#       end
@obj.log.info "URL Merge Patterns"
@url_merge_pattern.each do |key, val|
  @obj.log.info "#{key} => #{val}"
end
@obj.log.info "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
@app_db="dummydb"
@app_dispatcher = getDispatcher
@lastupdatedtime=File.mtime(@obj.constants.apm_conf).to_i
end

Instance Attribute Details

#agent_enabledObject (readonly)

Returns the value of attribute agent_enabled.



12
13
14
# File 'lib/agent/configuration/am_configuration.rb', line 12

def agent_enabled
  @agent_enabled
end

#agenthostObject (readonly)

Returns the value of attribute agenthost.



10
11
12
# File 'lib/agent/configuration/am_configuration.rb', line 10

def agenthost
  @agenthost
end

#agentportObject (readonly)

Returns the value of attribute agentport.



10
11
12
# File 'lib/agent/configuration/am_configuration.rb', line 10

def agentport
  @agentport
end

#alreadyconnectedObject (readonly)

Returns the value of attribute alreadyconnected.



10
11
12
# File 'lib/agent/configuration/am_configuration.rb', line 10

def alreadyconnected
  @alreadyconnected
end

#apdex_tObject (readonly)

Returns the value of attribute apdex_t.



11
12
13
# File 'lib/agent/configuration/am_configuration.rb', line 11

def apdex_t
  @apdex_t
end

#apmhostObject (readonly)

Returns the value of attribute apmhost.



10
11
12
# File 'lib/agent/configuration/am_configuration.rb', line 10

def apmhost
  @apmhost
end

#apmportObject (readonly)

Returns the value of attribute apmport.



10
11
12
# File 'lib/agent/configuration/am_configuration.rb', line 10

def apmport
  @apmport
end

#app_dbObject

Returns the value of attribute app_db.



13
14
15
# File 'lib/agent/configuration/am_configuration.rb', line 13

def app_db
  @app_db
end

#app_dispatcherObject

Returns the value of attribute app_dispatcher.



13
14
15
# File 'lib/agent/configuration/am_configuration.rb', line 13

def app_dispatcher
  @app_dispatcher
end

#appnameObject (readonly)

Returns the value of attribute appname.



11
12
13
# File 'lib/agent/configuration/am_configuration.rb', line 11

def appname
  @appname
end

#connect_intervalObject (readonly)

Returns the value of attribute connect_interval.



12
13
14
# File 'lib/agent/configuration/am_configuration.rb', line 12

def connect_interval
  @connect_interval
end

#connection_retryObject (readonly)

Returns the value of attribute connection_retry.



12
13
14
# File 'lib/agent/configuration/am_configuration.rb', line 12

def connection_retry
  @connection_retry
end

#db_operationsObject (readonly)

Returns the value of attribute db_operations.



12
13
14
# File 'lib/agent/configuration/am_configuration.rb', line 12

def db_operations
  @db_operations
end

#dbmetric_overflow_tObject (readonly)

Returns the value of attribute dbmetric_overflow_t.



11
12
13
# File 'lib/agent/configuration/am_configuration.rb', line 11

def dbmetric_overflow_t
  @dbmetric_overflow_t
end

#delayedStartObject (readonly)

Returns the value of attribute delayedStart.



10
11
12
# File 'lib/agent/configuration/am_configuration.rb', line 10

def delayedStart
  @delayedStart
end

#hostTypeObject (readonly)

Returns the value of attribute hostType.



10
11
12
# File 'lib/agent/configuration/am_configuration.rb', line 10

def hostType
  @hostType
end

#instance_idObject (readonly)

Returns the value of attribute instance_id.



10
11
12
# File 'lib/agent/configuration/am_configuration.rb', line 10

def instance_id
  @instance_id
end

#is_securedObject (readonly)

Returns the value of attribute is_secured.



12
13
14
# File 'lib/agent/configuration/am_configuration.rb', line 12

def is_secured
  @is_secured
end

#lastupdatedtimeObject

Returns the value of attribute lastupdatedtime.



13
14
15
# File 'lib/agent/configuration/am_configuration.rb', line 13

def lastupdatedtime
  @lastupdatedtime
end

#license_keyObject (readonly)

Returns the value of attribute license_key.



10
11
12
# File 'lib/agent/configuration/am_configuration.rb', line 10

def license_key
  @license_key
end

#logs_dirObject (readonly)

Returns the value of attribute logs_dir.



12
13
14
# File 'lib/agent/configuration/am_configuration.rb', line 12

def logs_dir
  @logs_dir
end

#metric_overflow_tObject (readonly)

Returns the value of attribute metric_overflow_t.



11
12
13
# File 'lib/agent/configuration/am_configuration.rb', line 11

def metric_overflow_t
  @metric_overflow_t
end

#proxy_hostObject (readonly)

Returns the value of attribute proxy_host.



12
13
14
# File 'lib/agent/configuration/am_configuration.rb', line 12

def proxy_host
  @proxy_host
end

#proxy_passObject (readonly)

Returns the value of attribute proxy_pass.



11
12
13
# File 'lib/agent/configuration/am_configuration.rb', line 11

def proxy_pass
  @proxy_pass
end

#proxy_portObject (readonly)

Returns the value of attribute proxy_port.



12
13
14
# File 'lib/agent/configuration/am_configuration.rb', line 12

def proxy_port
  @proxy_port
end

#proxy_userObject (readonly)

Returns the value of attribute proxy_user.



11
12
13
# File 'lib/agent/configuration/am_configuration.rb', line 11

def proxy_user
  @proxy_user
end

#proxyneededObject (readonly)

Returns the value of attribute proxyneeded.



11
12
13
# File 'lib/agent/configuration/am_configuration.rb', line 11

def proxyneeded
  @proxyneeded
end

#site24x7Object (readonly)

Returns the value of attribute site24x7.



10
11
12
# File 'lib/agent/configuration/am_configuration.rb', line 10

def site24x7
  @site24x7
end

#site24x7urlObject (readonly)

Returns the value of attribute site24x7url.



10
11
12
# File 'lib/agent/configuration/am_configuration.rb', line 10

def site24x7url
  @site24x7url
end

#sql_captureObject (readonly)

Returns the value of attribute sql_capture.



11
12
13
# File 'lib/agent/configuration/am_configuration.rb', line 11

def sql_capture
  @sql_capture
end

#sql_capture_paramsObject (readonly)

Returns the value of attribute sql_capture_params.



11
12
13
# File 'lib/agent/configuration/am_configuration.rb', line 11

def sql_capture_params
  @sql_capture_params
end

#sql_trace_tObject (readonly)

Returns the value of attribute sql_trace_t.



11
12
13
# File 'lib/agent/configuration/am_configuration.rb', line 11

def sql_trace_t
  @sql_trace_t
end

#trace_overflow_tObject (readonly)

Returns the value of attribute trace_overflow_t.



11
12
13
# File 'lib/agent/configuration/am_configuration.rb', line 11

def trace_overflow_t
  @trace_overflow_t
end

#trans_traceObject (readonly)

Returns the value of attribute trans_trace.



11
12
13
# File 'lib/agent/configuration/am_configuration.rb', line 11

def trans_trace
  @trans_trace
end

#trans_trace_tObject (readonly)

Returns the value of attribute trans_trace_t.



11
12
13
# File 'lib/agent/configuration/am_configuration.rb', line 11

def trans_trace_t
  @trans_trace_t
end

#txn_skip_listenObject (readonly)

Returns the value of attribute txn_skip_listen.



12
13
14
# File 'lib/agent/configuration/am_configuration.rb', line 12

def txn_skip_listen
  @txn_skip_listen
end

#url_merge_patternObject (readonly)

Returns the value of attribute url_merge_pattern.



12
13
14
# File 'lib/agent/configuration/am_configuration.rb', line 12

def url_merge_pattern
  @url_merge_pattern
end

Instance Method Details

#assignConfigObject



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/agent/configuration/am_configuration.rb', line 177

def assignConfig
initValues
 @config.each do |key,value|
   value = checkAndGetEnvValue(value)
   case key
   when "application.name" then @appname=value
                                if (ENV.has_key?('APM_APPLICATION_NAME'))
                                  @appname = ENV['APM_APPLICATION_NAME']
                                end
   when "apm.host" then @apmhost=value
   when "apm.port" then @apmport=isInteger(@apmport,value)
   when "license.key" then @license_key=value
                           if (@license_key.empty? && ENV.has_key?('S247_LICENSE_KEY'))
                             @license_key = ENV['S247_LICENSE_KEY']
                           end
   when "behind.proxy" then @proxyneeded=@obj.util.getBooleanValue value
   when "agent.server.port" then @agentport=isInteger(@agentport,value)
   when "apdex.threshold" then @apdex_t=isFloat(@apdex_t,value)
   when "transaction.trace.enabled" then @trans_trace=@obj.util.getBooleanValue value
   when "transaction.trace.threshold" then @trans_trace_t=isFloat(@trans_trace_t,value)
   when "sql.capture.enabled" then @sql_capture=@obj.util.getBooleanValue value
   when "transaction.trace.sql.parametrize" then @sql_capture_params=@obj.util.getBooleanValue value
   when "transaction.trace.sql.stacktrace.threshold" then @sql_trace_t=isFloat(@sql_trace_t,value)
   when "proxy.server.host" then @proxy_host=value
   when "proxy.server.port" then @proxy_port=isInteger(@proxy_port,value)
   when "proxy.auth.username" then @proxy_user=value
   when "proxy.auth.password" then @proxy_pass=@obj.util.decrypt value, @license_key
                                      if (@proxy_pass == nil)
                                        @proxy_pass = value
                                      end
   when "apm.protocol.https" then @is_secured=@obj.util.getBooleanValue value
   when "apminsight.log.dir" then @logs_dir=value
   when "apminsight.log.level" then @obj.log.setLevel value
   when "agent.connection.retry" then @connection_retry=value #Not in Conf - yet to come
   when "agent.polling.interval" then   @connect_interval=isInteger(@connect_interval, value)#Not in Conf - yet to come
   when "transaction.skip.listening" then @txn_skip_listen=@obj.util.getArray value.gsub("\s", ""),","
   when "metricstore.metric.bucket.size" then @metric_overflow_t = isInteger(@metric_overflow_t, value)
     when "metricstore.dbmetric.bucket.size" then @dbmetric_overflow_t = isInteger(@dbmetric_overflow_t, value)
     when "transaction.tracestore.size" then @trace_overflow_t = isInteger(@trace_overflow_t, value)
   when "agent.delay.start" then @delayedStart=@obj.util.getBooleanValue value
  end
 end
   store_encrypted_data(@config)
end

#checkAgentInfoObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/agent/configuration/am_configuration.rb', line 100

def checkAgentInfo
  if FileTest.exist?(@obj.constants.agent_conf)
    @obj.log.debug "Status : Agent Already Connected"
    props = @obj.util.readProperties(@obj.constants.agent_conf)
    instance_id = props["agent.id"]
    
    if (instance_id == nil || instance_id == "")
      # If instance id is not found or empty, it means the apminsight.info is being modified by user
      # Ignore all its entry
      @obj.log.warn "File: #{@obj.constants.agent_conf} is corrupted. Agent will continue ignoring these values."
      return false
    else
      @instance_id = instance_id
    end
    
    @agent_enabled= @obj.util.getBooleanValue props["agent.enabled"]
    true
  else
    @obj.log.info "Status : Agent not connected"
    false
  end
end

#checkAndGetEnvValue(data) ⇒ Object

Checks whether the given value is Environment Variable



223
224
225
226
227
228
229
230
231
232
# File 'lib/agent/configuration/am_configuration.rb', line 223

def checkAndGetEnvValue(data)
  begin
      value = "#{data}"[/\{(.*)\}/,1]
      if (value != nil && ENV.has_key?(value))
        return data.gsub(/\{.*\}/, ENV[value])
    end
  rescue Exception=>e
  end
  return data
end

#checkLicenseFileObject



123
124
125
126
127
128
129
130
131
132
# File 'lib/agent/configuration/am_configuration.rb', line 123

def checkLicenseFile
    @obj.constants.setLicenseKey @license_key
  if(@license_key.start_with?('APMI_')) 
    @obj.log.info "Connecting to App Manager"
    false
  else
    @obj.log.info "Connecting to Site24x7"
    true
  end
end

#configureFileObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/agent/configuration/am_configuration.rb', line 55

def configureFile
  begin
    if(FileTest.exist?(@obj.constants.apm_conf))
      #conf file exists in APPlication Home
        @obj.log.debug "Config File Exists. It is read from #{@obj.constants.apm_conf}"
      @config = @obj.util.readProperties(@obj.constants.apm_conf)
        secureConfFile "#{@obj.constants.apm_conf}"
    else
      gemSpecs = Gem.loaded_specs[@obj.constants.s247_apm_gem]
      if (gemSpecs == nil)
        gemSpecs = Gem.loaded_specs[@obj.constants.apm_gem]
      end
      gem_conf = gemSpecs.full_gem_path
      #gem_conf = File.join(gem_conf, 'lib')
      gem_conf = File.join(gem_conf, 'conf')
      gem_conf = File.join(gem_conf, 'apminsight.conf')
      #conf file not exists in APPlications Home. So 1. copy it for gem locations
      if @obj.util.copyFiles gem_conf,@obj.constants.apm_conf
        #copied sucessfully
        @obj.log.info "Config File copied to application home directory. It is read from #{@obj.constants.apm_conf}"
        @config = @obj.util.readProperties(@obj.constants.apm_conf)
          secureConfFile "#{@obj.constants.apm_conf}"
      else
        #Problem in copying, so reading props from Conf file in Gem Location
        @obj.log.warn "Config File not copied. It is read from #{gem_conf}"
        @config = @obj.util.readProperties(gem_conf)
          secureConfFile gem_conf
      end
    end
  rescue Exception=>e
    @obj.log.info "[Exception] Problem in Reading Configuration File : \n File : #{@obj.constants.apm_conf}"
    @obj.log.logException "#{e.message}",e
    @config = @obj.util.readProperties(gem_conf)
  ensure
  end
end

#getAgentConfigDataObject



334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# File 'lib/agent/configuration/am_configuration.rb', line 334

def getAgentConfigData
  agentconfig = Hash.new
  agentconfig["last.modified.time"]=@lastupdatedtime*1000
  agentconfig["apdex.threshold"]=@apdex_t
  agentconfig["sql.capture.enabled"]=0
  if @sql_capture
    agentconfig["sql.capture.enabled"]=1
  end
  agentconfig["transaction.trace.enabled"]=0
  if @trans_trace
    agentconfig["transaction.trace.enabled"]=1
  end
  agentconfig["transaction.trace.threshold"]=@trans_trace_t
  agentconfig["transaction.trace.sql.parametrize"]=0
  if @sql_capture_params
    agentconfig["transaction.trace.sql.parametrize"]=1
  end
  agentconfig["transaction.trace.sql.stacktrace.threshold"]=@sql_trace_t
  agentconfig["transaction.tracking.request.interval"]=1
  agentconfig
end

#getAgentInfoObject



296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/agent/configuration/am_configuration.rb', line 296

def getAgentInfo
  data =  Hash.new
  agentdata = Hash.new
  agentdata = {"application.type"=>"RUBY","application.name"=>@appname,"hostname"=>@agenthost,"port"=>@agentport,"agent.version"=>ManageEngine::APMInsight::MAJOR_VERSION}
  if (@hostType != nil)
    agentdata["host.type"]=@hostType
  end
  data["agent_info"]=agentdata
  data["environment"]=getEnvData
  data["custom_config_info"]=getAgentConfigData
  data
end

#getDispatcherObject



356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
# File 'lib/agent/configuration/am_configuration.rb', line 356

def getDispatcher
  
  @obj.log.info "Server: #{ENV['SERVER_SOFTWARE']}"
  
    dispatcher = "unknown"
    if defined?(PhusionPassenger) then
      dispatcher = "passenger"
    end
    if defined?(Unicorn) then
      dispatcher = "unicorn"
    end
    if defined?(Rainbows) then
      dispatcher = "rainbows"
    end
    dispatcher
end

#getEnvDataObject



309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/agent/configuration/am_configuration.rb', line 309

def getEnvData
  env =  Hash.new
  begin
    env["OS"] = Gem::Platform.local.os
    env["OS Version"] = Gem::Platform.local.version
    env["OS Arch"] = Gem::Platform.local.cpu
    env["Ruby Version"] = "#{RUBY_VERSION}"
      gemSpecs = Gem.loaded_specs[@obj.constants.s247_apm_gem]
      if (gemSpecs == nil)
        gemSpecs = Gem.loaded_specs[@obj.constants.apm_gem]
      end
      if (gemSpecs != nil)
        env["Agent Installed Path"] = gemSpecs.full_gem_path
      end
    
#     ENV.to_hash.each do |key, value|
#       env[key] = value
#     end
  env["Application Path"] = "#{Dir.pwd}"
  rescue Exception=>e
    @obj.log.warn "Error in capturing env data. #{e.message}"
  end
  env
end

#getHostTypeObject



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/agent/configuration/am_configuration.rb', line 259

def getHostType
  begin
      # Check for AWS environment
    url = URI.parse('http://169.254.169.254/latest/meta-data/') # AWS metadata url
      request = Net::HTTP::Get.new(url.path)
    response = Net::HTTP.start(url.host, url.port, :read_timeout => 2) {|http| http.request(request)}
      if (response.kind_of? Net::HTTPOK)
        @hostType = "AWS"
        return @hostType
      end
    rescue Exception => e
    end
    
    begin
      #Check for Azure environment
      url = URI.parse('http://169.254.169.254/metadata/v1/maintenance') # Azure metadata url
      request = Net::HTTP::Get.new(url.path)
      response = Net::HTTP.start(url.host, url.port, :read_timeout => 2) {|http| http.request(request)}
      if (response.kind_of? Net::HTTPOK)
        @hostType = "AZURE"
        return @hostType
      end
  rescue Exception => e
  end
  
    begin
      # Check for Heroku env. In the backgroud it is using AWS EC2, hence sending as AWS
      if (ENV.has_key?('DYNO') || ENV.has_key?('STACK'))
        @hostType = "AWS"
        return @hostType
      end
    rescue Exception => e
    end
  
    @hostType = nil
end

#initValuesObject



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/agent/configuration/am_configuration.rb', line 154

def initValues
  @apmport=8080
  @appname="My Application"
  @proxyneeded = false
  @proxy_host="localhost"
  @proxy_port=80
  @proxy_user=""
  @proxy_pass=""
  @is_secured=false
  @logs_dir="./log"
  @connection_retry = 0
  @connect_interval = 60
  @apdex_t=0.5
  @txn_skip_listen=Array.new
  @trans_trace_t=2
  @sql_trace_t=3
  @metric_overflow_t=250
    @dbmetric_overflow_t=500
  @trace_overflow_t=30
  @site24x7url = @obj.constants.site24x7USurl #default agent communication URL
    @delayedStart = false
end

#isFloat(default, value) ⇒ Object



383
384
385
386
387
388
389
390
# File 'lib/agent/configuration/am_configuration.rb', line 383

def isFloat default,value
  if @obj.util.is_float value
    value.to_f
  else
    default.to_f
    @obj.log.info "Problem in getting Integer Value #{value} .. So setting default value #{default} "
  end
end

#isInteger(default, value) ⇒ Object



373
374
375
376
377
378
379
380
381
# File 'lib/agent/configuration/am_configuration.rb', line 373

def isInteger default,value
  if @obj.util.is_integer value
    value.to_i
  else
    @obj.log.info "Problem in getting Integer Value #{value} .. So setting default value #{default} "
    default.to_i
  end

end

#secureConfFile(file) ⇒ Object



92
93
94
95
96
97
98
# File 'lib/agent/configuration/am_configuration.rb', line 92

def secureConfFile(file)
  begin
    File.chmod(0600, file)
  rescue Exception => e
    @obj.log.warn "Unable to secure the conf file #{file}"
  end
end

#store_encrypted_data(config) ⇒ Object



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/agent/configuration/am_configuration.rb', line 234

def store_encrypted_data config
  data = config["proxy.auth.password"]
  if (data != nil && @obj.util.decrypt(data, @license_key) == nil) # checking whether data is already encrypted
    begin
      file_contents = ""
        conf_file = File.open(@obj.constants.apm_conf, 'r')
        conf_file.read.each_line do |line|
          if line.start_with?("proxy.auth.password")
            file_contents += "proxy.auth.password=" + @obj.util.encrypt(config["proxy.auth.password"], @license_key)
          else
            file_contents += line
          end
          #file_contents += "\n"
        end #end of do read loop
        conf_file.close
        conf_file = File.open(@obj.constants.apm_conf, "w+")
        conf_file.puts file_contents
        conf_file.close
        file_contents = nil # clearing memory
    rescue Exception=>e
      @obj.log.logException "Error while encrypting file", e
    end
  end # if already encrypted
end

#update_config(configInfo) ⇒ Object



392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
# File 'lib/agent/configuration/am_configuration.rb', line 392

def update_config configInfo
  filepath = @obj.constants.apm_conf
  f = "apminsight.conf.new"
  begin
    propsFile=File.open(filepath, 'r')
    file = File.new(f,"w+")
          propsFile.read.each_line do |line|
            line.strip!
            if (line[0] != ?# and line[0] != ?=)
                i = line.index('=')
               if (i)
        key1 = line[0..i - 1].strip
        if configInfo.has_key?(key1)
          file.puts "#{key1}=#{configInfo[key1]}\n"
        else
          file.puts "#{line}\n"
        end
              else
        file.puts "#{line}\n"
              end
    else
      file.puts "#{line}\n"
            end
           end
  rescue Exception=>e
    @obj.log.info "Problem in Reading / Writing Property File :  #{e.message} "
    @obj.log.error "#{e.backtrace}"
  ensure
      propsFile.close
      file.close
  end
  res = @obj.util.copyFiles f, filepath
  if res
    @obj.log.info "copyFiles result = #{res}"
    #delete apminsight.conf.new has to be done
  end
  configureFile
  assignConfig
end

#updateAgentInfoFile(props) ⇒ Object



146
147
148
149
150
151
152
# File 'lib/agent/configuration/am_configuration.rb', line 146

def updateAgentInfoFile(props)
  @instance_id = props["agent.id"]
  @agent_enabled= @obj.util.getBooleanValue props["agent.enabled"]
  @obj.util.writeProperties(@obj.constants.agent_conf,props)
  
  secureConfFile(@obj.constants.agent_conf)
end

#urlMergePatternObject



134
135
136
137
138
139
140
141
142
143
144
# File 'lib/agent/configuration/am_configuration.rb', line 134

def urlMergePattern
  @url_merge_pattern = Hash.new
  begin
    if (FileTest.exist?(@obj.constants.mergepattern_conf))
      @url_merge_pattern=@obj.util.readProperties(@obj.constants.mergepattern_conf)
    end
  rescue Exception => e
    @obj.log.info "[Exception] Problem in Reading Configuration File : \n File : #{@obj.constants.mergepattern_conf}"
    @obj.log.logException "#{e.message}",e
  end
end