scout_scout 0.0.1 → 0.0.2

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/.gitignore CHANGED
@@ -17,5 +17,6 @@ tmtags
17
17
  coverage
18
18
  rdoc
19
19
  pkg
20
+ *.gemspec
20
21
 
21
22
  ## PROJECT::SPECIFIC
@@ -1,17 +1,17 @@
1
1
  = scout_scout
2
2
 
3
- Get your data out of Scout:
3
+ Scout your data out of Scout:
4
4
 
5
5
  require 'scout_scout'
6
6
  scout = ScoutScout.new('youraccountname', 'your@awesome.com', 'sekret')
7
7
  #all your servers
8
8
  clients = scout.clients
9
- #one specific server
10
- ram_hungry = scout.client(1234)
9
+ #one specific server - pass in hostname
10
+ ram_hungry = scout.client('db1.awesome.com')
11
11
  #details on that server's plugins
12
- ram_hungry_plugins = scout.plugins(1234)
13
- #details about the plugin with id 5678 in account 1234
14
- data = scout.plugin_data(1234,5678)
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')
15
15
 
16
16
  == Note on Patches/Pull Requests
17
17
 
data/Rakefile CHANGED
@@ -1,9 +1,12 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
+ $LOAD_PATH.unshift 'lib'
4
+ require 'scout_scout/version'
3
5
 
4
6
  begin
5
7
  require 'jeweler'
6
8
  Jeweler::Tasks.new do |gem|
9
+ gem.version = ScoutScout::VERSION
7
10
  gem.name = "scout_scout"
8
11
  gem.summary = %Q{API wrapper for scout.com}
9
12
  gem.description = %Q{API wrapper for scout.com}
@@ -38,8 +41,6 @@ task :spec => :check_dependencies
38
41
  task :default => :spec
39
42
 
40
43
  require 'rake/rdoctask'
41
- $LOAD_PATH.unshift 'lib'
42
- require 'scout_scout/version'
43
44
  Rake::RDocTask.new do |rdoc|
44
45
  version = ScoutScout::VERSION
45
46
 
@@ -1,6 +1,7 @@
1
1
  require 'hashie'
2
2
  require 'httparty'
3
3
  require 'scout_scout/version'
4
+ require 'cgi'
4
5
 
5
6
  class ScoutScout
6
7
  include HTTParty
@@ -8,19 +9,20 @@ class ScoutScout
8
9
  format :xml
9
10
  mattr_inheritable :account
10
11
 
11
- def initialize(acct, user, pass)
12
- self.class.account = acct
13
- self.class.basic_auth user, pass
12
+ def initialize(scout_account_name, username, password)
13
+ self.class.account = scout_account_name
14
+ self.class.basic_auth username, password
14
15
  end
15
16
 
16
- def alerts(id = nil)
17
- if id.nil?
18
- response = self.class.get("/#{self.class.account}/activities.xml")
19
- response['alerts'].map { |alert| Hashie::Mash.new(alert) }
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")
20
22
  else
21
- response = self.class.get("/#{self.class.account}/clients/#{id}/activities.xml")
22
- response['alerts'].map { |alert| Hashie::Mash.new(alert) }
23
+ self.class.get("/#{self.class.account}/activities.xml?host=#{client_id_or_hostname}")
23
24
  end
25
+ response['alerts'].map { |alert| Hashie::Mash.new(alert) }
24
26
  end
25
27
 
26
28
  def clients
@@ -28,33 +30,35 @@ class ScoutScout
28
30
  response['clients'].map { |client| Hashie::Mash.new(client) }
29
31
  end
30
32
 
31
- def client(id)
32
- response = self.class.get("/#{self.class.account}/clients/#{id}.xml")
33
- Hashie::Mash.new(response['client'])
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
34
41
  end
35
42
 
36
- def plugins(id)
37
- response = self.class.get("/#{self.class.account}/clients/#{id}/plugins.xml")
38
- response['plugins'].map { |plugin| Hashie::Mash.new(plugin) }
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)) }
39
50
  end
40
51
 
