scout_scout 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -7,11 +7,11 @@ Scout your data out of Scout:
7
7
  #all your servers
8
8
  clients = scout.clients
9
9
  #one specific server - pass in hostname
10
- ram_hungry = scout.client('db1.awesome.com')
10
+ ram_hungry = ScoutScout::Client.find('db1.awesome.com')
11
11
  #details on that server's plugins
12
- ram_hungry_plugins = scout.plugins('db1.awesome.com')
13
- #details about the plugin with with name 'Server Overview' on server 'db1.awesome.com'
14
- data = scout.plugin_data('db1.awesome.com','Server Overview')
12
+ ram_hungry_plugins = ram_hungry.plugins
13
+ #details about a specific plugin
14
+ data = ram_hungry.plugin(12345)
15
15
 
16
16
  == Note on Patches/Pull Requests
17
17
 
data/lib/scout_scout.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  require 'hashie'
2
2
  require 'httparty'
3
3
  require 'scout_scout/version'
4
- require 'cgi'
4
+ require 'scout_scout/client'
5
+ require 'scout_scout/descriptor'
6
+ require 'scout_scout/plugin'
7
+ require 'scout_scout/alert'
5
8
 
6
9
  class ScoutScout
7
10
  include HTTParty
@@ -14,51 +17,20 @@ class ScoutScout
14
17
  self.class.basic_auth username, password
15
18
  end
16
19
 
17
- def alerts(client_id_or_hostname = nil)
18
- response = if client_id_or_hostname.nil?
19
- self.class.get("/#{self.class.account}/activities.xml")
20
- elsif client_id_or_hostname.is_a?(Fixnum)
21
- self.class.get("/#{self.class.account}/clients/#{client_id_or_hostname}/activities.xml")
22
- else
23
- self.class.get("/#{self.class.account}/activities.xml?host=#{client_id_or_hostname}")
24
- end
25
- response['alerts'].map { |alert| Hashie::Mash.new(alert) }
20
+ # Recent alerts across all clients on this account
21
+ #
22
+ # @return [Array] An array of ScoutScout::Alert objects
23
+ def alerts
24
+ response = self.class.get("/#{self.class.account}/activities.xml")
25
+ response['alerts'].map { |alert| ScoutScout::Alert.new(alert) }
26
26
  end
27
27
 
28
+ # All clients on this account
29
+ #
30
+ # @return [Array] An array of ScoutScout::Client objects
28
31
  def clients
29
32
  response = self.class.get("/#{self.class.account}/clients.xml")
30
- response['clients'].map { |client| Hashie::Mash.new(client) }
31
- end
32
-
33
- def client(client_id_or_hostname)
34
- if client_id_or_hostname.is_a?(Fixnum)
35
- response = self.class.get("/#{self.class.account}/clients/#{client_id_or_hostname}.xml")
36
- Hashie::Mash.new(response['client'])
37
- else
38
- response = self.class.get("/#{self.class.account}/clients.xml?host=#{client_id_or_hostname}")
39
- Hashie::Mash.new(response['clients'].first)
40
- end
41
- end
42
-
43
- def plugins(client_id_or_hostname)
44
- response = if client_id_or_hostname.is_a?(Fixnum)
45
- self.class.get("/#{self.class.account}/clients/#{client_id_or_hostname}/plugins.xml")
46
- else
47
- self.class.get("/#{self.class.account}/plugins.xml?host=#{client_id_or_hostname}")
48
- end
49
- response['plugins'].map { |plugin| format_plugin(Hashie::Mash.new(plugin)) }
50
- end
51
-
52
- def plugin_data(hostname, plugin_name)
53
- response = self.class.get("/#{self.class.account}/plugins/show.xml?host=#{hostname}&name=#{CGI.escape(plugin_name)}")
54
- format_plugin(Hashie::Mash.new(response['plugin']))
55
- end
56
-
57
- protected
58
-
59
- def format_plugin(plugin)
60
- plugin.descriptors = plugin.descriptors.descriptor
61
- plugin
33
+ response['clients'].map { |client| ScoutScout::Client.new(client) }
62
34
  end
63
35
 
64
36
  end
