giraffi 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/.document +5 -0
  2. data/.yardopts +7 -0
  3. data/Gemfile +10 -0
  4. data/HISTORY.md +6 -0
  5. data/LICENSE.md +20 -0
  6. data/README.md +114 -0
  7. data/Rakefile +53 -0
  8. data/VERSION +1 -0
  9. data/examples/setup_http_monitoring.rb +88 -0
  10. data/giraffi.gemspec +155 -0
  11. data/lib/giraffi/client/applogs.rb +25 -0
  12. data/lib/giraffi/client/axions.rb +96 -0
  13. data/lib/giraffi/client/items.rb +102 -0
  14. data/lib/giraffi/client/logs.rb +23 -0
  15. data/lib/giraffi/client/media.rb +67 -0
  16. data/lib/giraffi/client/monitoringdata.rb +25 -0
  17. data/lib/giraffi/client/my_current_status.rb +19 -0
  18. data/lib/giraffi/client/regions.rb +15 -0
  19. data/lib/giraffi/client/services.rb +97 -0
  20. data/lib/giraffi/client/trends.rb +25 -0
  21. data/lib/giraffi/client/triggers.rb +94 -0
  22. data/lib/giraffi/client.rb +73 -0
  23. data/lib/giraffi/config.rb +60 -0
  24. data/lib/giraffi/version.rb +3 -0
  25. data/lib/giraffi.rb +26 -0
  26. data/test/applogs_test.rb +55 -0
  27. data/test/axions_test.rb +149 -0
  28. data/test/client_test.rb +52 -0
  29. data/test/fixtures/add_applogs_success_response.json +3 -0
  30. data/test/fixtures/add_monitroingdata.json +1 -0
  31. data/test/fixtures/add_service_to_item.json +12 -0
  32. data/test/fixtures/add_trigger_to_service.json +1 -0
  33. data/test/fixtures/create_axion.json +1 -0
  34. data/test/fixtures/create_item.json +15 -0
  35. data/test/fixtures/create_medium.json +1 -0
  36. data/test/fixtures/find_applogs_with_no_param.json +11 -0
  37. data/test/fixtures/find_applogs_with_params.json +2 -0
  38. data/test/fixtures/find_average_trends.json +6 -0
  39. data/test/fixtures/find_axion_by_id.json +9 -0
  40. data/test/fixtures/find_axion_by_trigger.json +11 -0
  41. data/test/fixtures/find_axion_logs_with_no_param.json +6 -0
  42. data/test/fixtures/find_axion_logs_with_params.json +5 -0
  43. data/test/fixtures/find_axions_by_trigger_with_axionkind.json +1 -0
  44. data/test/fixtures/find_axions_by_trigger_without_axionkind.json +1 -0
  45. data/test/fixtures/find_axions_with_no_param.json +1 -0
  46. data/test/fixtures/find_axions_with_params.json +11 -0
  47. data/test/fixtures/find_failure_trends.json +1 -0
  48. data/test/fixtures/find_item_by_id.json +15 -0
  49. data/test/fixtures/find_items_with_no_param.json +77 -0
  50. data/test/fixtures/find_items_with_params.json +17 -0
  51. data/test/fixtures/find_media_by_axion.json +13 -0
  52. data/test/fixtures/find_media_with_no_param.json +22 -0
  53. data/test/fixtures/find_media_with_params.json +1 -0
  54. data/test/fixtures/find_medium_by_id.json +1 -0
  55. data/test/fixtures/find_monitoringdata_with_no_param.json +4 -0
  56. data/test/fixtures/find_monitoringdata_with_params.json +3 -0
  57. data/test/fixtures/find_region_by_service.json +1 -0
  58. data/test/fixtures/find_regions.json +1 -0
  59. data/test/fixtures/find_service_by_id.json +12 -0
  60. data/test/fixtures/find_service_by_item_with_params.json +14 -0
  61. data/test/fixtures/find_services_by_item_with_no_param.json +14 -0
  62. data/test/fixtures/find_services_with_no_param.json +38 -0
  63. data/test/fixtures/find_services_with_params.json +14 -0
  64. data/test/fixtures/find_trigger_by_id.json +12 -0
  65. data/test/fixtures/find_triggers_by_service.json +1 -0
  66. data/test/fixtures/find_triggers_with_no_param.json +34 -0
  67. data/test/fixtures/find_triggers_with_params.json +14 -0
  68. data/test/fixtures/my_current_status_about_fake_uri.json +6 -0
  69. data/test/fixtures/my_current_status_about_real_uri.json +6 -0
  70. data/test/giraffi_test.rb +14 -0
  71. data/test/items_test.rb +170 -0
  72. data/test/logs_test.rb +60 -0
  73. data/test/media_test.rb +104 -0
  74. data/test/monitoringdata_test.rb +53 -0
  75. data/test/my_current_status_test.rb +29 -0
  76. data/test/regions_test.rb +20 -0
  77. data/test/services_test.rb +166 -0
  78. data/test/test_helper.rb +40 -0
  79. data/test/trends_test.rb +35 -0
  80. data/test/triggers_test.rb +151 -0
  81. metadata +271 -0