41
- def plugin_data(client, id)
42
- require 'nokogiri'
43
- html = self.class.get("/#{self.class.account}/clients/#{client}/plugins/#{id}", :format => :html)
44
- plugin_doc = Nokogiri::HTML(html)
45
- table = plugin_doc.css('table.list.spaced').first
46
- data = []
47
- table.css('tr').each do |row|
48
- if (columns = row.css('td')).length == 2
49
- link = columns.first.css('a').first
50
- descriptor = {}
51
- descriptor[:name] = link.content
52
- descriptor[:data] = columns[1].content.strip
53
- descriptor[:id] = link.attribute('href').to_s.gsub(/.*=/,'').to_i
54
- descriptor[:graph] = "#{self.class.base_uri}/#{self.class.account}/descriptors/#{descriptor[:id]}/graph"
55
- data << Hashie::Mash.new(descriptor)
56
- end
57
- end
58
- data
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']))
59
55
  end
56
+
57
+ protected
58
+
59
+ def format_plugin(plugin)
60
+ plugin.descriptors = plugin.descriptors.descriptor
61
+ plugin
62
+ end
63
+
60
64
  end
@@ -1,3 +1,3 @@
1
1
  class ScoutScout
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -0,0 +1,33 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <alerts type="array">
3
+ <alert>
4
+ <body nil="true"></body>
5
+ <client-id type="integer">24331</client-id>
6
+ <email-viewed-at type="datetime" nil="true"></email-viewed-at>
7
+ <id type="integer">35793021</id>
8
+ <last-repeated-at type="datetime">2010-01-21T20:30:00-05:00</last-repeated-at>
9
+ <needs-sms type="integer">0</needs-sms>
10
+ <num-repeats type="integer">1</num-repeats>
11
+ <plugin-id type="integer">122761</plugin-id>
12
+ <sms-sent-at type="datetime" nil="true"></sms-sent-at>
13
+ <stopped-repeating-at type="datetime" nil="true"></stopped-repeating-at>
14
+ <time type="datetime">2010-01-21T20:30:00-05:00</time>
15
+ <trigger-id type="integer">101821</trigger-id>
16
+ <title> Passenger Global Queue Depth met or exceeded 1 , increasing to 2 for 30 minutes at 08:30PM </title>
17
+ </alert>
18
+ <alert>
19
+ <body nil="true"></body>
20
+ <client-id type="integer">22301</client-id>
21
+ <email-viewed-at type="datetime" nil="true"></email-viewed-at>
22
+ <id type="integer">35793011</id>
23
+ <last-repeated-at type="datetime">2010-01-21T20:30:00-05:00</last-repeated-at>
24
+ <needs-sms type="integer">0</needs-sms>
25
+ <num-repeats type="integer">1</num-repeats>
26
+ <plugin-id type="integer">122731</plugin-id>
27
+ <sms-sent-at type="datetime" nil="true"></sms-sent-at>
28
+ <stopped-repeating-at type="datetime" nil="true"></stopped-repeating-at>
29
+ <time type="datetime">2010-01-21T20:30:00-05:00</time>
30
+ <trigger-id type="integer">101731</trigger-id>
31
+ <title> Passenger Global Queue Depth met or exceeded 1 , increasing to 1 for 30 minutes at 08:30PM </title>
32
+ </alert>
33
+ </alerts>
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <client>
3
+ <checkin-interval type="integer">3</checkin-interval>
4
+ <checkup-status>OK</checkup-status>
5
+ <external-id nil="true"></external-id>
6
+ <id type="integer">13431</id>
7
+ <key>FOOBAR</key>
8
+ <last-checkin type="datetime">2010-01-21T20:35:01-05:00</last-checkin>
9
+ <last-ping type="datetime">2010-01-21T20:35:00-05:00</last-ping>
10
+ <name>foobar</name>
11
+ <num-checkins type="integer">20785</num-checkins>
12
+ <partner-id type="integer" nil="true"></partner-id>
13
+ <plan-updated-at type="datetime">2010-01-19T08:59:32-05:00</plan-updated-at>
14
+ <second-to-last-checkin type="datetime">2010-01-21T20:32:01-05:00</second-to-last-checkin>
15
+ <second-to-last-ping type="datetime">2010-01-21T20:32:00-05:00</second-to-last-ping>
16
+ <send-checkup-email type="boolean" nil="true"></send-checkup-email>
17
+ <send-checkup-sms type="boolean" nil="true"></send-checkup-sms>
18
+ <take-snapshots type="boolean">false</take-snapshots>
19
+ <version>3.2.6</version>
20
+ <active-alerts type="array"/>
21
+ </client>
@@ -0,0 +1,23 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <clients type="array">
3
+ <client>
4
+ <checkin-interval type="integer">3</checkin-interval>
5
+ <checkup-status>OK</checkup-status>
6
+ <external-id nil="true"></external-id>
7
+ <id type="integer">13431</id>
8
+ <key>FOOBAR</key>
9
+ <last-checkin type="datetime">2010-01-21T20:35:01-05:00</last-checkin>
10
+ <last-ping type="datetime">2010-01-21T20:35:00-05:00</last-ping>
11
+ <name>foobar</name>
12
+ <num-checkins type="integer">20785</num-checkins>
13
+ <partner-id type="integer" nil="true"></partner-id>
14
+ <plan-updated-at type="datetime">2010-01-19T08:59:32-05:00</plan-updated-at>
15
+ <second-to-last-checkin type="datetime">2010-01-21T20:32:01-05:00</second-to-last-checkin>
16
+ <second-to-last-ping type="datetime">2010-01-21T20:32:00-05:00</second-to-last-ping>
17
+ <send-checkup-email type="boolean" nil="true"></send-checkup-email>
18
+ <send-checkup-sms type="boolean" nil="true"></send-checkup-sms>
19
+ <take-snapshots type="boolean">false</take-snapshots>
20
+ <version>3.2.6</version>
21
+ <active-alerts type="array"/>
22
+ </client>
23
+ </clients>
@@ -0,0 +1,57 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <clients type="array">
3
+ <client>
4
+ <checkin-interval type="integer">3</checkin-interval>
5
+ <checkup-status>OK</checkup-status>
6
+ <external-id nil="true"></external-id>
7
+ <id type="integer">13431</id>
8
+ <key>FOOBAR</key>
9
+ <last-checkin type="datetime">2010-01-21T20:35:01-05:00</last-checkin>
10
+ <last-ping type="datetime">2010-01-21T20:35:00-05:00</last-ping>
11
+ <name>foobar</name>
12
+ <num-checkins type="integer">20785</num-checkins>
13
+ <partner-id type="integer" nil="true"></partner-id>
14
+ <plan-updated-at type="datetime">2010-01-19T08:59:32-05:00</plan-updated-at>
15
+ <second-to-last-checkin type="datetime">2010-01-21T20:32:01-05:00</second-to-last-checkin>
16
+ <second-to-last-ping type="datetime">2010-01-21T20:32:00-05:00</second-to-last-ping>
17
+ <send-checkup-email type="boolean" nil="true"></send-checkup-email>
18
+ <send-checkup-sms type="boolean" nil="true"></send-checkup-sms>
19
+ <take-snapshots type="boolean">false</take-snapshots>
20
+ <version>3.2.6</version>
21
+ <active-alerts type="array"/>
22
+ </client>
23
+ <client>
24
+ <checkin-interval type="integer">3</checkin-interval>
25
+ <checkup-status>Failure</checkup-status>
26
+ <external-id nil="true"></external-id>
27
+ <id type="integer">22751</id>
28
+ <key>FOO2</key>
29
+ <last-checkin type="datetime">2010-01-15T07:33:59-05:00</last-checkin>
30
+ <last-ping type="datetime">2010-01-15T07:33:52-05:00</last-ping>
31
+ <name>foo2</name>
32
+ <num-checkins type="integer">4801</num-checkins>
33
+ <partner-id type="integer" nil="true"></partner-id>
34
+ <plan-updated-at type="datetime">2010-01-19T08:59:32-05:00</plan-updated-at>
35
+ <second-to-last-checkin type="datetime">2010-01-05T05:33:14-05:00</second-to-last-checkin>
36
+ <second-to-last-ping type="datetime">2010-01-05T05:33:03-05:00</second-to-last-ping>
37
+ <send-checkup-email type="boolean" nil="true"></send-checkup-email>
38
+ <send-checkup-sms type="boolean" nil="true"></send-checkup-sms>
39
+ <take-snapshots type="boolean">false</take-snapshots>
40
+ <version>5.0.3</version>
41
+ <active-alerts type="array">
42
+ <alert>
43
+ <body nil="true"></body>
44
+ <email-viewed-at type="datetime" nil="true"></email-viewed-at>
45
+ <id type="integer">34555661</id>
46
+ <last-repeated-at type="datetime">2010-01-05T06:00:00-05:00</last-repeated-at>
47
+ <needs-sms type="integer">0</needs-sms>
48
+ <num-repeats type="integer">2</num-repeats>
49
+ <plugin-id type="integer">112001</plugin-id>
50
+ <sms-sent-at type="datetime" nil="true"></sms-sent-at>
51
+ <time type="datetime">2010-01-05T05:00:00-05:00</time>
52
+ <trigger-id type="integer">88111</trigger-id>
53
+ <title> Passenger private total increased 1,133 MB (200%) from 566 MB to 1,699 MB from 04:00AM-05:00AM relative to 03:00AM-04:00AM and is still continuing as of 06:00AM (16 days so far) </title>
54
+ </alert>
55
+ </active-alerts>
56
+ </client>
57
+ </clients>
@@ -0,0 +1,62 @@
1
+ <plugin>
2
+ <code-updated-at type="datetime">2010-01-14T18:39:52-05:00</code-updated-at>
3
+ <created-at type="datetime">2010-01-14T18:39:53-05:00</created-at>
4
+ <enabled type="boolean">true</enabled>
5
+ <failed-at type="datetime" nil="true"></failed-at>
6
+ <failing type="boolean">false</failing>
7
+ <first-reported-at type="datetime">2010-01-14T18:40:17-05:00</first-reported-at>
8
+ <id type="integer">122681</id>
9
+ <interval type="integer">0</interval>
10
+ <last-reported-at type="datetime">2010-01-30T19:01:00-05:00</last-reported-at>
11
+ <name>Passenger</name>
12
+ <plugin-url-id type="integer" nil="true"></plugin-url-id>
13
+ <status nil="true"></status>
14
+ <updated-at type="datetime">2010-01-30T19:01:04-05:00</updated-at>
15
+ <url>http://github.com/eric/sevenscale-scout-plugins/raw/master/passenger_united.rb</url>
16
+ <descriptors>
17
+ <descriptor>
18
+ <name>passenger_process_active</name>
19
+ <value>31</value>
20
+ </descriptor>
21
+ <descriptor>
22
+ <name>passenger_process_current</name>
23
+ <value>35</value>
24
+ </descriptor>
25
+ <descriptor>
26
+ <name>apache_vmsize_total</name>
27
+ <value>1613.7</value>
28
+ </descriptor>
29
+ <descriptor>
30
+ <name>passenger_queue_depth</name>
31
+ <value>0</value>
32
+ </descriptor>
33
+ <descriptor>
34
+ <name>passenger_max_pool_size</name>
35
+ <value>35</value>
36
+ </descriptor>
37
+ <descriptor>
38
+ <name>passenger_vmsize_total</name>
39
+ <value>6835.4</value>
40
+ </descriptor>
41
+ <descriptor>
42
+ <name>passenger_process_inactive</name>
43
+ <value>4</value>
44
+ </descriptor>
45
+ <descriptor>
46
+ <name>passenger_private_total</name>
47
+ <value>1515.1</value>
48
+ </descriptor>
49
+ <descriptor>
50
+ <name>nginx_processes</name>
51
+ <value>0</value>
52
+ </descriptor>
53
+ <descriptor>
54
+ <name>apache_private_total</name>
55
+ <value>10.3</value>
56
+ </descriptor>
57
+ <descriptor>
58
+ <name>apache_processes</name>
59
+ <value>5</value>
60
+ </descriptor>
61
+ </descriptors>
62
+ </plugin>
@@ -0,0 +1,127 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <plugins type="array">
3
+ <plugin>
4
+ <code-updated-at type="datetime">2010-01-14T18:39:52-05:00</code-updated-at>
5
+ <created-at type="datetime">2010-01-14T18:39:53-05:00</created-at>
6
+ <enabled type="boolean">true</enabled>
7
+ <failed-at type="datetime" nil="true"></failed-at>
8
+ <failing type="boolean">false</failing>
9
+ <first-reported-at type="datetime">2010-01-14T18:40:17-05:00</first-reported-at>
10
+ <id type="integer">122681</id>
11
+ <interval type="integer">0</interval>
12
+ <last-reported-at type="datetime">2010-01-30T19:01:00-05:00</last-reported-at>
13
+ <name>Passenger</name>
14
+ <plugin-url-id type="integer" nil="true"></plugin-url-id>
15
+ <status nil="true"></status>
16
+ <updated-at type="datetime">2010-01-30T19:01:04-05:00</updated-at>
17
+ <url>http://github.com/eric/sevenscale-scout-plugins/raw/master/passenger_united.rb</url>
18
+ <descriptors>
19
+ <descriptor>
20
+ <name>passenger_process_active</name>
21
+ <value>31</value>
22
+ </descriptor>
23
+ <descriptor>
24
+ <name>passenger_process_current</name>
25
+ <value>35</value>
26
+ </descriptor>
27
+ <descriptor>
28
+ <name>apache_vmsize_total</name>
29
+ <value>1613.7</value>
30
+ </descriptor>
31
+ <descriptor>
32
+ <name>passenger_queue_depth</name>
33
+ <value>0</value>
34
+ </descriptor>
35
+ <descriptor>
36
+ <name>passenger_max_pool_size</name>
37
+ <value>35</value>
38
+ </descriptor>
39
+ <descriptor>
40
+ <name>passenger_vmsize_total</name>
41
+ <value>6835.4</value>
42
+ </descriptor>
43
+ <descriptor>
44
+ <name>passenger_process_inactive</name>
45
+ <value>4</value>
46
+ </descriptor>
47
+ <descriptor>
48
+ <name>passenger_private_total</name>
49
+ <value>1515.1</value>
50
+ </descriptor>
51
+ <descriptor>
52
+ <name>nginx_processes</name>
53
+ <value>0</value>
54
+ </descriptor>
55
+ <descriptor>
56
+ <name>apache_private_total</name>
57
+ <value>10.3</value>
58
+ </descriptor>
59
+ <descriptor>
60
+ <name>apache_processes</name>
61
+ <value>5</value>
62
+ </descriptor>
63
+ </descriptors>
64
+ </plugin>
65
+ <plugin>
66
+ <code-updated-at type="datetime">2010-01-14T18:39:52-05:00</code-updated-at>
67
+ <created-at type="datetime">2010-01-14T18:39:53-05:00</created-at>
68
+ <enabled type="boolean">true</enabled>
69
+ <failed-at type="datetime" nil="true"></failed-at>
70
+ <failing type="boolean">false</failing>
71
+ <first-reported-at type="datetime">2010-01-14T18:40:17-05:00</first-reported-at>
72
+ <id type="integer">122682</id>
73
+ <interval type="integer">0</interval>
74
+ <last-reported-at type="datetime">2010-01-30T19:01:00-05:00</last-reported-at>
75
+ <name>Passenger 2</name>
76
+ <plugin-url-id type="integer" nil="true"></plugin-url-id>
77
+ <status nil="true"></status>
78
+ <updated-at type="datetime">2010-01-30T19:01:04-05:00</updated-at>
79
+ <url>http://github.com/eric/sevenscale-scout-plugins/raw/master/passenger_united.rb</url>
80
+ <descriptors>
81
+ <descriptor>
82
+ <name>passenger_process_active</name>
83
+ <value>31</value>
84
+ </descriptor>
85
+ <descriptor>
86
+ <name>passenger_process_current</name>
87
+ <value>35</value>
88
+ </descriptor>
89
+ <descriptor>
90
+ <name>apache_vmsize_total</name>
91
+ <value>1613.7</value>
92
+ </descriptor>
93
+ <descriptor>
94
+ <name>passenger_queue_depth</name>
95
+ <value>0</value>
96
+ </descriptor>
97
+ <descriptor>
98
+ <name>passenger_max_pool_size</name>
99
+ <value>35</value>
100
+ </descriptor>
101
+ <descriptor>
102
+ <name>passenger_vmsize_total</name>
103
+ <value>6835.4</value>
104
+ </descriptor>
105
+ <descriptor>
106
+ <name>passenger_process_inactive</name>
107
+ <value>4</value>
108
+ </descriptor>
109
+ <descriptor>
110
+ <name>passenger_private_total</name>
111
+ <value>1515.1</value>
112
+ </descriptor>
113
+ <descriptor>
114
+ <name>nginx_processes</name>
115
+ <value>0</value>
116
+ </descriptor>
117
+ <descriptor>
118
+ <name>apache_private_total</name>
119
+ <value>10.3</value>
120
+ </descriptor>
121
+ <descriptor>
122
+ <name>apache_processes</name>
123
+ <value>5</value>
124
+ </descriptor>
125
+ </descriptors>
126
+ </plugin>
127
+ </plugins>
@@ -14,7 +14,7 @@ describe "ScoutScout" do
14
14
  describe "global" do