@@ -0,0 +1,15 @@
1
+ class ScoutScout::Alert < Hashie::Mash
2
+ # The Scout client that generated this alert
3
+ #
4
+ # @return [ScoutScout::Client]
5
+ def client
6
+ @client ||= ScoutScout::Client.find(client_id)
7
+ end
8
+
9
+ # The Scout plugin that generated this alert
10
+ #
11
+ # @return [ScoutScout::Plugin]
12
+ def plugin
13
+ client.plugin(plugin_id)
14
+ end
15
+ end
@@ -0,0 +1,53 @@
1
+ class ScoutScout::Client < Hashie::Mash
2
+ def initialize(hash)
3
+ if hash['active_alerts']
4
+ @alert_hash = hash['active_alerts']
5
+ hash.delete('active_alerts')
6
+ end
7
+ super(hash)
8
+ end
9
+
10
+ # Search for a client by id or hostname
11
+ #
12
+ # @return [ScoutScout::Client]
13
+ def self.find(client_id_or_hostname)
14
+ if client_id_or_hostname.is_a?(Fixnum)
15
+ response = ScoutScout.get("/#{ScoutScout.account}/clients/#{client_id_or_hostname}.xml")
16
+ ScoutScout::Client.new(response['client'])
17
+ else
18
+ response = ScoutScout.get("/#{ScoutScout.account}/clients.xml?host=#{client_id_or_hostname}")
19
+ ScoutScout::Client.new(response['clients'].first)
20
+ end
21
+ end
22
+
23
+ # Active alerts for this client
24
+ #
25
+ # @return [Array] An array of ScoutScout::Alert objects
26
+ def active_alerts
27
+ @active_alerts ||= @alert_hash.map { |a| ScoutScout::Alert.new(a) }
28
+ end
29
+
30
+ # Recent alerts for this client
31
+ #
32
+ # @return [Array] An array of ScoutScout::Alert objects
33
+ def alerts
34
+ response = ScoutScout.get("/#{ScoutScout.account}/clients/#{self.id}/activities.xml")
35
+ response['alerts'].map { |alert| ScoutScout::Alert.new(alert) }
36
+ end
37
+
38
+ # Details about all plugins for this client
39
+ #
40
+ # @return [Array] An array of ScoutScout::Plugin objects
41
+ def plugins
42
+ response = ScoutScout.get("/#{ScoutScout.account}/clients/#{self.id}/plugins.xml")
43
+ response['plugins'].map { |plugin| ScoutScout::Plugin.new(plugin) }
44
+ end
45
+
46
+ # Details about a specific plugin
47
+ #
48
+ # @return [ScoutScout::Plugin]
49
+ def plugin(id)
50
+ response = ScoutScout.get("/#{ScoutScout.account}/clients/#{self.id}/plugins/#{id}.xml")
51
+ ScoutScout::Plugin.new(response['plugin'])
52
+ end
53
+ end
@@ -0,0 +1,2 @@
1
+ class ScoutScout::Descriptor < Hashie::Mash
2
+ end
@@ -0,0 +1,16 @@
1
+ class ScoutScout::Plugin < Hashie::Mash
2
+ def initialize(hash)
3
+ if hash['descriptors'] && hash['descriptors']['descriptor']
4
+ @descriptor_hash = hash['descriptors']['descriptor']
5
+ hash.delete('descriptors')
6
+ end
7
+ super(hash)
8
+ end
9
+
10
+ # All descriptors for this plugin, including their name and current
11
+ #
12
+ # @return [Array] An array of ScoutScout::Descriptor objects
13
+ def descriptors
14
+ @descriptors ||= @descriptor_hash.map { |d| ScoutScout::Descriptor.new(d) }
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  class ScoutScout
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -20,7 +20,11 @@ describe "ScoutScout" do
20
20
  it 'should list all clients' do
21
21
  @clients.size.should == 2
22
22
  end
23
+ it "should be an array ScoutScout::Client objects" do
24
+ @clients.first.class.should == ScoutScout::Client
25
+ end
23
26
  it "should include active alerts" do
27
+ @clients.last.active_alerts.first.class.should == ScoutScout::Alert
24
28
  @clients.last.active_alerts.first.title.should =~ /Passenger/
25
29
  end
26
30
  end
@@ -29,6 +33,15 @@ describe "ScoutScout" do
29
33
  @scout_scout.stub_get('activities.xml')
30
34
  @activities = @scout_scout.alerts
31
35
  end
36
+ it "should be an array ScoutScout::Alert objects" do
37
+ @activities.first.class.should == ScoutScout::Alert
38
+ end
39
+ it "should be associated with it's plugin and client" do
40
+ @scout_scout.stub_get('clients/24331.xml', 'client.xml')
41
+ @activities.first.client.class.should == ScoutScout::Client
42
+ @scout_scout.stub_get('clients/13431/plugins/122761.xml', 'plugin_data.xml')
43
+ @activities.first.plugin.class.should == ScoutScout::Plugin
44
+ end
32
45
  it "should be accessable" do
33
46
  @activities.size.should == 2
34
47
  @activities.each do |activity|
@@ -42,26 +55,30 @@ describe "ScoutScout" do
42
55
  describe '' do
