Class: ScoutScout
- Inherits:
-
Object
- Object
- ScoutScout
- 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
-
.get(uri) ⇒ Object
Checks for errors via the HTTP status code.
- .http_get ⇒ Object
Instance Method Summary collapse
-
#alerts ⇒ Array
Recent alerts across all servers on this account.
-
#initialize(scout_account_name, username, password) ⇒ ScoutScout
constructor
A new instance of ScoutScout.
- #people ⇒ Object
-
#servers ⇒ Array
All servers on this account.
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(scout_account_name, username, password) self.class.account = scout_account_name 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.
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.) : response end |
.http_get ⇒ Object
72 |
# File 'lib/scout_scout.rb', line 72 alias_method :http_get, :get |
Instance Method Details
#alerts ⇒ Array
Recent alerts across all servers on this account
33 34 35 36 |
# File 'lib/scout_scout.rb', line 33 def alerts response = self.class.get("/#{self.class.account}/activities.xml") response['alerts'].map { |alert| ScoutScout::Alert.new(alert) } end |
#people ⇒ Object
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}/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}/account_memberships/(\d+)} $1.to_i end ScoutScout::Person.new :id => id, :name => name, :email => email, :admin => admin end end |
#servers ⇒ Array
All servers on this account
41 42 43 44 |
# File 'lib/scout_scout.rb', line 41 def servers response = self.class.get("/#{self.class.account}/clients.xml") response['clients'].map { |client| ScoutScout::Server.new(client) } end |