15
15
  describe "client list" do
16
16
  before(:each) do
17
- stub_http_response_with('clients.xml')
17
+ @scout_scout.stub_get('clients.xml')
18
18
  @clients = @scout_scout.clients
19
19
  end
20
20
  it 'should list all clients' do
@@ -26,7 +26,7 @@ describe "ScoutScout" do
26
26
  end
27
27
  describe 'alert log' do
28
28
  before(:each) do
29
- stub_http_response_with('activities.xml')
29
+ @scout_scout.stub_get('activities.xml')
30
30
  @activities = @scout_scout.alerts
31
31
  end
32
32
  it "should be accessable" do
@@ -38,18 +38,29 @@ describe "ScoutScout" do
38
38
  end
39
39
  end
40
40
  describe 'individual clients' do
41
- describe '' do
42
- before(:each) do
43
- stub_http_response_with('client.xml')
44
- @client = @scout_scout.client(1234)
41
+ describe 'should be accessable' do
42
+ describe '' do
43
+ before(:each) do
44
+ @scout_scout.stub_get('clients/1234.xml', 'client.xml')
45
+ @client = @scout_scout.client(1234)
46
+ end
47
+ it "by id" do
48
+ @client.key.should == 'FOOBAR'
49
+ end
45
50
  end
46
- it "should be accessable" do
47
- @client.key.should == 'FOOBAR'
51
+ describe '' do
52
+ before(:each) do
53
+ @scout_scout.stub_get('clients.xml?host=foo.awesome.com', 'client_by_hostname.xml')
54
+ @client = @scout_scout.client('foo.awesome.com')
55
+ end
56
+ it "by hostname" do
57
+ @client.key.should == 'FOOBAR'
58
+ end
48
59
  end
