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.



13
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
# File 'lib/agent/configuration/am_configuration.rb', line 13

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
@db_operations =["select","insert","update","delete"]
@obj.log.debug "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
@obj.log.debug "APP HOME #{File.absolute_path(".")} "
@obj.log.debug "APP HOME #{Dir.pwd} "
@obj.log.debug "Configuration : "
@obj.log.debug "Agent Name : #{@agenthost}"
@obj.log.debug "Agent Already Connected : #{@alreadyconnected}"
@obj.log.debug "Agent Enabled : #{@agent_enabled}"
@obj.log.debug "Allowed DB Operations : #{@db_operations}"
@config.each do|key,val|
@obj.log.info "#{key} => #{val}"
  end
@obj.log.debug "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
@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.



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

def agent_enabled
  @agent_enabled
end

#agenthostObject (readonly)

Returns the value of attribute agenthost.



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

def agenthost
  @agenthost
end

#agentportObject (readonly)

Returns the value of attribute agentport.



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

def agentport
  @agentport
end

#alreadyconnectedObject (readonly)

Returns the value of attribute alreadyconnected.



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

def alreadyconnected
  @alreadyconnected
end

#apdex_tObject (readonly)

Returns the value of attribute apdex_t.



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

def apdex_t
  @apdex_t
end

#apmhostObject (readonly)

Returns the value of attribute apmhost.



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

def apmhost
  @apmhost
end

#apmportObject (readonly)

Returns the value of attribute apmport.



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

def apmport
  @apmport
end

#app_dbObject

Returns the value of attribute app_db.



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

def app_db
  @app_db
end

#app_dispatcherObject

Returns the value of attribute app_dispatcher.



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

def app_dispatcher
  @app_dispatcher
end

#appnameObject (readonly)

Returns the value of attribute appname.



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

def appname
  @appname
end

#connect_intervalObject (readonly)

Returns the value of attribute connect_interval.



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

def connect_interval
  @connect_interval
end

#connection_retryObject (readonly)

Returns the value of attribute connection_retry.



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

def connection_retry
  @connection_retry
end

#db_operationsObject (readonly)

Returns the value of attribute db_operations.



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

def db_operations
  @db_operations
end

#include_packagesObject (readonly)

Returns the value of attribute include_packages.



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

def include_packages
  @include_packages
end

#instance_idObject (readonly)

Returns the value of attribute instance_id.



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

def instance_id
  @instance_id
end

#is_securedObject (readonly)

Returns the value of attribute is_secured.



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

def is_secured
  @is_secured
end

#lastupdatedtimeObject

Returns the value of attribute lastupdatedtime.



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

def lastupdatedtime
  @lastupdatedtime
end

#license_keyObject (readonly)

Returns the value of attribute license_key.



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

def license_key
  @license_key
end

#logs_dirObject (readonly)

Returns the value of attribute logs_dir.



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

def logs_dir
  @logs_dir
end

#metric_overflow_tObject (readonly)

Returns the value of attribute metric_overflow_t.



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

def metric_overflow_t
  @metric_overflow_t
end

#proxy_hostObject (readonly)

Returns the value of attribute proxy_host.



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

def proxy_host
  @proxy_host
end

#proxy_passObject (readonly)

Returns the value of attribute proxy_pass.



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

def proxy_pass
  @proxy_pass
end

#proxy_portObject (readonly)

Returns the value of attribute proxy_port.



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

def proxy_port
  @proxy_port
end

#proxy_userObject (readonly)

Returns the value of attribute proxy_user.



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

def proxy_user
  @proxy_user
end

#proxyneededObject (readonly)

Returns the value of attribute proxyneeded.



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

def proxyneeded
  @proxyneeded
end

#site24x7Object (readonly)

Returns the value of attribute site24x7.



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

def site24x7
  @site24x7
end

#sql_captureObject (readonly)

Returns the value of attribute sql_capture.



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

def sql_capture
  @sql_capture
end

#sql_capture_paramsObject (readonly)

Returns the value of attribute sql_capture_params.



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

def sql_capture_params
  @sql_capture_params
end

#sql_trace_tObject (readonly)

Returns the value of attribute sql_trace_t.



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

def sql_trace_t
  @sql_trace_t
end

#trace_overflow_tObject (readonly)

Returns the value of attribute trace_overflow_t.



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

def trace_overflow_t
  @trace_overflow_t
end

#trans_traceObject (readonly)

