giraffi 0.1.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/.document +5 -0
- data/.yardopts +7 -0
- data/Gemfile +10 -0
- data/HISTORY.md +6 -0
- data/LICENSE.md +20 -0
- data/README.md +114 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/examples/setup_http_monitoring.rb +88 -0
- data/giraffi.gemspec +155 -0
- data/lib/giraffi/client/applogs.rb +25 -0
- data/lib/giraffi/client/axions.rb +96 -0
- data/lib/giraffi/client/items.rb +102 -0
- data/lib/giraffi/client/logs.rb +23 -0
- data/lib/giraffi/client/media.rb +67 -0
- data/lib/giraffi/client/monitoringdata.rb +25 -0
- data/lib/giraffi/client/my_current_status.rb +19 -0
- data/lib/giraffi/client/regions.rb +15 -0
- data/lib/giraffi/client/services.rb +97 -0
- data/lib/giraffi/client/trends.rb +25 -0
- data/lib/giraffi/client/triggers.rb +94 -0
- data/lib/giraffi/client.rb +73 -0
- data/lib/giraffi/config.rb +60 -0
- data/lib/giraffi/version.rb +3 -0
- data/lib/giraffi.rb +26 -0
- data/test/applogs_test.rb +55 -0
- data/test/axions_test.rb +149 -0
- data/test/client_test.rb +52 -0
- data/test/fixtures/add_applogs_success_response.json +3 -0
- data/test/fixtures/add_monitroingdata.json +1 -0
- data/test/fixtures/add_service_to_item.json +12 -0
- data/test/fixtures/add_trigger_to_service.json +1 -0
- data/test/fixtures/create_axion.json +1 -0
- data/test/fixtures/create_item.json +15 -0
- data/test/fixtures/create_medium.json +1 -0
- data/test/fixtures/find_applogs_with_no_param.json +11 -0
- data/test/fixtures/find_applogs_with_params.json +2 -0
- data/test/fixtures/find_average_trends.json +6 -0
- data/test/fixtures/find_axion_by_id.json +9 -0
- data/test/fixtures/find_axion_by_trigger.json +11 -0
- data/test/fixtures/find_axion_logs_with_no_param.json +6 -0
- data/test/fixtures/find_axion_logs_with_params.json +5 -0
- data/test/fixtures/find_axions_by_trigger_with_axionkind.json +1 -0
- data/test/fixtures/find_axions_by_trigger_without_axionkind.json +1 -0
- data/test/fixtures/find_axions_with_no_param.json +1 -0
- data/test/fixtures/find_axions_with_params.json +11 -0
- data/test/fixtures/find_failure_trends.json +1 -0
- data/test/fixtures/find_item_by_id.json +15 -0
- data/test/fixtures/find_items_with_no_param.json +77 -0
- data/test/fixtures/find_items_with_params.json +17 -0
- data/test/fixtures/find_media_by_axion.json +13 -0
- data/test/fixtures/find_media_with_no_param.json +22 -0
- data/test/fixtures/find_media_with_params.json +1 -0
- data/test/fixtures/find_medium_by_id.json +1 -0
- data/test/fixtures/find_monitoringdata_with_no_param.json +4 -0
- data/test/fixtures/find_monitoringdata_with_params.json +3 -0
- data/test/fixtures/find_region_by_service.json +1 -0
- data/test/fixtures/find_regions.json +1 -0
- data/test/fixtures/find_service_by_id.json +12 -0
- data/test/fixtures/find_service_by_item_with_params.json +14 -0
- data/test/fixtures/find_services_by_item_with_no_param.json +14 -0
- data/test/fixtures/find_services_with_no_param.json +38 -0
- data/test/fixtures/find_services_with_params.json +14 -0
- data/test/fixtures/find_trigger_by_id.json +12 -0
- data/test/fixtures/find_triggers_by_service.json +1 -0
- data/test/fixtures/find_triggers_with_no_param.json +34 -0
- data/test/fixtures/find_triggers_with_params.json +14 -0
- data/test/fixtures/my_current_status_about_fake_uri.json +6 -0
- data/test/fixtures/my_current_status_about_real_uri.json +6 -0
- data/test/giraffi_test.rb +14 -0
- data/test/items_test.rb +170 -0
- data/test/logs_test.rb +60 -0
- data/test/media_test.rb +104 -0
- data/test/monitoringdata_test.rb +53 -0
- data/test/my_current_status_test.rb +29 -0
- data/test/regions_test.rb +20 -0
- data/test/services_test.rb +166 -0
- data/test/test_helper.rb +40 -0
- data/test/trends_test.rb +35 -0
- data/test/triggers_test.rb +151 -0
- metadata +271 -0
@@ -0,0 +1,102 @@
|
|
1
|
+
module Giraffi
|
2
|
+
class Client
|
3
|
+
# Defines methods related to the items
|
4
|
+
|
5
|
+
module Items
|
6
|
+
# Returns the desired items
|
7
|
+
#
|
8
|
+
# @requires_apikey Yes
|
9
|
+
# @param options [Hash] The request params to retrieve the desired items
|
10
|
+
# @return [HTTParty::Response]
|
11
|
+
def find_items(options={})
|
12
|
+
self.class.get("/items.json?apikey=#{apikey}", :query => options)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns the desired item by the numerical ID
|
16
|
+
#
|
17
|
+
# @requires_apikey Yes
|
18
|
+
# @param id [String] The numerical ID of the desired item
|
19
|
+
# @return [HTTParty::Response]
|
20
|
+
def find_item(id)
|
21
|
+
self.class.get("/items/#{id}.json?apikey=#{apikey}")
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns the desired agent related to the item
|
25
|
+
#
|
26
|
+
# @requires_apikey Yes
|
27
|
+
# @param id [String] The numerical ID of the desired item
|
28
|
+
# @return [HTTParty::Response]
|
29
|
+
def find_agent(id)
|
30
|
+
# TODO
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns all services related to the item
|
34
|
+
#
|
35
|
+
# @requires_apikey Yes
|
36
|
+
# @param id [String] The numerical ID of the item
|
37
|
+
# @param options [Hash] A set of params to retrieve services related the item
|
38
|
+
# @return [HTTParty::Response]
|
39
|
+
def find_services_by_item(id, options={})
|
40
|
+
self.class.get("/items/#{id}/services.json?apikey=#{apikey}", :query => options)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Creates a new item
|
44
|
+
#
|
45
|
+
# @requires_apikey Yes
|
46
|
+
# @param options [Hash] A set of attributes to create a new item
|
47
|
+
# @return [HTTParty::Response]
|
48
|
+
def create_item(options={})
|
49
|
+
self.class.post("/items.json?apikey=#{apikey}", :query => { :item => options })
|
50
|
+
end
|
51
|
+
|
52
|
+
# Reloads all items
|
53
|
+
#
|
54
|
+
# @requires_apikey Yes
|
55
|
+
# @return [HTTParty::Response]
|
56
|
+
def reload_items
|
57
|
+
self.class.post("/items/reload.json?apikey=#{apikey}")
|
58
|
+
end
|
59
|
+
|
60
|
+
# Adds a service to the item
|
61
|
+
#
|
62
|
+
# @requires_apikey Yes
|
63
|
+
# @param id [String] The numerical ID of the related item
|
64
|
+
# @param options [Hash] A set of attributes for a service to add to the item
|
65
|
+
# @return [HTTParty::Response]
|
66
|
+
def add_service_to_item(id, options={})
|
67
|
+
self.class.post("/items/#{id}/services.json?apikey=#{apikey}", :query => { :service => options })
|
68
|
+
end
|
69
|
+
|
70
|
+
# Updates the desired item
|
71
|
+
#
|
72
|
+
# @requires_apikey Yes
|
73
|
+
# @param id [String] The numerical ID of the desired item
|
74
|
+
# @param options [Hash] A set of attributes to update the item
|
75
|
+
# @return [HTTParty::Response]
|
76
|
+
def update_item(id, options={})
|
77
|
+
self.class.put("/items/#{id}.json?apikey=#{apikey}", :query => {:item => options}, :body => {})
|
78
|
+
end
|
79
|
+
|
80
|
+
# Deletes the item
|
81
|
+
#
|
82
|
+
# @requires_apikey Yes
|
83
|
+
# @param id [String] The numerical ID of the desired item
|
84
|
+
# @return [HTTParty::Response]
|
85
|
+
def destroy_item(id)
|
86
|
+
self.class.delete("/items/#{id}.json?apikey=#{apikey}")
|
87
|
+
end
|
88
|
+
|
89
|
+
# Removes a service from the item
|
90
|
+
#
|
91
|
+
# @requires_apikey Yes
|
92
|
+
# @param args [Array] A set of params to remove a service from the item
|
93
|
+
# @option args [String] The numerical ID of the related item
|
94
|
+
# @option args [String] The numerical ID of the service to remove
|
95
|
+
# @return [HTTParty::Response]
|
96
|
+
def remove_service_from_item(*args)
|
97
|
+
raise ArgumentError.new('The method `remove_service_from_item` requires 2 arguments (item-id and service-id)') if args.size != 2
|
98
|
+
self.class.delete("/items/#{args[0]}/services/#{args[-1]}.json?apikey=#{apikey}")
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Giraffi
|
2
|
+
class Client
|
3
|
+
# Defines methods related to the logs generated by the Giraffi
|
4
|
+
|
5
|
+
module Logs
|
6
|
+
# Returns the desired logs related to the axions
|
7
|
+
#
|
8
|
+
# @param options [Hash] The request params to retrieve the desired logs
|
9
|
+
# @return [HTTParty::Response]
|
10
|
+
def find_axion_logs(options={})
|
11
|
+
self.class.get("/logs/axion.json?apikey=#{apikey}", query: options)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns the number of logs related to the axions
|
15
|
+
#
|
16
|
+
# @param options [Hash] The request params to retrieve the desired logs to count
|
17
|
+
# @return [HTTParty::Response]
|
18
|
+
def count_axion_logs(options={})
|
19
|
+
self.class.get("/logs/axion/count.json?apikey=#{apikey}", query: options)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Giraffi
|
2
|
+
class Client
|
3
|
+
# Defines methods related to the media
|
4
|
+
|
5
|
+
module Media
|
6
|
+
# Returns the desired media
|
7
|
+
#
|
8
|
+
# @param options [Hash] The request params to retrieve the desired media
|
9
|
+
# @return [HTTParty::Response]
|
10
|
+
def find_media(options={})
|
11
|
+
self.class.get("/media.json?apikey=#{apikey}", :query => options)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns the desired medium
|
15
|
+
#
|
16
|
+
# @param id [String] The numerical ID of the desired medium
|
17
|
+
# @return [HTTParty::Response]
|
18
|
+
def find_medium(id)
|
19
|
+
self.class.get("/media/#{id}.json?apikey=#{apikey}")
|
20
|
+
end
|
21
|
+
|
22
|
+
# Returns the desired oauth
|
23
|
+
#
|
24
|
+
# @param id [String] The numerical ID of the desired medium
|
25
|
+
# @return [HTTParty::Response]
|
26
|
+
def find_oauth_by_medium(id)
|
27
|
+
self.class.get("/media/#{id}/oauth.json?apikey=#{apikey}")
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns the oauth-callbacks related to the medium
|
31
|
+
#
|
32
|
+
# @param args [Array] A set of params to retrieve the desired oauth-callback
|
33
|
+
# @option args [String] The numerical ID of the desired medium
|
34
|
+
# @option args [String] The oauth verifier related to the callback
|
35
|
+
# @return [HTTParty::Response]
|
36
|
+
def find_oauth_callback_by_medium(*args)
|
37
|
+
raise ArgumentError.new('The method `find_oauth_callback_by_medium` requires 2 arguments(medium-id and oauth-token)') if args.size != 2
|
38
|
+
self.class.get("/media/#{args[0]}/oauth_callback.json?apikey=#{apikey}", :query => {:oauth_verifier => args[-1]})
|
39
|
+
end
|
40
|
+
|
41
|
+
# Creates a new medium
|
42
|
+
#
|
43
|
+
# @param options [Hash] A set of attributes to create a new medium
|
44
|
+
# @return [HTTParty::Response]
|
45
|
+
def create_medium(options={})
|
46
|
+
self.class.post("/media.json?apikey=#{apikey}", :query => { :medium => options })
|
47
|
+
end
|
48
|
+
|
49
|
+
# Updates the desired medium
|
50
|
+
#
|
51
|
+
# @param id [String] The numerical ID of the desired medium
|
52
|
+
# @param options [Hash] A set of attributes to update the medium
|
53
|
+
# @return [HTTParty::Response]
|
54
|
+
def update_medium(id, options={})
|
55
|
+
self.class.put("/media/#{id}.json?apikey=#{apikey}", :query => {:medium => options}, :body => {})
|
56
|
+
end
|
57
|
+
|
58
|
+
# Deletes the medium
|
59
|
+
#
|
60
|
+
# @param id [String] The numerical ID of the desired medium
|
61
|
+
# @return [HTTParty::Response]
|
62
|
+
def destroy_medium(id)
|
63
|
+
self.class.delete("/media/#{id}?apikey=#{apikey}")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Giraffi
|
2
|
+
class Client
|
3
|
+
# Defines methods related to the monitoring data
|
4
|
+
|
5
|
+
module Monitoringdata
|
6
|
+
# Returns the desired monitoring data
|
7
|
+
#
|
8
|
+
# @requires_apikey Yes
|
9
|
+
# @param options [Hash] The request params to retrieve the desired monitoring data
|
10
|
+
# @return [HTTParty::Response]
|
11
|
+
def find_monitoringdata(options={})
|
12
|
+
self.class.get("/monitoringdata.json?apikey=#{apikey}", query: options)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Posts the monitoring data to the Giraffi
|
16
|
+
#
|
17
|
+
# @requires_apikey Yes
|
18
|
+
# @param options [Hash] The monitoring data to post to the Giraffi
|
19
|
+
# @return [HTTParty::Response]
|
20
|
+
def add_monitoringdata(options={})
|
21
|
+
self.class.post("#{monitoringdata_endpoint}/internal/nodelayed?apikey=#{apikey}", :body => MultiJson.encode({:internal => options}))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Giraffi
|
2
|
+
class Client
|
3
|
+
# Defines methods related to the status of endpoints
|
4
|
+
|
5
|
+
module MyCurrentStatus
|
6
|
+
# Returns the current status of the desired endpoint
|
7
|
+
#
|
8
|
+
# @requires_apikey No
|
9
|
+
# @param options [String] The alias string of the desired endpoint
|
10
|
+
# @return [HTTParty::Response]
|
11
|
+
def my_current_status(options="")
|
12
|
+
uri = to_uri options.to_sym
|
13
|
+
raise StandardError.new("The given key `#{options}` is not valid.") if uri.nil?
|
14
|
+
self.class.get("#{uri}/my_current_status.json")
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Giraffi
|
2
|
+
class Client
|
3
|
+
# Defines methods related to the regions
|
4
|
+
|
5
|
+
module Regions
|
6
|
+
# Returns all available regions
|
7
|
+
#
|
8
|
+
# @requires_apikey Yes
|
9
|
+
# @return [HTTParty::Response]
|
10
|
+
def find_regions
|
11
|
+
self.class.get("/regions.json?apikey=#{apikey}")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module Giraffi
|
2
|
+
class Client
|
3
|
+
# Defines methods related to the services
|
4
|
+
|
5
|
+
module Services
|
6
|
+
# Returns the desired services
|
7
|
+
#
|
8
|
+
# @requires_apikey Yes
|
9
|
+
# @param options [Hash] The request params to retrieve the desired services
|
10
|
+
# @return [HTTParty::Response]
|
11
|
+
def find_services(options={})
|
12
|
+
self.class.get("/services.json?apikey=#{apikey}", :query => options)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns the desired service
|
16
|
+
#
|
17
|
+
# @requires_apikey Yes
|
18
|
+
# @param id [String] The numerical ID of the desired service
|
19
|
+
# @return [HTTParty::Response]
|
20
|
+
def find_service(id)
|
21
|
+
self.class.get("/services/#{id}.json?apikey=#{apikey}")
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns the region related to the desired service
|
25
|
+
#
|
26
|
+
# @requires_apikey Yes
|
27
|
+
# @param id [String] The numerical ID of the desired service
|
28
|
+
# @return [HTTParty::Response]
|
29
|
+
def find_region_by_service(id)
|
30
|
+
self.class.get("/services/#{id}/regions.json?apikey=#{apikey}")
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns all triggers related to the desired service
|
34
|
+
#
|
35
|
+
# @requires_apikey Yes
|
36
|
+
# @param id [String] The numerical ID of the desired service
|
37
|
+
# @return [HTTParty::Response]
|
38
|
+
def find_triggers_by_service(id)
|
39
|
+
self.class.get("/services/#{id}/triggers.json?apikey=#{apikey}")
|
40
|
+
end
|
41
|
+
|
42
|
+
# Adds a trigger to the service
|
43
|
+
#
|
44
|
+
# @requires_apikey Yes
|
45
|
+
# @param id [String] The numerical ID of the related service
|
46
|
+
# @param options [Hash] A set of attributes for a trigger to add to the service
|
47
|
+
# @return [HTTParty::Response]
|
48
|
+
def add_trigger_to_service(id, options={})
|
49
|
+
self.class.post("/services/#{id}/triggers.json?apikey=#{apikey}", :query => {:trigger => options})
|
50
|
+
end
|
51
|
+
|
52
|
+
# Updates the desired service
|
53
|
+
#
|
54
|
+
# @requires_apikey Yes
|
55
|
+
# @param id [String] The numerical ID of the desired service
|
56
|
+
# @param options [Hash] A set of attributes to update the service
|
57
|
+
# @return [HTTParty::Response]
|
58
|
+
def update_service(id, options={})
|
59
|
+
self.class.put("/services/#{id}.json?apikey=#{apikey}", :query => {:service => options}, :body => {})
|
60
|
+
end
|
61
|
+
|
62
|
+
# Updates the region related to the service
|
63
|
+
#
|
64
|
+
# @requires_apikey Yes
|
65
|
+
# @param args [Array] A set of params to update the region
|
66
|
+
# @option args [String] The numerical ID of the related service
|
67
|
+
# @option args [String] The region code(e.g JP) to update
|
68
|
+
# @return [HTTParty::Response]
|
69
|
+
def update_region_of_service(*args)
|
70
|
+
raise ArgumentError.new('The method `update_region_of_service` requires 2 arguments (service-id and region-code).') if args.size != 2
|
71
|
+
self.class.put("/services/#{args[0]}/regions/#{args[-1]}.json?apikey=#{apikey}", :body => {})
|
72
|
+
end
|
73
|
+
|
74
|
+
# Deletes the service
|
75
|
+
#
|
76
|
+
# @requires_apikey Yes
|
77
|
+
# @param id [String] The numerical ID of the desired service
|
78
|
+
# @return [HTTParty::Response]
|
79
|
+
def destroy_service(id)
|
80
|
+
self.class.delete("/services/#{id}.json?apikey=#{apikey}")
|
81
|
+
end
|
82
|
+
|
83
|
+
# Removes a trigger from the service
|
84
|
+
#
|
85
|
+
# @requires_apikey Yes
|
86
|
+
# @param args [Array] A set of params to remove a trigger from the service
|
87
|
+
# @option args [String] The numerical ID of the related service
|
88
|
+
# @option args [String] The numerical ID of the trigger to remove
|
89
|
+
# @return [HTTParty::Response]
|
90
|
+
def remove_trigger_from_service(*args)
|
91
|
+
raise ArgumentError.new('The method `remove_trigger_from_service` requires 2 arguments (service-id and trigger-id).') if args.size != 2
|
92
|
+
self.class.delete("/services/#{args[0]}/triggers/#{args[-1]}.json?apikey=#{apikey}")
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Giraffi
|
2
|
+
class Client
|
3
|
+
# Defines methods related to the trend data
|
4
|
+
|
5
|
+
module Trends
|
6
|
+
# Returns the desired trend data(average)
|
7
|
+
#
|
8
|
+
# @requires_apikey Yes
|
9
|
+
# @param options [Hash] The request params to retrieve the desired trend data(average)
|
10
|
+
# @return [HTTParty::Response]
|
11
|
+
def find_average_trends(options={})
|
12
|
+
self.class.get("/trends/average.json?apikey=#{apikey}", query: options)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns the desired trend data(failure)
|
16
|
+
#
|
17
|
+
# @requires_apikey Yes
|
18
|
+
# @param options [Hash] The request params to retrieve the desired trend data(failure)
|
19
|
+
# @return [HTTParty::Response]
|
20
|
+
def find_failure_trends(options={})
|
21
|
+
self.class.get("/trends/failure.json?apikey=#{apikey}", query: options)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Giraffi
|
2
|
+
class Client
|
3
|
+
# Defines methods related to the triggers
|
4
|
+
|
5
|
+
module Triggers
|
6
|
+
# Returns the desired trigger
|
7
|
+
#
|
8
|
+
# @requires_apikey Yes
|
9
|
+
# @param options [Hash] The request params to retrieve the desired triggers
|
10
|
+
# @return [HTTParty::Response]
|
11
|
+
def find_triggers(options={})
|
12
|
+
self.class.get("/triggers.json?apikey=#{apikey}", :query => options)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns the desired trigger
|
16
|
+
#
|
17
|
+
# @requires_apikey Yes
|
18
|
+
# @param id [String] The numerical ID of the desired trigger
|
19
|
+
# @return [HTTParty::Response]
|
20
|
+
def find_trigger(id)
|
21
|
+
self.class.get("/triggers/#{id}.json?apikey=#{apikey}")
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns all axions related to the desired trigger
|
25
|
+
#
|
26
|
+
# @requires_apikey Yes
|
27
|
+
# @param args [Array] A set of params to retrieve axions related to the trigger
|
28
|
+
# @option args [String] The numerical ID of the related trigger
|
29
|
+
# @option args [String] The kind of axion [problem, recovery] to retrieve
|
30
|
+
# @return [HTTParty::Response]
|
31
|
+
def find_axions_by_trigger(*args)
|
32
|
+
raise ArgumentError.new('The method `find_axions_by_trigger` requires at least a trigger id.') if args.size.zero?
|
33
|
+
if args.size == 1
|
34
|
+
self.class.get("/triggers/#{args[0]}/axions.json?apikey=#{apikey}")
|
35
|
+
else
|
36
|
+
self.class.get("/triggers/#{args[0]}/axions.json?apikey=#{apikey}", :query => {:axionkind => args[-1]})
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Executes all axions related to the desired trigger
|
41
|
+
#
|
42
|
+
# @requires_apikey Yes
|
43
|
+
# @param id [String] The numerical ID of the desired trigger
|
44
|
+
# @return [HTTParty::Response]
|
45
|
+
def execute_axions_by_trigger(id)
|
46
|
+
self.class.post("/triggers/#{id}/axions/execute.json?apikey=#{apikey}")
|
47
|
+
end
|
48
|
+
|
49
|
+
# Updates the desired trigger
|
50
|
+
#
|
51
|
+
# @requires_apikey Yes
|
52
|
+
# @param id [String] The numerical ID of the desired trigger
|
53
|
+
# @param options [Hash] A set of attributes to update the trigger
|
54
|
+
# @return [HTTParty::Response]
|
55
|
+
def update_trigger(id, options={})
|
56
|
+
self.class.put("/triggers/#{id}.json?apikey=#{apikey}", :query => {:trigger => options}, :body => {})
|
57
|
+
end
|
58
|
+
|
59
|
+
# Updates the axion related to the desired trigger
|
60
|
+
#
|
61
|
+
# @requires_apikey Yes
|
62
|
+
# @param args [Array] A set of parmas to update the axion related to the trigger
|
63
|
+
# @option args [String] The numerical ID of the related trigger
|
64
|
+
# @option args [String] The numerical ID of the desired axion
|
65
|
+
# @option args [String] The kind of axion [problem, recovery] to update
|
66
|
+
# @return [HTTParty::Response]
|
67
|
+
def update_axion_of_trigger(*args)
|
68
|
+
raise ArgumentError.new('The method `update_axion_by_trigger` requires 3 argments (trigger-id, axion-id and axion-kind)') if args.size != 3
|
69
|
+
self.class.put("/triggers/#{args[0]}/axions/#{args[1]}.json?apikey=#{apikey}", :query => { :axionkind => args[-1] }, :body => {})
|
70
|
+
end
|
71
|
+
|
72
|
+
# Deletes the trigger
|
73
|
+
#
|
74
|
+
# @requires_apikey Yes
|
75
|
+
# @param id [String] The numerical ID of the desired trigger
|
76
|
+
# @return [HTTParty::Response]
|
77
|
+
def destroy_trigger(id)
|
78
|
+
self.class.delete("/triggers/#{id}.json?apikey=#{apikey}")
|
79
|
+
end
|
80
|
+
|
81
|
+
# Removes an axion from the trigger
|
82
|
+
#
|
83
|
+
# @requires_apikey Yes
|
84
|
+
# @param args [Array] A set of parmas to remove an axion from the trigger
|
85
|
+
# @option args [String] The numerical ID of the related trigger
|
86
|
+
# @option args [String] The numerical ID of the axion to remove
|
87
|
+
# @return [HTTParty::Response]
|
88
|
+
def remove_axion_from_trigger(*args)
|
89
|
+
raise ArgumentError.new('The method `remove_axion_from_trigger` requires 2 arguments (trigger-id and axion-id)') if args.size != 2
|
90
|
+
self.class.delete("/triggers/#{args[0]}/axions/#{args[-1]}.json?apikey=#{apikey}")
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'multi_json'
|
3
|
+
require 'giraffi/config'
|
4
|
+
|
5
|
+
module Giraffi
|
6
|
+
# Warpper for the Giraffi RESTful API
|
7
|
+
|
8
|
+
class Client
|
9
|
+
include MultiJson
|
10
|
+
include HTTParty
|
11
|
+
base_uri Config::DEFAULT_ENDPOINT
|
12
|
+
headers Config::DEFAULT_REQUEST_HEADERS
|
13
|
+
format :plain #:json
|
14
|
+
#debug_output
|
15
|
+
|
16
|
+
# Requires client method modules
|
17
|
+
require 'giraffi/client/items'
|
18
|
+
require 'giraffi/client/services'
|
19
|
+
require 'giraffi/client/media'
|
20
|
+
require 'giraffi/client/axions'
|
21
|
+
require 'giraffi/client/applogs'
|
22
|
+
require 'giraffi/client/logs'
|
23
|
+
require 'giraffi/client/monitoringdata'
|
24
|
+
require 'giraffi/client/my_current_status'
|
25
|
+
require 'giraffi/client/regions'
|
26
|
+
require 'giraffi/client/trends'
|
27
|
+
require 'giraffi/client/triggers'
|
28
|
+
|
29
|
+
include Giraffi::Client::Items
|
30
|
+
include Giraffi::Client::Services
|
31
|
+
include Giraffi::Client::Media
|
32
|
+
include Giraffi::Client::Axions
|
33
|
+
include Giraffi::Client::Applogs
|
34
|
+
include Giraffi::Client::Logs
|
35
|
+
include Giraffi::Client::Monitoringdata
|
36
|
+
include Giraffi::Client::MyCurrentStatus
|
37
|
+
include Giraffi::Client::Regions
|
38
|
+
include Giraffi::Client::Trends
|
39
|
+
include Giraffi::Client::Triggers
|
40
|
+
|
41
|
+
# @return [Array] the attributes +Config::VALID_OPTIONS_KEYS+ as a Array
|
42
|
+
attr_accessor *Config::VALID_OPTIONS_KEYS
|
43
|
+
|
44
|
+
# Examines a bad response and raise an appropriate error
|
45
|
+
#
|
46
|
+
# @param response [HTTParty::Response]
|
47
|
+
def bad_response(response)
|
48
|
+
if response.class == HTTParty::Response
|
49
|
+
raise ResponseError, response
|
50
|
+
end
|
51
|
+
raise StandardError, "Unknown error"
|
52
|
+
end
|
53
|
+
|
54
|
+
# Initializes a new API object
|
55
|
+
#
|
56
|
+
# @param attrs [Hash] The options allows you to access the Giraffi RESTful API
|
57
|
+
# @return [Giraffi::Client]
|
58
|
+
def initialize(attrs={})
|
59
|
+
attrs = Giraffi.options.merge(attrs)
|
60
|
+
Config::VALID_OPTIONS_KEYS.each do |key|
|
61
|
+
instance_variable_set("@#{key}".to_sym, attrs[key])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Returns the URL related to the given key
|
66
|
+
#
|
67
|
+
# @param options [Symbol] The keyword related to the real URI
|
68
|
+
# @return [String] URI or nil when no matching value
|
69
|
+
def to_uri(key)
|
70
|
+
{papi: endpoint,okapi: monitoringdata_endpoint,lapi: applogs_endpoint}[key] || nil
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'giraffi/version'
|
2
|
+
|
3
|
+
module Giraffi
|
4
|
+
# Defines constants and methods related to configuration
|
5
|
+
module Config
|
6
|
+
|
7
|
+
# The HTTP request header if none is set
|
8
|
+
DEFAULT_REQUEST_HEADERS = {
|
9
|
+
"User-Agent" => "Giraffi Ruby Gem #{Giraffi::Version}",
|
10
|
+
"Accept" => "application/json",
|
11
|
+
"Content-Type" => "application/json"
|
12
|
+
}
|
13
|
+
|
14
|
+
# The basic endpoint if none is set
|
15
|
+
DEFAULT_ENDPOINT = 'https://papi.giraffi.jp'
|
16
|
+
|
17
|
+
# The endpoint for posting the monitoringdata if none is set
|
18
|
+
DEFAULT_MONITORINGDATA_ENDPOINT = 'https://okapi.giraffi.jp:3007'
|
19
|
+
|
20
|
+
# The endpoint for posting the application logs if none is set
|
21
|
+
DEFAULT_APPLOGS_ENDPOINT = 'https://lapi.giraffi.jp:3443'
|
22
|
+
|
23
|
+
# The APIKEY to allow you to use the Giraffi API if none is set
|
24
|
+
DEFAULT_APIKEY = nil
|
25
|
+
|
26
|
+
# An array of valid keys in the options hash when configuring a {Giraffi::Client}
|
27
|
+
VALID_OPTIONS_KEYS = [
|
28
|
+
:request_headers,
|
29
|
+
:endpoint,
|
30
|
+
:monitoringdata_endpoint,
|
31
|
+
:applogs_endpoint,
|
32
|
+
:apikey
|
33
|
+
]
|
34
|
+
|
35
|
+
# @return [Array] the attribute +VALID_OPTIONS_KEYS+ as an Array
|
36
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
37
|
+
|
38
|
+
# Set all configuration options to thier values when this module is extended
|
39
|
+
def self.extended(base)
|
40
|
+
base.reset
|
41
|
+
end
|
42
|
+
|
43
|
+
# Create a hash of options and thier values
|
44
|
+
def options
|
45
|
+
options = {}
|
46
|
+
VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
|
47
|
+
options
|
48
|
+
end
|
49
|
+
|
50
|
+
# Reset all configuration options to defaults
|
51
|
+
def reset
|
52
|
+
self.request_headers = DEFAULT_REQUEST_HEADERS
|
53
|
+
self.endpoint = DEFAULT_ENDPOINT
|
54
|
+
self.monitoringdata_endpoint = DEFAULT_MONITORINGDATA_ENDPOINT
|
55
|
+
self.applogs_endpoint = DEFAULT_APPLOGS_ENDPOINT
|
56
|
+
self.apikey = DEFAULT_APIKEY
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
data/lib/giraffi.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
require 'giraffi/client'
|
3
|
+
require 'giraffi/config'
|
4
|
+
|
5
|
+
module Giraffi
|
6
|
+
extend Config
|
7
|
+
class << self
|
8
|
+
# Alias for Giraffi::Client.new
|
9
|
+
#
|
10
|
+
# @param options [Hash] The APIKEY allows you to access the Giraffi RESTful API
|
11
|
+
# @return [Giraffi::Client]
|
12
|
+
def new(options={})
|
13
|
+
Giraffi::Client.new(options)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Delegate to Giraffi::Client
|
17
|
+
def method_missing(method, *args, &blocks)
|
18
|
+
return super unless new.respond_to?(method)
|
19
|
+
new.send(method, *args, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def respond_to?(method, include_private=false)
|
23
|
+
new.respond_to?(method, include_private) || super(method, include_private)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|