Class: ScoutScout

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/scout_scout.rb,
lib/scout_scout/version.rb

Defined Under Namespace

Classes: Alert, Cluster, Descriptor, Error, Metric, Person, Plugin, Server, Trigger

Constant Summary collapse

VERSION =
'0.0.6'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scout_account_name, username, password) ⇒ ScoutScout

Returns a new instance of ScoutScout.



25
26
27
28
# File 'lib/scout_scout.rb', line 25

def initialize(, username, password)
  self.class. = 
  self.class.basic_auth username, password
end

Class Method Details

.get(uri) ⇒ Object

Checks for errors via the HTTP status code. If an error is found, a ScoutScout::Error is raised. Otherwise, the response.

Returns:

  • HTTParty::Response



79
80
81
82
# File 'lib/scout_scout.rb', line 79

def self.get(uri)
  response = http_get(uri)
  response.code.to_s =~ /^(4|5)/ ? raise( ScoutScout::Error,response.message) : response
end

.http_getObject



72
# File 'lib/scout_scout.rb', line 72

alias_method :http_get, :get

Instance Method Details

#alertsArray

Recent alerts across all servers on this account

Returns:

  • (Array)

    An array of ScoutScout::Alert objects



33
34
35
36
# File 'lib/scout_scout.rb', line 33

def alerts
  response = self.class.get("/#{self.class.}/activities.xml")
  response['alerts'].map { |alert| ScoutScout::Alert.new(alert) }
end

#peopleObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/scout_scout.rb', line 46

def people
  response = self.class.get("/#{self.class.}/account_memberships")
  doc = Nokogiri::HTML(response.body)

  tables = doc.css('table.list')
  # first table is pending
  # second is active
  active_table = tables.last
  user_rows = active_table.css('tr')[1..-1] # skip first row, which is headings

  user_rows.map do |row|
    name_td, email_td, admin_td, links_td = *row.css('td')

    name = name_td.content.gsub(/[\t\n]/, '')
    email = email_td.content.gsub(/[\t\n]/, '')
    admin = admin_td.content.gsub(/[\t\n]/, '') == 'Yes'
    id = if links_td.inner_html =~ %r{/#{self.class.}/account_memberships/(\d+)}
           $1.to_i
         end

    ScoutScout::Person.new :id => id, :name => name, :email => email, :admin => admin
  end

end

#serversArray

All servers on this account

Returns:

  • (Array)

    An array of ScoutScout::Server objects



41
42
43
44
# File 'lib/scout_scout.rb', line 41

def servers
  response = self.class.get("/#{self.class.}/clients.xml")
  response['clients'].map { |client| ScoutScout::Server.new(client) }
end