@@ -0,0 +1,38 @@
1
+ [
2
+ {
3
+ "service":{
4
+ "id":17972,
5
+ "item_id":3681,
6
+ "normalinterval":300,
7
+ "options":{},
8
+ "servicetype":"ping",
9
+ "status":2,
10
+ "warninginterval":180,
11
+ "warningretry":5
12
+ }
13
+ },
14
+ {
15
+ "service":{
16
+ "id":18800,
17
+ "item_id":3824,
18
+ "normalinterval":300,
19
+ "options":{},
20
+ "servicetype":"ping",
21
+ "status":2,
22
+ "warninginterval":180,
23
+ "warningretry":5
24
+ }
25
+ },
26
+ {
27
+ "service":{
28
+ "id":20471,
29
+ "item_id":4090,
30
+ "normalinterval":300,
31
+ "options":{},
32
+ "servicetype":"ping",
33
+ "status":2,
34
+ "warninginterval":180,
35
+ "warningretry":5
36
+ }
37
+ }
38
+ ]
@@ -0,0 +1,14 @@
1
+ [
2
+ {
3
+ "service":{
4
+ "id":17972,
5
+ "item_id":3681,
6
+ "normalinterval":300,
7
+ "options":{},
8
+ "servicetype":"ping",
9
+ "status":2,
10
+ "warninginterval":180,
11
+ "warningretry":5
12
+ }
13
+ }
14
+ ]
@@ -0,0 +1,12 @@
1
+ {
2
+ "trigger":{
3
+ "id":123,
4
+ "service_id": 110,
5
+ "triggertype":"traffic",
6
+ "options":{
7
+ "value":100000,
8
+ "operator":"<"
9
+ },
10
+ "axioninterval":180
11
+ }
12
+ }
@@ -0,0 +1 @@
1
+ [{"trigger":{"axioninterval":180,"id":1150,"level":0,"options":{"time":"3"},"service_id":17972,"triggertype":"timeout"}}]
@@ -0,0 +1,34 @@
1
+ [
2
+ {
3
+ "trigger":{
4
+ "axioninterval":180,
5
+ "id":1150,
6
+ "level":0,
7
+ "options":{"time":"3"},
8
+ "service_id":17972,
9
+ "triggertype":"timeout"
10
+ }
11
+ },
12
+ {
13
+ "trigger":{
14
+ "axioninterval":180,
15
+ "id":1151,
16
+ "level":0,
17
+ "options":{"time":"3"},
18
+ "service_id":17972,
19
+ "triggertype":"timeout"
20
+ }
21
+ },
22
+ {
23
+ "trigger":{
24
+ "id":123,
25
+ "service_id": 110,
26
+ "triggertype":"traffic",
27
+ "options":{
28
+ "value":100000,
29
+ "operator":"<"
30
+ },
31
+ "axioninterval":180
32
+ }
33
+ }
34
+ ]
@@ -0,0 +1,14 @@
1
+ [
2
+ {
3
+ "trigger":{
4
+ "id":123,
5
+ "service_id": 110,
6
+ "triggertype":"traffic",
7
+ "options":{
8
+ "value":100000,
9
+ "operator":"<"
10
+ },
11
+ "axioninterval":180
12
+ }
13
+ }
14
+ ]
@@ -0,0 +1,6 @@
1
+ {
2
+ "my_current_status":{
3
+ "domain":"I am not here",
4
+ "alive":false
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "my_current_status":{
3
+ "domain": "papi.giraffi.jp",
4
+ "alive": true
5
+ }
6
+ }
@@ -0,0 +1,14 @@
1
+ require 'test_helper'
2
+
3
+ class GiraffiTest < Test::Unit::TestCase
4
+ context 'Testing the Ruby Gem for the Giraffi RESTful API' do
5
+
6
+ context 'about the module `giraffi`' do
7
+ should 'create a new giraffi client via the alias Giraffi.new' do
8
+ giraffi = Giraffi.new({apikey: apikey})
9
+ assert_equal Giraffi::Client, giraffi.class
10
+ end
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,170 @@
1
+ require 'test_helper'
2
+
3
+ class ItemsTest < Test::Unit::TestCase
4
+ context "Testing Giraffi Ruby Gem for the Giraffi RESTful" do
5
+ setup do
6
+
7
+ @customkey = "26cfa4e2-e493-44d7-8322-4f03b467b412"
8
+ @item_id = 3681
9
+ @service_id = 17972
10
+
11
+ @item_attrs = {
12
+ name: "Locus Solus",
13
+ host: nil,
14
+ ip: "127.0.0.59",
15
+ normalinterval: "300",
16
+ warninginterval: "180",
17
+ warningretry: "5",
18
+ status: "2",
19
+ customkey: "6f76d596-e4c7-4b54-9afb-e2615c42d1aa"
20
+ }
21
+ end
22
+
23
+ context 'about the API related to the items' do
24
+ should 'return successfully the desired items with no param' do
25
+ stub_request(:get, "#{Giraffi.endpoint}/items.json?apikey=#{apikey}").
26
+ with(headers: Giraffi.request_headers).
27
+ to_return(body: fixture("find_items_with_no_param.json"))
28
+
29
+ giraffi = Giraffi.new({apikey: apikey})
30
+ response = giraffi.find_items
31
+ assert response.ok?
32
+ assert_equal JSON.parse(response.body).size, 5
33
+ end
34
+
35
+ should 'return successfully the desired item with params' do
36
+ stub_request(:get, "#{Giraffi.endpoint}/items.json?apikey=#{apikey}&customkey=#{@customkey}").
37
+ with(body: {}, headers: Giraffi.request_headers).
38
+ to_return(body: fixture("find_items_with_params.json"))
39
+
40
+ giraffi = Giraffi.new({apikey: apikey})
41
+ response = giraffi.find_items({customkey: @customkey})
42
+ assert response.ok?
43
+ assert_equal JSON.parse(response.body)[0]['item']['customkey'], @customkey
44
+ end
45
+
46
+ should 'return successfully the desired item by the numerical ID' do
47
+ stub_request(:get, "#{Giraffi.endpoint}/items/#{@item_id}.json?apikey=#{apikey}").
48
+ with(headers: Giraffi.request_headers).
49
+ to_return(body: fixture("find_item_by_id.json"))
50
+
51
+ giraffi = Giraffi.new({apikey: apikey})
52
+ response = giraffi.find_item(@item_id)
53
+ assert response.ok?
54
+ assert_equal JSON.parse(response.body)['item']['id'], @item_id
55
+ end
56
+
57
+ should 'return the desired agent related to the item' do
58
+ # TODO
59
+ end
60
+
61
+ should 'return all services related to the item' do
62
+ stub_request(:get, "#{Giraffi.endpoint}/items/#{@item_id}/services.json?apikey=#{apikey}").
63
+ with(headers: Giraffi.request_headers).
64
+ to_return(body: fixture("find_services_by_item_with_no_param.json"))
65
+
66
+ giraffi = Giraffi.new({apikey: apikey})
67
+ response = giraffi.find_services_by_item(@item_id)
68
+ assert response.ok?
69
+ assert_equal @item_id, JSON.parse(response.body)[0]['service']['item_id']
70
+ end
71
+
72
+ should 'return a service related to the item with params' do
73
+ stub_request(:get, "#{Giraffi.endpoint}/items/#{@item_id}/services.json?apikey=#{apikey}").
74
+ with(query: {servicetype: "ping"}, headers: Giraffi.request_headers).
75
+ to_return(body: fixture("find_service_by_item_with_params.json"))
76
+
77
+ giraffi = Giraffi.new({apikey: apikey})
78
+ response = giraffi.find_services_by_item(@item_id, {servicetype: "ping"})
79
+ assert response.ok?
80
+ assert_equal @item_id, JSON.parse(response.body)[0]['service']['item_id']
81
+ assert_equal 'ping', JSON.parse(response.body)[0]['service']['servicetype']
82
+ end
83
+
84
+ should 'return no service related to the item with bad params' do
85
+ stub_request(:get, "#{Giraffi.endpoint}/items/#{@item_id}/services.json?apikey=#{apikey}").
86
+ with(query: {servicetype: "http"}, headers: Giraffi.request_headers).
87
+ to_return(body: [])
88
+
89
+ giraffi = Giraffi.new({apikey: apikey})
90
+ response = giraffi.find_services_by_item(@item_id, {servicetype: "http"})
91
+ assert response.ok?
92
+ assert_equal response.body.size, 0
93
+ end
94
+
95
+ should 'create successfully a new item' do
96
+ stub_request(:post, "#{Giraffi.endpoint}/items.json?apikey=#{apikey}").
97
+ with(:query => { :item => @item_attrs } , :headers => Giraffi.request_headers).
98
+ to_return(status: 201, :body => fixture('create_item.json'))
99
+
100
+ giraffi = Giraffi.new({apikey: apikey})
101
+ response = giraffi.create_item(@item_attrs)
102
+ assert_equal response.code, 201
103
+ assert_equal JSON.parse(response.body)['item']['name'], 'Locus Solus'
104
+ end
105
+
106
+ should 'reload all item' do
107
+ stub_request(:post, "#{Giraffi.endpoint}/items/reload.json?apikey=#{apikey}").
108
+ to_return(body: "\"OK\"")
109
+
110
+ giraffi = Giraffi.new({apikey: apikey})
111
+ response = giraffi.reload_items
112
+ assert response.ok?
113
+ assert_equal response.body, "\"OK\""
114
+ end
115
+
116
+ should 'add successfully a service to the item' do
117
+ stub_request(:post, "#{Giraffi.endpoint}/items/#{@item_id}/services.json?apikey=#{apikey}").
118
+ with(:query => { :service => { :servicetype => "applog", :status => "1" }}, :headers => Giraffi.request_headers).
119
+ to_return(:status => 201, :body => fixture('add_service_to_item.json'))
120
+
121
+ giraffi = Giraffi.new({apikey: apikey})
122
+ response = giraffi.add_service_to_item(@item_id, {servicetype: "applog", status: "1"})
123
+ assert_equal response.code, 201
124
+ assert_equal JSON.parse(response.body)['service']['item_id'], @item_id
125
+ end
126
+
127
+ should 'update successfully the desired item' do
128
+ stub_request(:put, "#{Giraffi.endpoint}/items/#{@item_id}.json?apikey=#{apikey}").
129
+ with(:body => {}, :query => {:item => {:name => "LeRoiUbu"}}, :headers => Giraffi.request_headers).
130
+ to_return(:status => 200, :body => {})
131
+
132
+ giraffi = Giraffi.new({apikey: apikey})
133
+ response = giraffi.update_item(3681, {:name => "LeRoiUbu"})
134
+ assert response.ok?
135
+ assert response.body == {}
136
+ end
137
+
138
+ should 'delete successfully the item' do
139
+ stub_request(:delete, "#{Giraffi.endpoint}/items/#{@item_id}.json?apikey=#{apikey}").
140
+ to_return(:status => 200, :body => {})
141
+
142
+ giraffi = Giraffi.new({apikey: apikey})
143
+ response = giraffi.destroy_item(@item_id)
144
+ assert response.ok?
145
+ assert response.body == {}
146
+ end
147
+
148
+ should 'remove successfully a service from the item' do
149
+ stub_request(:delete, "#{Giraffi.endpoint}/items/#{@item_id}/services/17972.json?apikey=#{apikey}").
150
+ to_return(:body => {})
151
+
152
+ giraffi = Giraffi.new({apikey: apikey})
153
+ response = giraffi.remove_service_from_item(@item_id, @service_id)
154
+ assert_nothing_raised ArgumentError do
155
+ giraffi.remove_service_from_item(@item_id, @service_id)
156
+ end
157
+ assert response.ok?
158
+ assert response.body == {}
159
+ end
160
+
161
+ should 'raise an error when the number of arguments for `remove_service_from_item` is not 2' do
162
+ giraffi = Giraffi.new({apikey: apikey})
163
+ assert_raise ArgumentError do
164
+ giraffi.remove_service_from_item(@item_id)
165
+ end
166
+ end
167
+ end
168
+
169
+ end
170
+ end
data/test/logs_test.rb ADDED
@@ -0,0 +1,60 @@
1
+ require 'test_helper'
2
+
3
+ class LogsTest < Test::Unit::TestCase
4
+ context "Testing Giraffi Ruby Gem for the Giraffi RESTful" do
5
+ setup do
6
+ @axion_id = '425'
7
+ end
8
+
9
+ context 'about the API related to the axion logs' do
10
+ should 'return successfully the logs related to the axions with no param' do
11
+ stub_request(:get, "#{Giraffi.endpoint}/logs/axion.json?apikey=#{apikey}").
12
+ with(headers: Giraffi.request_headers).
13
+ to_return(body: fixture("find_axion_logs_with_no_param.json"))
14
+
15
+ giraffi = Giraffi.new({apikey: apikey})
16
+ response = giraffi.find_axion_logs
17
+ assert response.ok?
18
+ assert_equal JSON.parse(response.body).size, 4
19
+ assert_equal JSON.parse(response.body)[0]['axion_id'], 422
20
+ end
21
+
22
+ should 'return successfully the logs related to the axions with params' do
23
+ stub_request(:get, "#{Giraffi.endpoint}/logs/axion.json?apikey=#{apikey}").
24
+ with(query: {axion_id: "425"}, headers: Giraffi.request_headers).
25
+ to_return(body: fixture("find_axion_logs_with_params.json"))
26
+
27
+ giraffi = Giraffi.new({apikey: apikey})
28
+ response = giraffi.find_axion_logs({axion_id: @axion_id})
29
+ assert response.ok?
30
+ assert_equal JSON.parse(response.body).size, 3
31
+ assert_equal JSON.parse(response.body)[0]['axion_id'], @axion_id.to_i
32
+ end
33
+
34
+ should 'return successfully the number of logs related to the axions with no param' do
35
+ stub_request(:get, "#{Giraffi.endpoint}/logs/axion/count.json?apikey=#{apikey}").
36
+ with(headers: Giraffi.request_headers).
37
+ to_return(status: 200, body: "4")
38
+
39
+ giraffi = Giraffi.new({apikey: apikey})
40
+ response = giraffi.count_axion_logs
41
+
42
+ assert response.ok?
43
+ assert_equal response.body, "4"
44
+ end
45
+
46
+ should 'return successfully the number of logs related to the axions with no param' do
47
+ stub_request(:get, "#{Giraffi.endpoint}/logs/axion/count.json?apikey=#{apikey}").
48
+ with(:query => {axion_id: @axion_id}, headers: Giraffi.request_headers).
49
+ to_return(status: 200, body: "3")
50
+
51
+ giraffi = Giraffi.new({apikey: apikey})
52
+ response = giraffi.count_axion_logs({axion_id: @axion_id})
53
+
54
+ assert response.ok?
55
+ assert_equal response.body, "3"
56
+ end
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,104 @@
1
+ require 'test_helper'
2
+
3
+ class MediaTest < Test::Unit::TestCase
4
+ context "Testing Giraffi Ruby Gem for the Giraffi RESTful" do
5
+ setup do
6
+ @medium_id = '522'
7
+ @medium_attrs = {
8
+ name: "Tweats what happened",
9
+ mediumtype: "twitter"
10
+ }
11
+ end
12
+
13
+ context 'about the API related to the media' do
14
+ should 'return successfully the desired media with no param' do
15
+ stub_request(:get, "#{Giraffi.endpoint}/media.json?apikey=#{apikey}").
16
+ with(headers: Giraffi.request_headers).
17
+ to_return(body: fixture("find_media_with_no_param.json"))
18
+
19
+ giraffi = Giraffi.new({apikey: apikey})
20
+ response = giraffi.find_media({})
21
+ assert response.ok?
22
+ assert_equal JSON.parse(response.body).size, 2
23
+ assert_equal JSON.parse(response.body)[1]['medium']['mediumtype'], "twitter"
24
+ end
25
+
26
+ should 'return successfully the desired media with params' do
27
+ stub_request(:get, "#{Giraffi.endpoint}/media.json?apikey=#{apikey}").
28
+ with(body: {}, query: {mediumtype: "twitter"}, headers: Giraffi.request_headers).
29
+ to_return(body: fixture("find_media_with_params.json"))
30
+
31
+ giraffi = Giraffi.new({apikey: apikey})
32
+ response = giraffi.find_media({mediumtype: "twitter"})
33
+ assert response.ok?
34
+ assert_equal JSON.parse(response.body).size, 1
35
+ assert_equal JSON.parse(response.body)[0]['medium']['mediumtype'], 'twitter'
36
+ end
37
+
38
+ should 'return successfully the desired medium by the numerical ID' do
39
+ stub_request(:get, "#{Giraffi.endpoint}/media/#{@medium_id}.json?apikey=#{apikey}").
40
+ with(headers: Giraffi.request_headers).
41
+ to_return(body: fixture("find_medium_by_id.json"))
42
+
43
+ giraffi = Giraffi.new({apikey: apikey})
44
+ response = giraffi.find_medium(@medium_id)
45
+ assert response.ok?
46
+ assert_equal JSON.parse(response.body)['medium']['id'], @medium_id.to_i
47
+ end
48
+
49
+ should 'redirect successfully to the requested page by the oauth related to the medium' do
50
+ # TODO
51
+ end
52
+
53
+ should 'return successfully the oauth-callback related to the medium' do
54
+ # TODO
55
+
56
+ #giraffi = Giraffi.new({apikey: apikey})
57
+ #assert_nothing_raised ArgumentError do
58
+ # giraffi.find_oauth_callback_by_medium(@medium_id, 'oauth_token')
59
+ #end
60
+ end
61
+
62
+ should 'raise an error when the number of arguments for `find_oauth_callback` is not 2' do
63
+ giraffi = Giraffi.new({apikey: apikey})
64
+ assert_raise ArgumentError do
65
+ giraffi.find_oauth_callback_by_medium(@medium_id)
66
+ end
67
+ end
68
+
69
+ should 'create successfully a new medium' do
70
+ stub_request(:post, "#{Giraffi.endpoint}/media.json?apikey=#{apikey}").
71
+ with(:query => {:medium => @medium_attrs}, headers: Giraffi.request_headers).
72
+ to_return(status: 201, body: fixture("create_medium.json"))
73
+
74
+ giraffi = Giraffi.new({apikey: apikey})
75
+ response = giraffi.create_medium(@medium_attrs)
76
+ assert_equal response.code, 201
77
+ assert_equal JSON.parse(response.body)['medium']['name'], "Tweats what happened"
78
+ end
79
+
80
+ should 'update successfully the desired medium' do
81
+ stub_request(:put, "#{Giraffi.endpoint}/media/#{@medium_id}.json?apikey=#{apikey}").
82
+ with(:body => {}, :query => {:medium => {:options => {:address => "foo@example.com"}}}, :headers => Giraffi.request_headers).
83
+ to_return(:status => 200, :body => {})
84
+
85
+ giraffi = Giraffi.new({apikey: apikey})
86
+ response = giraffi.update_medium(@medium_id, {:options => {:address => "foo@example.com"}})
87
+ assert response.ok?
88
+ assert response.body == {}
89
+ end
90
+
91
+ should 'delete successfully the medium' do
92
+ stub_request(:delete, "#{Giraffi.endpoint}/media/#{@medium_id}?apikey=#{apikey}").
93
+ with(:headers => Giraffi.request_headers).
94
+ to_return(:status => 200, :body => {})
95
+
96
+ giraffi = Giraffi.new({apikey: apikey})
97
+ response = giraffi.destroy_medium(@medium_id)
98
+ assert response.ok?
99
+ assert response.body == {}
100
+ end
101
+ end
102
+
103
+ end
104
+ end
@@ -0,0 +1,53 @@
1
+ require 'test_helper'
2
+
3
+ class MonitoringdataTest < Test::Unit::TestCase
4
+ context "Testing Giraffi Ruby Gem for the Giraffi RESTful" do
5
+ setup do
6
+ @monitoringdata_attrs = {
7
+ :service_id => "17972",
8
+ :servicetype => "load_average",
9
+ :value => "20",
10
+ :tags => ["Testing now", "26cfa4e2-e493-44d7-8322-4f03b467b412"],
11
+ :checked_at => "#{Time.now().to_i}"
12
+ }
13
+ end
14
+
15
+ context 'about the API related to the monitoring data' do
16
+ should 'return successfully the desired monitoring data with no param' do
17
+ stub_request(:get, "#{Giraffi.endpoint}/monitoringdata.json?apikey=#{apikey}").
18
+ with(headers: Giraffi.request_headers).
19
+ to_return(status: 200, body: fixture("find_monitoringdata_with_no_param.json"))
20
+
21
+ giraffi = Giraffi.new({apikey: apikey})
22
+ response = giraffi.find_monitoringdata
23
+ assert response.ok?
24
+ assert_equal JSON.parse(response.body).size, 2
25
+ assert_equal JSON.parse(response.body)[0]['job_id'], "bce29a30-fef0-012e-4b4f-525400011682"
26
+ end
27
+
28
+ should 'return successfully the desired monitoring data with params' do
29
+ stub_request(:get, "#{Giraffi.endpoint}/monitoringdata.json?apikey=#{apikey}").
30
+ with(query: {job_id: "e21d3e40-01dd-012f-6bef-5254000ab9a8"}, headers: Giraffi.request_headers).
31
+ to_return(status: 200, body: fixture("find_monitoringdata_with_params.json"))
32
+
33
+ giraffi = Giraffi.new({apikey: apikey})
34
+ response = giraffi.find_monitoringdata({job_id: "e21d3e40-01dd-012f-6bef-5254000ab9a8"})
35
+ assert response.ok?
36
+ assert_equal JSON.parse(response.body).size, 1
37
+ assert_equal JSON.parse(response.body)[0]['job_id'], "e21d3e40-01dd-012f-6bef-5254000ab9a8"
38
+ end
39
+
40
+ should 'add successfully the monitoring data to the Giraffi' do
41
+ stub_request(:post, "#{Giraffi.monitoringdata_endpoint}/internal/nodelayed?apikey=#{apikey}").
42
+ with(:body => MultiJson.encode({:internal => @monitoringdata_attrs}), headers: Giraffi.request_headers).
43
+ to_return(status: 200, body: fixture("add_monitroingdata.json"))
44
+
45
+ giraffi = Giraffi.new({apikey: apikey})
46
+ response = giraffi.add_monitoringdata(@monitoringdata_attrs)
47
+ assert response.ok?
48
+ assert_equal JSON.parse(response.body)['tags'], ["26cfa4e2-e493-44d7-8322-4f03b467b412"]
49
+ end
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+ require 'json'
3
+
4
+ class MyCurrentStatusTest < Test::Unit::TestCase
5
+ context "Testing Giraffi Ruby Gem for the Giraffi RESTful" do
6
+
7
+ context 'about the API related to the current status of the Giraffi API' do
8
+ should 'return the status related to the requested URI' do
9
+ stub_request(:get, "#{Giraffi.endpoint}/my_current_status.json").
10
+ with(headers: Giraffi.request_headers).
11
+ to_return(body: fixture("my_current_status_about_real_uri.json"))
12
+
13
+ giraffi = Giraffi.new
14
+ response = giraffi.my_current_status('papi')
15
+ assert response.ok?
16
+ assert_equal JSON.parse(response.body)['my_current_status']['domain'], Giraffi.endpoint.sub(/https:\/\//,'')
17
+ assert JSON.parse(response.body)['my_current_status']['alive']
18
+ end
19
+
20
+ should 'raise an error when the invalid keyword is given to `my_current_status`' do
21
+ giraffi = Giraffi.new
22
+ assert_raise StandardError do
23
+ giraffi.my_current_status('foo')
24
+ end
25
+ end
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+
3
+ class RegionsTest < Test::Unit::TestCase
4
+ context "Testing Giraffi Ruby Gem for the Giraffi RESTful" do
5
+
6
+ context 'about the API related to the regions' do
7
+ should 'return all the valid regions' do
8
+ stub_request(:get, "#{Giraffi.endpoint}/regions.json?apikey=#{apikey}").
9
+ with(headers: Giraffi.request_headers).
10
+ to_return(body: fixture('find_regions.json'))
11
+
12
+ giraffi = Giraffi.new({apikey: apikey})
13
+ response = giraffi.find_regions
14
+ assert response.ok?
15
+ assert_equal JSON.parse(response.body)[0]['region']['code'], "JP"
16
+ end
17
+ end
18
+
19
+ end
20
+ end