49
60
  end
50
61
  describe 'alert log' do
51
62
  before(:each) do
52
- stub_http_response_with('activities.xml')
63
+ @scout_scout.stub_get('clients/1234/activities.xml', 'activities.xml')
53
64
  @activities = @scout_scout.alerts(1234)
54
65
  end
55
66
  it "should be accessable" do
@@ -59,37 +70,35 @@ describe "ScoutScout" do
59
70
  end
60
71
  end
61
72
  end
62
- describe 'plugins' do
63
- describe '' do
73
+ describe 'plugin' do
74
+ describe 'list' do
64
75
  before(:each) do
65
- stub_http_response_with('plugins.xml')
76
+ @scout_scout.stub_get('clients/1234/plugins.xml', 'plugins.xml')
66
77
  @plugins = @scout_scout.plugins(1234)
67
78
  end
68
79
  it "should be accessable" do
69
- @plugins.size.should == 4
80
+ @plugins.size.should == 2
70
81
  @plugins.each do |plugin|
71
- plugin.code.should =~ /Scout::Plugin/
82
+ plugin.name.should =~ /Passenger/
83
+ plugin.descriptors.length.should == 11
72
84
  end
73
85
  end
74
86
  end
75
- describe 'data' do
87
+ describe 'individually' do
76
88
  before(:each) do