Returns the value of attribute trans_trace.



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

def trans_trace
  @trans_trace
end

#trans_trace_tObject (readonly)

Returns the value of attribute trans_trace_t.



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

def trans_trace_t
  @trans_trace_t
end

Instance Method Details

#assignConfigObject



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/agent/configuration/am_configuration.rb', line 125

def assignConfig
initValues
 @config.each do |key,value|
   case key
   when "application.name" then @appname=value
   when "apm.host" then @apmhost=value
   when "apm.port" then @apmport=isInteger(@apmport,value)
   when "license.key" then @license_key=value
   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=value
   when "proxy.auth.username" then @proxy_user=value
   when "proxy.auth.password" then @proxy_pass=value
   when "apminsight.secure" then @is_secured=@obj.util.getBooleanValue value
   when "apminsight.log.dir" then @logs_dir=value
   when "agent.connection.retry" then @connection_retry=value #Not in Conf - yet to come
  when "agent.connection.interval" then   @connect_interval=value#Not in Conf - yet to come
  when "include.packages" then @include_packages=@obj.util.getArray value,","
  end
 end
end

#checkAgentInfoObject



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/agent/configuration/am_configuration.rb', line 74

def checkAgentInfo
  if FileTest.exists?(@obj.constants.agent_conf)
    @obj.log.debug "Status : Agent Already Connected"
    props = @obj.util.readProperties(@obj.constants.agent_conf)
    @instance_id = props["agent.id"]
    @agent_enabled= @obj.util.getBooleanValue props["agent.enabled"]
    true
  else
    @obj.log.info "Status : Agent not connected"
    false
  end
end

#checkLicenseFileObject



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/agent/configuration/am_configuration.rb', line 87

def checkLicenseFile
  if(@license_key != nil)
    @obj.log.info "License key is not null. Connecting to site24x7"
    @obj.constants.setLicenseKey @license_key
    true
  else
    @obj.log.info "License key is null. Connecting to APPManager"
    false
  end

end

#configureFileObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/agent/configuration/am_configuration.rb', line 43

def configureFile
  begin
    if(FileTest.exists?(@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)
    else
      gem_conf = Gem.loaded_specs[@obj.constants.apm_gem].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.debug "Config File copied. It is read from #{@obj.constants.apm_conf}"
        @config = @obj.util.readProperties(@obj.constants.apm_conf)
      else
        #Problem in copying, so reading props from Conf file in Gem Location
        @obj.log.debug "Config File not copied. It is read from #{gem_conf}"
        @config = @obj.util.readProperties(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



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/agent/configuration/am_configuration.rb', line 176

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



154
155
156
157
158
159
160
161
162
# File 'lib/agent/configuration/am_configuration.rb', line 154

def getAgentInfo
  data =  Hash.new
  agentdata = Hash.new
  agentdata = {"application.type"=>"RUBY","application.name"=>@appname,"hostname"=>@agenthost,"port"=>@agentport,"agent.version"=>"1.0"}
  data["agent_info"]=agentdata
  data["environment"]=getEnvData
  data["custom_config_info"]=getAgentConfigData
  data
end

#getDispatcherObject



198
199
200
201
202
203
204
# File 'lib/agent/configuration/am_configuration.rb', line 198

def getDispatcher
dispatcher = "unknown"
if defined?(PhusionPassenger) then
  dispatcher = "passenger"
end
dispatcher
end

#getEnvDataObject



164
165
166
167
168
169
170
171
172
173
174
# File 'lib/agent/configuration/am_configuration.rb', line 164

def getEnvData
  env =  Hash.new
  begin
  ENV.to_hash.each do |key, value|
    env[key] = value
  end
  env["Application Path"]="#{Rails.root}"
  rescue Exception=>e
  end
  env
end

#initValuesObject



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

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
  @include_packages=Array.new
  @trans_trace_t=2
  @sql_trace_t=3
  @metric_overflow_t=250
  @trace_overflow_t=60
end

#isFloat(default, value) ⇒ Object



216
217
218
219
220
221
222
223
# File 'lib/agent/configuration/am_configuration.rb', line 216

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



206
207
208
209
210
211
212
213
214
# File 'lib/agent/configuration/am_configuration.rb', line 206

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

#update_config(configInfo) ⇒ Object



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/agent/configuration/am_configuration.rb', line 225

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



99
100
101
102
103
# File 'lib/agent/configuration/am_configuration.rb', line 99

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