Class: Appdynamics::Controller

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/appdynamics/controller.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host_name, account_name, user_name, password) ⇒ Controller

Returns a new instance of Controller.



8
9
10
11
12
13
14
15
# File 'lib/appdynamics/controller.rb', line 8

def initialize host_name, , user_name, password
    @host_name = host_name
    @account_name = 
    @user_name = user_name
    @password = password
    @base_uri = "http://#{host_name}/controller/rest"
    @auth = {username: "#{user_name}@#{}", password: password}
end

Instance Attribute Details

#account_nameObject (readonly)

Returns the value of attribute account_name.



5
6
7
# File 'lib/appdynamics/controller.rb', line 5

def 
  @account_name
end

#application_idObject (readonly)

Returns the value of attribute application_id.



5
6
7
# File 'lib/appdynamics/controller.rb', line 5

def application_id
  @application_id
end

#application_nameObject (readonly)

Returns the value of attribute application_name.



5
6
7
# File 'lib/appdynamics/controller.rb', line 5

def application_name
  @application_name
end

#applicationsObject

Returns the value of attribute applications.



5
6
7
# File 'lib/appdynamics/controller.rb', line 5

def applications
  @applications
end

#base_uriObject (readonly)

Returns the value of attribute base_uri.



5
6
7
# File 'lib/appdynamics/controller.rb', line 5

def base_uri
  @base_uri
end

#host_nameObject (readonly)

Returns the value of attribute host_name.



5
6
7
# File 'lib/appdynamics/controller.rb', line 5

def host_name
  @host_name
end

#nodesObject (readonly)

Returns the value of attribute nodes.



5
6
7
# File 'lib/appdynamics/controller.rb', line 5

def nodes
  @nodes
end

#passwordObject (readonly)

Returns the value of attribute password.



5
6
7
# File 'lib/appdynamics/controller.rb', line 5

def password
  @password
end

#tiersObject (readonly)

Returns the value of attribute tiers.



5
6
7
# File 'lib/appdynamics/controller.rb', line 5

def tiers
  @tiers
end

#user_nameObject (readonly)

Returns the value of attribute user_name.



5
6
7
# File 'lib/appdynamics/controller.rb', line 5

def user_name
  @user_name
end

Class Method Details

.deserialize(datum) ⇒ Object



21
22
23
# File 'lib/appdynamics/controller.rb', line 21

def self.deserialize datum
    YAML.load datum
end

.from_hash(hsh) ⇒ Object



36
37
38
39
40
# File 'lib/appdynamics/controller.rb', line 36

def self.from_hash hsh
    controller = Controller.new hsh['host_name'], hsh['account_name'], hsh['user_name'], hsh['password']
    controller.applications = hsh['applications']
    controller
end

Instance Method Details

#get(path, additional_options = {}) ⇒ Object



68
69
70
71
72
# File 'lib/appdynamics/controller.rb', line 68

def get path, additional_options = {}
    result = self.class.get(URI.escape(path), options(additional_options))
    raise Exception.new "HTTP Error: #{result.response.code}" unless result.response.code == "200"
    result
end

#metric_data_for(metric, start_time, end_time, rollup = false) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/appdynamics/controller.rb', line 99

def metric_data_for metric, start_time, end_time, rollup = false
    path = "#{base_uri}/#{metric.relative_route(true)}"
    start_time = Time.parse start_time unless start_time.class == Time
    end_time = Time.parse end_time unless end_time.class == Time
    path = "#{base_uri}/#{metric.relative_route(true)}"
    additional_options = {
        'time-range-type' => "BETWEEN_TIMES",
        'start-time' => start_time.to_i * 1000,
        'end-time' => end_time.to_i * 1000,
        'rollup' => rollup
    }
    result = get path, options({query: additional_options})
    result
end

#metrics_for(obj) ⇒ Object



90
91
92
93
94
95
96
97
# File 'lib/appdynamics/controller.rb', line 90

def metrics_for obj
    path = "#{base_uri}/#{obj.relative_route}"
    path += "/metrics" if obj.class == Application
    result = get path
    result.map{|res|
        Metric.new self, obj, res
    }
end

#nodes_for(application) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/appdynamics/controller.rb', line 74

def nodes_for application
    path = "#{base_uri}/#{application.relative_route}/nodes"
    result = get path
    result.map{|res|
        Node.new self, application, res
    }
end

#reset_cache!Object



64
65
66
# File 'lib/appdynamics/controller.rb', line 64

def reset_cache!
    @nodes = @tiers = @applications = nil
end

#serializeObject



17
18
19
# File 'lib/appdynamics/controller.rb', line 17

def serialize
    YAML.dump self
end

#tiers_for(application) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/appdynamics/controller.rb', line 82

def tiers_for application
    path = "#{base_uri}/#{application.relative_route}/tiers"
    result = get path
    result.map{|res|
        Tier.new self, application, res
    }
end

#to_hashObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/appdynamics/controller.rb', line 25

def to_hash
    hsh = {
        host_name: @host_name,
        account_name: @account_name,
        user_name: @user_name,
        password: @password
    }
    hsh.merge!({applications: @applications.map{|app| app.to_hash}}) if @applications
    hsh
end