77
- stub_http_response_with('plugin.html')
78
- @plugin_data = @scout_scout.plugin_data(1234,5678)
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')
79
91
  end
80
92
  it "should be accessable" do
81
- @plugin_data.size.should == 13
93
+ @plugin_data.name.should == 'Passenger'
94
+ @plugin_data.descriptors.length.should == 11
82
95
  end
83
- it "should include data" do
84
- @plugin_data.first.data.should == '6 MB'
85
- end
86
- it "should include graph URLs" do
87
- @plugin_data.first.graph.should == 'https://scoutapp.com/account/descriptors/368241/graph'
88
- end
89
- it "should include name" do
90
- @plugin_data.first.name.should == 'Swap Used'
96
+ it "should include descriptors" do
97
+ @plugin_data.descriptors.first.value.should == '31'
98
+ @plugin_data.descriptors.first.name.should == 'passenger_process_active'
91
99
  end
92
100
  end
101
+
93
102
  end
94
103
  end
95
104
  end
@@ -5,19 +5,48 @@ require 'fakeweb'
5
5
 
6
6
  FakeWeb.allow_net_connect = false
7
7
 
8
- def file_fixture(filename)
9
- open(File.join(File.dirname(__FILE__), 'fixtures', "#{filename.to_s}")).read
10
- end
8
+ class ScoutScout
11
9
 