43
56
  before(:each) do
44
57
  @scout_scout.stub_get('clients/1234.xml', 'client.xml')
45
- @client = @scout_scout.client(1234)
58
+ @client = ScoutScout::Client.find(1234)
46
59
  end
47
60
  it "by id" do
48
61
  @client.key.should == 'FOOBAR'
62
+ @client.class.should == ScoutScout::Client
49
63
  end
50
64
  end
51
65
  describe '' do
52
66
  before(:each) do
53
67
  @scout_scout.stub_get('clients.xml?host=foo.awesome.com', 'client_by_hostname.xml')
54
- @client = @scout_scout.client('foo.awesome.com')
68
+ @client = ScoutScout::Client.find('foo.awesome.com')
55
69
  end
56
70
  it "by hostname" do
57
71
  @client.key.should == 'FOOBAR'
72
+ @client.class.should == ScoutScout::Client
58
73
  end
59
74
  end
60
75
  end
61
76
  describe 'alert log' do
62
77
  before(:each) do
63
- @scout_scout.stub_get('clients/1234/activities.xml', 'activities.xml')
64
- @activities = @scout_scout.alerts(1234)
78
+ @scout_scout.stub_get('clients/13431.xml', 'client.xml')
79
+ @client = ScoutScout::Client.find(13431)
80
+ @scout_scout.stub_get('clients/13431/activities.xml', 'activities.xml')
81
+ @activities = @client.alerts
65
82
  end
66
83
  it "should be accessable" do
67
84
  @activities.size.should == 2
@@ -69,12 +86,17 @@ describe "ScoutScout" do
69
86
  activity.title.should =~ /Passenger/
70
87
  end
71
88
  end
89
+ it "should be an array ScoutScout::Alert objects" do
90
+ @activities.first.class.should == ScoutScout::Alert
91
+ end
72
92
  end
73
93
  describe 'plugin' do
74
94
  describe 'list' do
75
95
  before(:each) do
76
- @scout_scout.stub_get('clients/1234/plugins.xml', 'plugins.xml')
77
- @plugins = @scout_scout.plugins(1234)
96
+ @scout_scout.stub_get('clients/13431.xml', 'client.xml')
97
+ @client = ScoutScout::Client.find(13431)
98
+ @scout_scout.stub_get('clients/13431/plugins.xml', 'plugins.xml')
99
+ @plugins = @client.plugins
78
100
  end
79
101
  it "should be accessable" do
80
102
  @plugins.size.should == 2
@@ -83,20 +105,29 @@ describe "ScoutScout" do
83
105
  plugin.descriptors.length.should == 11
84
106
  end
85
107
  end
108
+ it "should be an array ScoutScout::Plugin objects" do
109
+ @plugins.first.class.should == ScoutScout::Plugin
110
+ end
86
111
  end
87
112
  describe 'individually' do
88
113
  before(:each) do
89
- @scout_scout.stub_get('plugins/show.xml?host=foo.awesome.com&name=passenger', 'plugin_data.xml')
90
- @plugin_data = @scout_scout.plugin_data('foo.awesome.com','passenger')
114
+ @scout_scout.stub_get('clients/13431.xml', 'client.xml')
115
+ @client = ScoutScout::Client.find(13431)
116
+ @scout_scout.stub_get('clients/13431/plugins/12345.xml', 'plugin_data.xml')
117
+ @plugin_data = @client.plugin(12345)
91
118
  end
92
119
  it "should be accessable" do
120
+ @plugin_data.class.should == ScoutScout::Plugin
93
121
  @plugin_data.name.should == 'Passenger'
94
122
  @plugin_data.descriptors.length.should == 11
95
123
  end
96
124
  it "should include descriptors" do
125
+ @plugin_data.descriptors.first.class.should == ScoutScout::Descriptor
97
126
  @plugin_data.descriptors.first.value.should == '31'
98
127
  @plugin_data.descriptors.first.name.should == 'passenger_process_active'
99
128
  end
129
+ it "should be an ScoutScout::Plugin objects" do
130
+ end
100
131
  end
101
132
 
102
133
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scout_scout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Newland
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-30 00:00:00 -05:00
12
+ date: 2010-01-31 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -68,6 +68,10 @@ files:
68
68
  - README.rdoc
69
69
  - Rakefile
70
70
  - lib/scout_scout.rb
71
+ - lib/scout_scout/alert.rb
72
+ - lib/scout_scout/client.rb
73
+ - lib/scout_scout/descriptor.rb
74
+ - lib/scout_scout/plugin.rb
71
75
  - lib/scout_scout/version.rb
72
76
  - spec/fixtures/activities.xml
73
77
  - spec/fixtures/client.xml