scout_api 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/CHANGELOG +3 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +25 -0
- data/LICENSE +20 -0
- data/README.rdoc +81 -0
- data/Rakefile +43 -0
- data/lib/scout_api/account.rb +72 -0
- data/lib/scout_api/alert.rb +17 -0
- data/lib/scout_api/group.rb +73 -0
- data/lib/scout_api/metric.rb +243 -0
- data/lib/scout_api/metric_calculation.rb +61 -0
- data/lib/scout_api/metric_proxy.rb +112 -0
- data/lib/scout_api/person.rb +3 -0
- data/lib/scout_api/plugin.rb +61 -0
- data/lib/scout_api/server.rb +165 -0
- data/lib/scout_api/trigger.rb +11 -0
- data/lib/scout_api/version.rb +3 -0
- data/lib/scout_api.rb +22 -0
- data/scout_scout.gemspec +86 -0
- data/test/alert_test.rb +20 -0
- data/test/fixtures/activities.xml +33 -0
- data/test/fixtures/client.xml +22 -0
- data/test/fixtures/client_by_hostname.xml +23 -0
- data/test/fixtures/clients.xml +59 -0
- data/test/fixtures/data.xml +5 -0
- data/test/fixtures/descriptors.xml +93 -0
- data/test/fixtures/plugin_data.xml +62 -0
- data/test/fixtures/plugins.xml +127 -0
- data/test/fixtures/triggers.xml +40 -0
- data/test/global_test.rb +27 -0
- data/test/metric_proxy_test.rb +17 -0
- data/test/metric_test.rb +32 -0
- data/test/plugin_test.rb +12 -0
- data/test/server_test.rb +97 -0
- data/test/test_helper.rb +53 -0
- metadata +185 -0
@@ -0,0 +1,93 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<ar-descriptors type="array">
|
3
|
+
<ar-descriptor>
|
4
|
+
<name>Passenger/apache_private_total</name>
|
5
|
+
</ar-descriptor>
|
6
|
+
<ar-descriptor>
|
7
|
+
<name>Server Overview/cpu_last_fifteen_minutes</name>
|
8
|
+
</ar-descriptor>
|
9
|
+
<ar-descriptor>
|
10
|
+
<name>Server Overview/cpu_last_five_minutes</name>
|
11
|
+
</ar-descriptor>
|
12
|
+
<ar-descriptor>
|
13
|
+
<name>Server Overview/cpu_last_minute</name>
|
14
|
+
</ar-descriptor>
|
15
|
+
<ar-descriptor>
|
16
|
+
<name>Server Overview/disk_avail</name>
|
17
|
+
</ar-descriptor>
|
18
|
+
<ar-descriptor>
|
19
|
+
<name>Server Overview/disk_capacity</name>
|
20
|
+
</ar-descriptor>
|
21
|
+
<ar-descriptor>
|
22
|
+
<name>Server Overview/disk_size</name>
|
23
|
+
</ar-descriptor>
|
24
|
+
<ar-descriptor>
|
25
|
+
<name>Server Overview/disk_used</name>
|
26
|
+
</ar-descriptor>
|
27
|
+
<ar-descriptor>
|
28
|
+
<name>Network Throughput/eth0_in</name>
|
29
|
+
</ar-descriptor>
|
30
|
+
<ar-descriptor>
|
31
|
+
<name>Network Throughput/eth0_in_packets</name>
|
32
|
+
</ar-descriptor>
|
33
|
+
<ar-descriptor>
|
34
|
+
<name>Network Throughput/eth0_out</name>
|
35
|
+
</ar-descriptor>
|
36
|
+
<ar-descriptor>
|
37
|
+
<name>Network Throughput/eth0_out_packets</name>
|
38
|
+
</ar-descriptor>
|
39
|
+
<ar-descriptor>
|
40
|
+
<name>Network Throughput/eth1_in</name>
|
41
|
+
</ar-descriptor>
|
42
|
+
<ar-descriptor>
|
43
|
+
<name>Network Throughput/eth1_in_packets</name>
|
44
|
+
</ar-descriptor>
|
45
|
+
<ar-descriptor>
|
46
|
+
<name>Network Throughput/eth1_out</name>
|
47
|
+
</ar-descriptor>
|
48
|
+
<ar-descriptor>
|
49
|
+
<name>Network Throughput/eth1_out_packets</name>
|
50
|
+
</ar-descriptor>
|
51
|
+
<ar-descriptor>
|
52
|
+
<name>Server Overview/mem_swap_percent</name>
|
53
|
+
</ar-descriptor>
|
54
|
+
<ar-descriptor>
|
55
|
+
<name>Server Overview/mem_swap_total</name>
|
56
|
+
</ar-descriptor>
|
57
|
+
<ar-descriptor>
|
58
|
+
<name>Server Overview/mem_swap_used</name>
|
59
|
+
</ar-descriptor>
|
60
|
+
<ar-descriptor>
|
61
|
+
<name>Server Overview/mem_total</name>
|
62
|
+
</ar-descriptor>
|
63
|
+
<ar-descriptor>
|
64
|
+
<name>Server Overview/mem_used</name>
|
65
|
+
</ar-descriptor>
|
66
|
+
<ar-descriptor>
|
67
|
+
<name>Server Overview/mem_used_percent</name>
|
68
|
+
</ar-descriptor>
|
69
|
+
<ar-descriptor>
|
70
|
+
<name>Passenger/nginx_processes</name>
|
71
|
+
</ar-descriptor>
|
72
|
+
<ar-descriptor>
|
73
|
+
<name>Passenger/passenger_max_pool_size</name>
|
74
|
+
</ar-descriptor>
|
75
|
+
<ar-descriptor>
|
76
|
+
<name>Passenger/passenger_private_total</name>
|
77
|
+
</ar-descriptor>
|
78
|
+
<ar-descriptor>
|
79
|
+
<name>Passenger/passenger_process_active</name>
|
80
|
+
</ar-descriptor>
|
81
|
+
<ar-descriptor>
|
82
|
+
<name>Passenger/passenger_process_current</name>
|
83
|
+
</ar-descriptor>
|
84
|
+
<ar-descriptor>
|
85
|
+
<name>Passenger/passenger_process_inactive</name>
|
86
|
+
</ar-descriptor>
|
87
|
+
<ar-descriptor>
|
88
|
+
<name>Passenger/passenger_queue_depth</name>
|
89
|
+
</ar-descriptor>
|
90
|
+
<ar-descriptor>
|
91
|
+
<name>Passenger/passenger_vmsize_total</name>
|
92
|
+
</ar-descriptor>
|
93
|
+
</ar-descriptors>
|
@@ -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>
|
@@ -0,0 +1,40 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<triggers type="array">
|
3
|
+
<trigger>
|
4
|
+
<id type="integer">119871</id>
|
5
|
+
<last-fired-at type="datetime">2010-04-08T04:10:00-04:00</last-fired-at>
|
6
|
+
<max-value type="float">85.0</max-value>
|
7
|
+
<min-value type="float">0.0</min-value>
|
8
|
+
<plugin-id type="integer">136421</plugin-id>
|
9
|
+
<sms-max-value type="float">90.0</sms-max-value>
|
10
|
+
<sms-percentage-change type="integer" nil="true"></sms-percentage-change>
|
11
|
+
<simple-type>peak</simple-type>
|
12
|
+
<title>Alert me when Disk Capacity exceeds 85%. SMS alert at 90%.</title>
|
13
|
+
<descriptor-label>Disk Capacity</descriptor-label>
|
14
|
+
</trigger>
|
15
|
+
<trigger>
|
16
|
+
<id type="integer">152031</id>
|
17
|
+
<last-fired-at type="datetime">2010-04-29T14:45:00-04:00</last-fired-at>
|
18
|
+
<max-value type="float">85.0</max-value>
|
19
|
+
<min-value type="float">0.0</min-value>
|
20
|
+
<plugin-id type="integer">136421</plugin-id>
|
21
|
+
<sms-max-value type="float">90.0</sms-max-value>
|
22
|
+
<sms-percentage-change type="integer" nil="true"></sms-percentage-change>
|
23
|
+
<simple-type>peak</simple-type>
|
24
|
+
<title>Alert me when % Memory Used exceeds 85%. SMS alert at 90%.</title>
|
25
|
+
<descriptor-label>% Memory Used</descriptor-label>
|
26
|
+
</trigger>
|
27
|
+
<trigger>
|
28
|
+
<id type="integer">119921</id>
|
29
|
+
<last-fired-at type="datetime" nil="true"></last-fired-at>
|
30
|
+
<max-value type="float">1.0</max-value>
|
31
|
+
<min-value type="float">0.0</min-value>
|
32
|
+
<plugin-id type="integer">136451</plugin-id>
|
33
|
+
<sms-max-value type="float">10.0</sms-max-value>
|
34
|
+
<sms-percentage-change type="integer" nil="true"></sms-percentage-change>
|
35
|
+
<simple-type>peak</simple-type>
|
36
|
+
<title>Alert me when Passenger Global Queue Depth exceeds 1 . SMS alert at 10 .</title>
|
37
|
+
<descriptor-label>Passenger Global Queue Depth</descriptor-label>
|
38
|
+
</trigger>
|
39
|
+
</triggers>
|
40
|
+
|
data/test/global_test.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.expand_path('../test_helper.rb', __FILE__)
|
2
|
+
|
3
|
+
class GlobalTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@scout = Scout::Account.new('account', 'username', 'password')
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_version
|
9
|
+
assert Scout::VERSION.is_a?(String)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_init
|
13
|
+
assert_equal 'account', @scout.class.param
|
14
|
+
assert @scout.class.default_options[:basic_auth] == { :username => 'username', :password => 'password' }
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_alerts
|
18
|
+
@scout.stub_get('activities.xml')
|
19
|
+
activities = @scout.alerts
|
20
|
+
assert activities.first.is_a?(Scout::Alert)
|
21
|
+
assert_equal 2, activities.size
|
22
|
+
activities.each do |activity|
|
23
|
+
assert activity.title =~ /Passenger/
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path('../test_helper.rb', __FILE__)
|
2
|
+
|
3
|
+
class MetricProxyTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@scout = Scout::Account.new('account', 'username', 'password')
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_metrics
|
9
|
+
@scout.stub_get('clients/13431.xml', 'client.xml')
|
10
|
+
server = Scout::Server.first(13431)
|
11
|
+
@scout.stub_get('descriptors.xml?name=&ids=&plugin_ids=&server_ids=13431&group_ids=', 'descriptors.xml')
|
12
|
+
metrics = server.metrics
|
13
|
+
assert_equal 30, metrics.size
|
14
|
+
assert metrics.first.is_a?(Scout::Metric)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/test/metric_test.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path('../test_helper.rb', __FILE__)
|
2
|
+
|
3
|
+
class MetricTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@scout = Scout::Account.new('account', 'username', 'password')
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_should_find_all_metrics
|
9
|
+
@scout.stub_get('descriptors.xml?name=blah&ids=&plugin_ids=&server_ids=&group_ids=','descriptors.xml')
|
10
|
+
metrics = Scout::Metric.all(:name=>'blah')
|
11
|
+
assert_equal Scout::Metric, metrics.first.class
|
12
|
+
assert_equal 30, metrics.size
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_should_get_klass_average
|
16
|
+
@scout.stub_get('data/value?name=cpu_last_minute&ids=&function=AVG&consolidate=AVG&plugin_ids=&server_ids=&group_ids=&start=&end=','data.xml')
|
17
|
+
result = Scout::Metric.average('cpu_last_minute')
|
18
|
+
assert result.is_a?(Hash)
|
19
|
+
assert_equal '31.10', result['value']
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_should_get_instance_average
|
23
|
+
@scout.stub_get('clients/13431.xml', 'client.xml')
|
24
|
+
server = Scout::Server.first(13431)
|
25
|
+
@scout.stub_get('clients/13431/plugins.xml', 'plugins.xml')
|
26
|
+
plugins = server.plugins
|
27
|
+
@scout.stub_get('data/value?name=passenger_process_active&ids=&function=AVG&consolidate=AVG&plugin_ids=&server_ids=&group_ids=&start=&end=','data.xml')
|
28
|
+
result = plugins.first.metrics.first.average
|
29
|
+
assert_equal '31.10', result['value']
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/test/plugin_test.rb
ADDED
data/test/server_test.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
require File.expand_path('../test_helper.rb', __FILE__)
|
2
|
+
|
3
|
+
class ServerTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@scout = Scout::Account.new('account', 'username', 'password')
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_first_by_id
|
9
|
+
@scout.stub_get('clients/13431.xml', 'client.xml')
|
10
|
+
server = Scout::Server.first(13431)
|
11
|
+
assert server.is_a?(Scout::Server)
|
12
|
+
assert_equal 13431, server.id
|
13
|
+
assert_equal 'FOOBAR', server.key
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_first_by_hostname
|
17
|
+
@scout.stub_get('clients.xml?host=foo.awesome.com', 'client_by_hostname.xml')
|
18
|
+
server = Scout::Server.first(:host => 'foo.awesome.com')
|
19
|
+
assert server.is_a?(Scout::Server)
|
20
|
+
assert_equal 'FOOBAR', server.key
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_find_all
|
24
|
+
@scout.stub_get('clients.xml')
|
25
|
+
servers = Scout::Server.all
|
26
|
+
assert_equal 2, servers.size
|
27
|
+
assert servers.first.is_a?(Scout::Server)
|
28
|
+
assert servers.last.active_alerts.first.is_a?(Scout::Alert)
|
29
|
+
assert servers.last.active_alerts.first.title =~ /Passenger/
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_plugin
|
33
|
+
@scout.stub_get('clients/13431.xml', 'client.xml')
|
34
|
+
server = Scout::Server.first(13431)
|
35
|
+
@scout.stub_get('clients/13431/plugins/122681.xml', 'plugin_data.xml')
|
36
|
+
plugin = server.plugin(122681)
|
37
|
+
assert plugin.is_a?(Scout::Plugin)
|
38
|
+
assert_equal 122681, plugin.id
|
39
|
+
|
40
|
+
assert plugin.metrics.first.is_a?(Scout::Metric)
|
41
|
+
assert_equal '31', plugin.metrics.first.value
|
42
|
+
assert_equal 'passenger_process_active', plugin.metrics.first.name
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_plugins
|
46
|
+
@scout.stub_get('clients/13431.xml', 'client.xml')
|
47
|
+
server = Scout::Server.first(13431)
|
48
|
+
@scout.stub_get('clients/13431/plugins.xml', 'plugins.xml')
|
49
|
+
plugins = server.plugins
|
50
|
+
|
51
|
+
assert_equal 2, plugins.size
|
52
|
+
plugins.each do |plugin|
|
53
|
+
assert plugin.name =~ /Passenger/
|
54
|
+
assert_equal 11, plugin.metrics.size
|
55
|
+
end
|
56
|
+
|
57
|
+
assert plugins.first.is_a?(Scout::Plugin)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_alerts
|
61
|
+
@scout.stub_get('clients/13431.xml', 'client.xml')
|
62
|
+
server = Scout::Server.first(13431)
|
63
|
+
@scout.stub_get('clients/13431/activities.xml', 'activities.xml')
|
64
|
+
activities = server.alerts
|
65
|
+
assert_equal 2, activities.size
|
66
|
+
activities.each do |activity|
|
67
|
+
assert activity.title =~ /Passenger/
|
68
|
+
end
|
69
|
+
assert activities.first.is_a?(Scout::Alert)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_triggers
|
73
|
+
@scout.stub_get('clients/13431.xml', 'client.xml')
|
74
|
+
server = Scout::Server.first(13431)
|
75
|
+
@scout.stub_get('clients/13431/triggers.xml', 'triggers.xml')
|
76
|
+
triggers = server.triggers
|
77
|
+
assert_equal 3, triggers.size
|
78
|
+
triggers.each do |trigger|
|
79
|
+
assert_equal 'peak', trigger.simple_type
|
80
|
+
end
|
81
|
+
assert triggers.first.is_a?(Scout::Trigger)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_create
|
85
|
+
@scout.stub_post('clients.xml?client[copy_plugins_from_client_id]=&client[name]=sweet%20new%20server',
|
86
|
+
'client.xml', {:id => '1234'})
|
87
|
+
@scout.stub_get('clients/1234.xml', 'client.xml')
|
88
|
+
server = Scout::Server.create('sweet new server')
|
89
|
+
assert_equal 13431, server.id
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_delete
|
93
|
+
@scout.stub_delete('clients/1234.xml','client.xml', {'status' => '200 OK'})
|
94
|
+
assert Scout::Server.delete(1234)
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '../../lib/scout_api')
|
3
|
+
require 'test/unit'
|
4
|
+
require 'fakeweb'
|
5
|
+
|
6
|
+
FakeWeb.allow_net_connect = false
|
7
|
+
|
8
|
+
class Scout::Account
|
9
|
+
|
10
|
+
def scout_url(path)
|
11
|
+
uri = URI.join(self.class.default_options[:base_uri], "#{self.class.param}/", path)
|
12
|
+
uri.userinfo = "#{self.class.default_options[:basic_auth][:username]}:#{self.class.default_options[:basic_auth][:password]}".gsub(/@/, '%40')
|
13
|
+
url = uri.to_s
|
14
|
+
url << (url.include?('?') ? '&' : '?') + "api_version=#{Scout::VERSION}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def file_fixture(filename)
|
18
|
+
open(File.join(File.dirname(__FILE__), 'fixtures', "#{filename.to_s}")).read
|
19
|
+
end
|
20
|
+
|
21
|
+
def stub_get(path, filename = nil, status=nil)
|
22
|
+
filename = path if filename.nil?
|
23
|
+
options = {:body => file_fixture(filename)}
|
24
|
+
options.merge!({:status => status}) unless status.nil?
|
25
|
+
FakeWeb.register_uri(:get, scout_url(path), options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def stub_post(path, filename, headers = {})
|
29
|
+
FakeWeb.register_uri(:post, scout_url(path), {:body => file_fixture(filename)}.merge(headers))
|
30
|
+
end
|
31
|
+
|
32
|
+
def stub_put(path, filename)
|
33
|
+
FakeWeb.register_uri(:put, scout_url(path), :body => file_fixture(filename))
|
34
|
+
end
|
35
|
+
|
36
|
+
def stub_delete(path, filename, headers = {})
|
37
|
+
FakeWeb.register_uri(:delete, scout_url(path), {:body => file_fixture(filename)}.merge(headers))
|
38
|
+
end
|
39
|
+
|
40
|
+
def stub_http_response_with(filename)
|
41
|
+
format = filename.split('.').last.intern
|
42
|
+
data = file_fixture(filename)
|
43
|
+
|
44
|
+
response = Net::HTTPOK.new("1.1", 200, "Content for you")
|
45
|
+
response.stub!(:body).and_return(data)
|
46
|
+
|
47
|
+
http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://localhost', :format => format)
|
48
|
+
http_request.stub!(:perform_actual_request).and_return(response)
|
49
|
+
|
50
|
+
HTTParty::Request.should_receive(:new).at_least(1).and_return(http_request)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|