12
- def stub_http_response_with(filename)
13
- format = filename.split('.').last.intern
14
- data = file_fixture(filename)
10
+ def scout_url(path)
11
+ uri = URI.join(self.class.default_options[:base_uri], "#{self.class.account}/", path)
12
+ uri.userinfo = "#{self.class.default_options[:basic_auth][:username]}:#{self.class.default_options[:basic_auth][:password]}".gsub(/@/, '%40')
13
+ uri.to_s
14
+ end
15
15
 
16
- response = Net::HTTPOK.new("1.1", 200, "Content for you")
17
- response.stub!(:body).and_return(data)
16
+ def file_fixture(filename)
17
+ open(File.join(File.dirname(__FILE__), 'fixtures', "#{filename.to_s}")).read
18
+ end
18
19
 
19
- http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://localhost', :format => format)
20
- http_request.stub!(:perform_actual_request).and_return(response)
20
+ def stub_get(path, filename = nil, status=nil)
21
+ filename = path if filename.nil?
22
+ options = {:body => file_fixture(filename)}
23
+ options.merge!({:status => status}) unless status.nil?
24
+ FakeWeb.register_uri(:get, scout_url(path), options)
25
+ end
26
+
27
+ def stub_post(path, filename)
28
+ FakeWeb.register_uri(:post, scout_url(path), :body => file_fixture(filename))
29
+ end
30
+
31
+ def stub_put(path, filename)
32
+ FakeWeb.register_uri(:put, scout_url(path), :body => file_fixture(filename))
33
+ end
34
+
35
+ def stub_delete(path, filename)
36
+ FakeWeb.register_uri(:delete, scout_url(path), :body => file_fixture(filename))
37
+ end
38
+
39
+ def stub_http_response_with(filename)
40
+ format = filename.split('.').last.intern
41
+ data = file_fixture(filename)
42
+
43
+ response = Net::HTTPOK.new("1.1", 200, "Content for you")
44
+ response.stub!(:body).and_return(data)
45
+
46
+ http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://localhost', :format => format)
47
+ http_request.stub!(:perform_actual_request).and_return(response)
48
+
49
+ HTTParty::Request.should_receive(:new).at_least(1).and_return(http_request)
50
+ end
21
51
 
22
- HTTParty::Request.should_receive(:new).and_return(http_request)
23
52
  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.1
4
+ version: 0.0.2
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-21 00:00:00 -05:00
12
+ date: 2010-01-30 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -67,9 +67,14 @@ files:
67
67
  - LICENSE
68
68
  - README.rdoc
69
69
  - Rakefile
70
- - VERSION
71
70
  - lib/scout_scout.rb
72
71
  - lib/scout_scout/version.rb
72
+ - spec/fixtures/activities.xml
73
+ - spec/fixtures/client.xml
74
+ - spec/fixtures/client_by_hostname.xml
75
+ - spec/fixtures/clients.xml
76
+ - spec/fixtures/plugin_data.xml
77
+ - spec/fixtures/plugins.xml
73
78
  - spec/scout_scout_spec.rb
74
79
  - spec/spec.opts
75
80
  - spec/spec_helper.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.1