esp_sdk 1.1.0 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -2
  3. data/.rubocop.yml +53 -6
  4. data/.ruby-version +1 -1
  5. data/.travis.yml +8 -2
  6. data/Gemfile.lock +171 -0
  7. data/Guardfile +47 -0
  8. data/README.md +230 -5
  9. data/Rakefile +14 -1
  10. data/assets/logo.png +0 -0
  11. data/bin/esp_console +71 -0
  12. data/esp_sdk.gemspec +27 -18
  13. data/lib/esp/exceptions.rb +3 -0
  14. data/lib/esp/extensions/active_resource/formats/json_api_format.rb +105 -0
  15. data/lib/esp/extensions/active_resource/paginated_collection.rb +198 -0
  16. data/lib/esp/extensions/active_resource/validations.rb +45 -0
  17. data/lib/esp/resources/alert.rb +135 -0
  18. data/lib/esp/resources/cloud_trail_event.rb +45 -0
  19. data/lib/esp/resources/concerns/stat_totals.rb +79 -0
  20. data/lib/esp/resources/contact_request.rb +42 -0
  21. data/lib/esp/resources/custom_signature.rb +224 -0
  22. data/lib/esp/resources/dashboard.rb +31 -0
  23. data/lib/esp/resources/external_account.rb +89 -0
  24. data/lib/esp/resources/organization.rb +61 -0
  25. data/lib/esp/resources/region.rb +46 -0
  26. data/lib/esp/resources/report.rb +100 -0
  27. data/lib/esp/resources/resource.rb +66 -0
  28. data/lib/esp/resources/service.rb +31 -0
  29. data/lib/esp/resources/signature.rb +106 -0
  30. data/lib/esp/resources/stat.rb +124 -0
  31. data/lib/esp/resources/stat_custom_signature.rb +121 -0
  32. data/lib/esp/resources/stat_region.rb +121 -0
  33. data/lib/esp/resources/stat_service.rb +121 -0
  34. data/lib/esp/resources/stat_signature.rb +121 -0
  35. data/lib/esp/resources/sub_organization.rb +69 -0
  36. data/lib/esp/resources/suppression/region.rb +99 -0
  37. data/lib/esp/resources/suppression/signature.rb +107 -0
  38. data/lib/esp/resources/suppression/unique_identifier.rb +60 -0
  39. data/lib/esp/resources/suppression.rb +86 -0
  40. data/lib/esp/resources/tag.rb +45 -0
  41. data/lib/esp/resources/team.rb +79 -0
  42. data/lib/esp/resources/user.rb +46 -0
  43. data/lib/esp/version.rb +3 -0
  44. data/lib/esp.rb +95 -0
  45. data/lib/esp_sdk.rb +9 -45
  46. data/lib/tasks/rubocop.rake +2 -0
  47. data/lib/tasks/testing.rake +3 -0
  48. data/rdoc/ActiveResource/Formats.html +176 -0
  49. data/rdoc/ActiveResource/PaginatedCollection.html +910 -0
  50. data/rdoc/ActiveResource.html +180 -0
  51. data/rdoc/ESP/Alert.html +771 -0
  52. data/rdoc/ESP/CloudTrailEvent.html +375 -0
  53. data/rdoc/ESP/ContactRequest.html +366 -0
  54. data/rdoc/ESP/CustomSignature.html +746 -0
  55. data/rdoc/ESP/Dashboard.html +355 -0
  56. data/rdoc/ESP/ExternalAccount.html +565 -0
  57. data/rdoc/ESP/Organization.html +590 -0
  58. data/rdoc/ESP/Region.html +399 -0
  59. data/rdoc/ESP/Report.html +622 -0
  60. data/rdoc/ESP/Service.html +380 -0
  61. data/rdoc/ESP/Signature.html +555 -0
  62. data/rdoc/ESP/Stat.html +1778 -0
  63. data/rdoc/ESP/StatCustomSignature.html +1599 -0
  64. data/rdoc/ESP/StatRegion.html +1598 -0
  65. data/rdoc/ESP/StatService.html +1598 -0
  66. data/rdoc/ESP/StatSignature.html +1598 -0
  67. data/rdoc/ESP/SubOrganization.html +540 -0
  68. data/rdoc/ESP/Suppression/Region.html +454 -0
  69. data/rdoc/ESP/Suppression/Signature.html +470 -0
  70. data/rdoc/ESP/Suppression/UniqueIdentifier.html +417 -0
  71. data/rdoc/ESP/Suppression.html +649 -0
  72. data/rdoc/ESP/Tag.html +371 -0
  73. data/rdoc/ESP/Team.html +584 -0
  74. data/rdoc/ESP/User.html +483 -0
  75. data/rdoc/ESP.html +546 -0
  76. data/rdoc/README_md.html +501 -0
  77. data/rdoc/created.rid +30 -0
  78. data/rdoc/images/add.png +0 -0
  79. data/rdoc/images/arrow_up.png +0 -0
  80. data/rdoc/images/brick.png +0 -0
  81. data/rdoc/images/brick_link.png +0 -0
  82. data/rdoc/images/bug.png +0 -0
  83. data/rdoc/images/bullet_black.png +0 -0
  84. data/rdoc/images/bullet_toggle_minus.png +0 -0
  85. data/rdoc/images/bullet_toggle_plus.png +0 -0
  86. data/rdoc/images/date.png +0 -0
  87. data/rdoc/images/delete.png +0 -0
  88. data/rdoc/images/find.png +0 -0
  89. data/rdoc/images/loadingAnimation.gif +0 -0
  90. data/rdoc/images/macFFBgHack.png +0 -0
  91. data/rdoc/images/package.png +0 -0
  92. data/rdoc/images/page_green.png +0 -0
  93. data/rdoc/images/page_white_text.png +0 -0
  94. data/rdoc/images/page_white_width.png +0 -0
  95. data/rdoc/images/plugin.png +0 -0
  96. data/rdoc/images/ruby.png +0 -0
  97. data/rdoc/images/tag_blue.png +0 -0
  98. data/rdoc/images/tag_green.png +0 -0
  99. data/rdoc/images/transparent.png +0 -0
  100. data/rdoc/images/wrench.png +0 -0
  101. data/rdoc/images/wrench_orange.png +0 -0
  102. data/rdoc/images/zoom.png +0 -0
  103. data/rdoc/index.html +134 -0
  104. data/rdoc/js/darkfish.js +155 -0
  105. data/rdoc/js/jquery.js +4 -0
  106. data/rdoc/js/navigation.js +142 -0
  107. data/rdoc/js/search.js +94 -0
  108. data/rdoc/js/search_index.js +1 -0
  109. data/rdoc/js/searcher.js +228 -0
  110. data/rdoc/rdoc.css +595 -0
  111. data/rdoc/table_of_contents.html +927 -0
  112. data/test/esp/extensions/active_resource/formats/json_api_format_test.rb +109 -0
  113. data/test/esp/extensions/active_resource/paginated_collection_test.rb +435 -0
  114. data/test/esp/extensions/active_resource/validations_test.rb +59 -0
  115. data/test/esp/resources/alert_test.rb +263 -0
  116. data/test/esp/resources/cloud_trail_event_test.rb +98 -0
  117. data/test/esp/resources/contact_request_test.rb +73 -0
  118. data/test/esp/resources/custom_signature_test.rb +241 -0
  119. data/test/esp/resources/dashboard_test.rb +71 -0
  120. data/test/esp/resources/external_account_test.rb +125 -0
  121. data/test/esp/resources/organization_test.rb +175 -0
  122. data/test/esp/resources/region_test.rb +84 -0
  123. data/test/esp/resources/report_test.rb +180 -0
  124. data/test/esp/resources/resource_test.rb +183 -0
  125. data/test/esp/resources/service_test.rb +64 -0
  126. data/test/esp/resources/signature_test.rb +177 -0
  127. data/test/esp/resources/stat_custom_signature_test.rb +115 -0
  128. data/test/esp/resources/stat_region_test.rb +114 -0
  129. data/test/esp/resources/stat_service_test.rb +114 -0
  130. data/test/esp/resources/stat_signature_test.rb +115 -0
  131. data/test/esp/resources/stat_test.rb +159 -0
  132. data/test/esp/resources/sub_organization_test.rb +127 -0
  133. data/test/esp/resources/suppression/region_test.rb +115 -0
  134. data/test/esp/resources/suppression/signature_test.rb +117 -0
  135. data/test/esp/resources/suppression/unique_identifier_test.rb +79 -0
  136. data/test/esp/resources/suppression_test.rb +226 -0
  137. data/test/esp/resources/tag_test.rb +98 -0
  138. data/test/esp/resources/team_test.rb +140 -0
  139. data/test/esp/resources/user_test.rb +113 -0
  140. data/test/esp_test.rb +139 -0
  141. data/test/factories/alerts.rb +234 -0
  142. data/test/factories/cloud_trail_events.rb +16 -0
  143. data/test/factories/contact_requests.rb +14 -0
  144. data/test/factories/custom_signatures.rb +30 -0
  145. data/test/factories/dashboards.rb +91 -0
  146. data/test/factories/errors.rb +24 -0
  147. data/test/factories/external_accounts.rb +44 -0
  148. data/test/factories/organizations.rb +48 -0
  149. data/test/factories/regions.rb +9 -0
  150. data/test/factories/reports.rb +56 -0
  151. data/test/factories/services.rb +12 -0
  152. data/test/factories/signatures.rb +28 -0
  153. data/test/factories/stat_custom_signatures.rb +97 -0
  154. data/test/factories/stat_regions.rb +97 -0
  155. data/test/factories/stat_services.rb +97 -0
  156. data/test/factories/stat_signautures.rb +97 -0
  157. data/test/factories/stats.rb +129 -0
  158. data/test/factories/sub_organizations.rb +34 -0
  159. data/test/factories/suppression/regions.rb +90 -0
  160. data/test/factories/suppression/signatures.rb +117 -0
  161. data/test/factories/suppression/unique_identifiers.rb +111 -0
  162. data/test/factories/suppressions.rb +71 -0
  163. data/test/factories/tags.rb +12 -0
  164. data/test/factories/teams.rb +32 -0
  165. data/test/factories/users.rb +54 -0
  166. data/test/json_strategy.rb +25 -0
  167. data/test/test_helper.rb +44 -5
  168. metadata +387 -119
  169. data/bin/esp_repl +0 -60
  170. data/lib/esp_sdk/api.rb +0 -33
  171. data/lib/esp_sdk/client.rb +0 -62
  172. data/lib/esp_sdk/configure.rb +0 -40
  173. data/lib/esp_sdk/end_points/base.rb +0 -102
  174. data/lib/esp_sdk/end_points/contact_requests.rb +0 -6
  175. data/lib/esp_sdk/end_points/custom_signatures.rb +0 -41
  176. data/lib/esp_sdk/end_points/dashboard.rb +0 -35
  177. data/lib/esp_sdk/end_points/external_accounts.rb +0 -9
  178. data/lib/esp_sdk/end_points/organizations.rb +0 -6
  179. data/lib/esp_sdk/end_points/reports.rb +0 -6
  180. data/lib/esp_sdk/end_points/services.rb +0 -6
  181. data/lib/esp_sdk/end_points/signatures.rb +0 -39
  182. data/lib/esp_sdk/end_points/sub_organizations.rb +0 -6
  183. data/lib/esp_sdk/end_points/teams.rb +0 -6
  184. data/lib/esp_sdk/end_points/users.rb +0 -6
  185. data/lib/esp_sdk/exceptions.rb +0 -8
  186. data/lib/esp_sdk/extensions/rest_client/request.rb +0 -9
  187. data/lib/esp_sdk/repl.rb +0 -61
  188. data/lib/esp_sdk/version.rb +0 -3
  189. data/test/esp_sdk/api_test.rb +0 -36
  190. data/test/esp_sdk/client_test.rb +0 -129
  191. data/test/esp_sdk/configure_test.rb +0 -65
  192. data/test/esp_sdk/end_points/.keep +0 -0
  193. data/test/esp_sdk/end_points/base_test.rb +0 -230
  194. data/test/esp_sdk/end_points/custom_signatures_test.rb +0 -90
  195. data/test/esp_sdk/end_points/dashboard_test.rb +0 -55
  196. data/test/esp_sdk/end_points/external_accounts_test.rb +0 -20
  197. data/test/esp_sdk/end_points/signatures_test.rb +0 -83
  198. data/test/esp_sdk/exceptions_test.rb +0 -41
  199. data/test/esp_sdk_test.rb +0 -70
@@ -0,0 +1,66 @@
1
+ module ESP
2
+ class Resource < ActiveResource::Base # :nodoc:
3
+ self.site = ESP.site
4
+ self.format = ActiveResource::Formats::JsonAPIFormat
5
+ with_api_auth(ESP.access_key_id, ESP.secret_access_key)
6
+ headers["Content-Type"] = format.mime_type
7
+
8
+ self.collection_parser = ActiveResource::PaginatedCollection
9
+
10
+ def self.where(*)
11
+ fail ESP::NotImplementedError
12
+ end
13
+
14
+ # Pass a json api compliant hash to the api.
15
+ def serializable_hash(*)
16
+ h = attributes.extract!('included')
17
+ h['data'] = { 'type' => self.class.to_s.underscore.sub('esp/', '').pluralize,
18
+ 'attributes' => attributes.except('id', 'type', 'created_at', 'updated_at', 'relationships') }
19
+ h['data']['id'] = id if id.present?
20
+ h
21
+ end
22
+
23
+ def self.find(*arguments)
24
+ scope = arguments.slice!(0)
25
+ options = (arguments.slice!(0) || {}).with_indifferent_access
26
+ arrange_options(options)
27
+ super(scope, options).tap do |object|
28
+ make_pageable object, options
29
+ end
30
+ end
31
+
32
+ def self.filters(params)
33
+ h = {}.tap do |filters|
34
+ params.each do |attr, value|
35
+ if value.is_a? Enumerable
36
+ filters["#{attr.sub(/_in$/, '')}_in"] = value
37
+ else
38
+ filters["#{attr.sub(/_eq$/, '')}_eq"] = value
39
+ end
40
+ end
41
+ end
42
+ { filter: h }
43
+ end
44
+
45
+ def self.make_pageable(object, options)
46
+ return object unless object.is_a? ActiveResource::PaginatedCollection
47
+ # Need to set from so paginated collection can use it for page calls.
48
+ object.tap do |collection|
49
+ collection.from = options['from']
50
+ collection.original_params = options['params']
51
+ end
52
+ end
53
+
54
+ def self.arrange_options(options)
55
+ if options[:params].present?
56
+ page = options[:params][:page] ? { page: options[:params].delete(:page) } : {}
57
+ options[:params].merge!(options[:params].delete(:filter)) if options[:params][:filter]
58
+ options[:params] = filters(options[:params]).merge!(page)
59
+ end
60
+ if options[:include].present?
61
+ options[:params] ||= {}
62
+ options[:params].merge!(options.extract!(:include))
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,31 @@
1
+ module ESP
2
+ class Service < ESP::Resource
3
+ ##
4
+ # The collection of signatures associated with this service.
5
+ has_many :signatures, class_name: 'ESP::Signature'
6
+
7
+ # Not Implemented. You cannot create or update a Service.
8
+ def save
9
+ fail ESP::NotImplementedError
10
+ end
11
+
12
+ # Not Implemented. You cannot destroy a Service.
13
+ def destroy
14
+ fail ESP::NotImplementedError
15
+ end
16
+
17
+ ##
18
+ # :singleton-method: find
19
+ # Find a Service by id
20
+ #
21
+ # ==== Parameter
22
+ #
23
+ # +id+ | Required | The ID of the service to retrieve
24
+ #
25
+ # :call-seq:
26
+ # find(id)
27
+
28
+ # :singleton-method: all
29
+ # Return a paginated Service list
30
+ end
31
+ end
@@ -0,0 +1,106 @@
1
+ module ESP
2
+ class Signature < ESP::Resource
3
+ ##
4
+ # The service this signature belongs to.
5
+ belongs_to :service, class_name: 'ESP::Service'
6
+
7
+ # Not Implemented. You cannot create or update a Signature.
8
+ def save
9
+ fail ESP::NotImplementedError
10
+ end
11
+
12
+ # Not Implemented. You cannot destroy a Signature.
13
+ def destroy
14
+ fail ESP::NotImplementedError
15
+ end
16
+
17
+ # Run this signature.
18
+ # Returns a collection of alerts.
19
+ # Throws an error if not successful.
20
+ #
21
+ # ==== Parameters
22
+ #
23
+ # +arguments+ | Required | A hash of run arguments
24
+ #
25
+ # ===== Valid Arguments
26
+ #
27
+ # +external_account_id+ | Required | The ID of the external account to run this custom signature against
28
+ #
29
+ # +regions+ | Required | Array of region names to run this custom signature against
30
+ #
31
+ # ==== Example
32
+ # signature = ESP::Signature.find(3)
33
+ # alerts = signature.run!(external_account_id: 3, regions: ['us_east_1'])
34
+ def run!(arguments = {})
35
+ result = run(arguments)
36
+ return result if result.is_a?(ActiveResource::Collection)
37
+ result.message = result.errors.full_messages.join(' ')
38
+ fail(ActiveResource::ResourceInvalid.new(result)) # rubocop:disable Style/RaiseArgs
39
+ end
40
+
41
+ # Run this signature.
42
+ # Returns a collection of alerts.
43
+ # If not successful, returns a Signature object with the errors object populated.
44
+ #
45
+ # ==== Parameters
46
+ #
47
+ # +arguments+ | Required | A hash of run arguments
48
+ #
49
+ # ===== Valid Arguments
50
+ #
51
+ # +external_account_id+ | Required | The ID of the external account to run this custom signature against
52
+ #
53
+ # +regions+ | Required | Array of region names to run this custom signature against
54
+ #
55
+ # ==== Example
56
+ # signature = ESP::Signature.find(3)
57
+ # alerts = signature.run(external_account_id: 3, regions: ['us_east_1'])
58
+ def run(arguments = {})
59
+ arguments = arguments.with_indifferent_access
60
+ attributes['external_account_id'] ||= arguments[:external_account_id]
61
+ attributes['regions'] ||= Array(arguments[:regions])
62
+
63
+ response = connection.post("#{self.class.prefix}signatures/#{id}/run.json", to_json)
64
+ ESP::Alert.send(:instantiate_collection, self.class.format.decode(response.body))
65
+ rescue ActiveResource::BadRequest, ActiveResource::ResourceInvalid, ActiveResource::ResourceNotFound => error
66
+ load_remote_errors(error, true)
67
+ self.code = error.response.code
68
+ self
69
+ end
70
+
71
+ # Create a suppression for this signature.
72
+ #
73
+ # ==== Parameter
74
+ #
75
+ # +arguments+ | Required | A hash of signature suppression attributes
76
+ #
77
+ # ===== Valid Arguments
78
+ #
79
+ # +regions+ | Required | An array of region names to suppress.
80
+ #
81
+ # +external_account_ids+ | Required | An Array of the external accounts identified by +external_account_id+ to suppress the signature or custom signature on.
82
+ #
83
+ # +reason+ | Required | The reason for creating the suppression.
84
+ #
85
+ # ==== Example
86
+ # suppress(regions: ['us_east_1'], external_account_ids: [5], reason: 'My very good reason for creating this suppression')
87
+ def suppress(arguments = {})
88
+ arguments = arguments.with_indifferent_access
89
+ ESP::Suppression::Signature.create(signature_ids: [id], regions: Array(arguments[:regions]), external_account_ids: Array(arguments[:external_account_ids]), reason: arguments[:reason])
90
+ end
91
+
92
+ ##
93
+ # :singleton-method: find
94
+ # Find a Signature by id
95
+ #
96
+ # ==== Parameter
97
+ #
98
+ # +id+ | Required | The ID of the signature to retrieve
99
+ #
100
+ # :call-seq:
101
+ # find(id)
102
+
103
+ # :singleton-method: all
104
+ # Return a paginated Signature list
105
+ end
106
+ end
@@ -0,0 +1,124 @@
1
+ module ESP
2
+ class Stat < ESP::Resource
3
+ include ESP::StatTotals
4
+
5
+ ##
6
+ # The report these stats are for.
7
+ belongs_to :report, class_name: 'ESP::Report'
8
+
9
+ ##
10
+ # The stats for each region associated with this stat object.
11
+ has_many :regions, class_name: 'ESP::StatRegion'
12
+
13
+ ##
14
+ # The stats for each service associated with this stat object.
15
+ has_many :services, class_name: 'ESP::StatService'
16
+
17
+ ##
18
+ # The stats for each signature associated with this stat object.
19
+ has_many :signatures, class_name: 'ESP::StatSignature'
20
+
21
+ ##
22
+ # The stats for each custom signature associated with this stat object.
23
+ has_many :custom_signatures, class_name: 'ESP::StatCustomSignature'
24
+
25
+ # Not Implemented. You cannot search for a Stat.
26
+ def self.find(*)
27
+ fail ESP::NotImplementedError, 'Regular ARELlike methods are disabled. Use either the ESP::Stat.for_report or ESP::Stat.latest_for_teams method.'
28
+ end
29
+
30
+ # :singleton-method: create
31
+ # Not Implemented. You cannot create a Stat.
32
+
33
+ # :method: save
34
+ # Not Implemented. You cannot create or update a Stat.
35
+
36
+ # :method: destroy
37
+ # Not Implemented. You cannot delete a Stat.
38
+
39
+ # Returns all the stats of all the alerts for a report identified by the report_id parameter. Said report contains all statistics for this alert triggered from signatures contained in all regions for the selected hour.
40
+ def self.for_report(report_id = nil)
41
+ fail ArgumentError, "You must supply a report id." unless report_id.present?
42
+ # call find_one directly since find is overriden/not implemented
43
+ find_one(from: "#{prefix}reports/#{report_id}/stats.json")
44
+ end
45
+
46
+ # Returns all the stats for the most recent report of each team accessible by the given API key.
47
+ def self.latest_for_teams
48
+ # call find_every directly since find is overriden/not implemented
49
+ find_every(from: :latest_for_teams)
50
+ end
51
+
52
+ # :section: 'total' rollup methods
53
+
54
+ # :method: total
55
+
56
+ # :method: total_pass
57
+
58
+ # :method: total_fail
59
+
60
+ # :method: total_warn
61
+
62
+ # :method: total_error
63
+
64
+ # :method: total_info
65
+
66
+ # :method: total_new_1h_pass
67
+
68
+ # :method: total_new_1h_fail
69
+
70
+ # :method: total_new_1h_warn
71
+
72
+ # :method: total_new_1h_error
73
+
74
+ # :method: total_new_1h_info
75
+
76
+ # :method: total_new_1d_pass
77
+
78
+ # :method: total_new_1d_fail
79
+
80
+ # :method: total_new_1d_warn
81
+
82
+ # :method: total_new_1d_error
83
+
84
+ # :method: total_new_1d_info
85
+
86
+ # :method: total_new_1w_pass
87
+
88
+ # :method: total_new_1w_fail
89
+
90
+ # :method: total_new_1w_error
91
+
92
+ # :method: total_new_1w_info
93
+
94
+ # :method: total_new_1w_warn
95
+
96
+ # :method: total_old_fail
97
+
98
+ # :method: total_old_pass
99
+
100
+ # :method: total_old_warn
101
+
102
+ # :method: total_old_error
103
+
104
+ # :method: total_old_info
105
+
106
+ # :method: total_suppressed
107
+
108
+ # :method: total_suppressed_pass
109
+
110
+ # :method: total_suppressed_fail
111
+
112
+ # :method: total_suppressed_warn
113
+
114
+ # :method: total_suppressed_error
115
+
116
+ # :method: total_new_1h
117
+
118
+ # :method: total_new_1d
119
+
120
+ # :method: total_new_1w
121
+
122
+ # :method: total_old
123
+ end
124
+ end
@@ -0,0 +1,121 @@
1
+ module ESP
2
+ class StatCustomSignature < ESP::Resource
3
+ include ESP::StatTotals
4
+
5
+ # The custom_signature these stats are for.
6
+ belongs_to :custom_signature, class_name: 'ESP::CustomSignature'
7
+
8
+ # Returns a paginated collection of custom_signature stats for the given stat_id
9
+ # Convenience method to use instead of ::find since a stat_id is required to return custom_signature stats.
10
+ #
11
+ # ==== Parameter
12
+ #
13
+ # +stat_id+ | Required | The ID of the stat to list custom_signature stats for
14
+ #
15
+ # ==== Example
16
+ # stats = ESP::StatCustomSignature.for_stat(1194)
17
+ def self.for_stat(stat_id = nil)
18
+ fail ArgumentError, "You must supply a stat id." unless stat_id.present?
19
+ from = "#{prefix}stats/#{stat_id}/custom_signatures.json"
20
+ find(:all, from: from)
21
+ end
22
+
23
+ # Find a StatRegion by id
24
+ #
25
+ # ==== Parameter
26
+ #
27
+ # +id+ | Required | The ID of the custom_signature stat to retrieve
28
+ #
29
+ # :call-seq:
30
+ # find(id)
31
+ def self.find(*arguments)
32
+ scope = arguments.slice!(0)
33
+ options = (arguments.slice!(0) || {}).with_indifferent_access
34
+ return super(scope, options) if scope.is_a?(Numeric) || options[:from].present?
35
+ params = options.fetch(:params, {}).with_indifferent_access
36
+ stat_id = params.delete(:stat_id)
37
+ for_stat(stat_id)
38
+ end
39
+
40
+ # :singleton-method: create
41
+ # Not Implemented. You cannot create a Stat.
42
+
43
+ # :method: save
44
+ # Not Implemented. You cannot create or update a Stat.
45
+
46
+ # :method: destroy
47
+ # Not Implemented. You cannot delete a Stat.
48
+
49
+ # :section: 'total' rollup methods
50
+
51
+ # :method: total
52
+
53
+ # :method: total_pass
54
+
55
+ # :method: total_fail
56
+
57
+ # :method: total_warn
58
+
59
+ # :method: total_error
60
+
61
+ # :method: total_info
62
+
63
+ # :method: total_new_1h_pass
64
+
65
+ # :method: total_new_1h_fail
66
+
67
+ # :method: total_new_1h_warn
68
+
69
+ # :method: total_new_1h_error
70
+
71
+ # :method: total_new_1h_info
72
+
73
+ # :method: total_new_1d_pass
74
+
75
+ # :method: total_new_1d_fail
76
+
77
+ # :method: total_new_1d_warn
78
+
79
+ # :method: total_new_1d_error
80
+
81
+ # :method: total_new_1d_info
82
+
83
+ # :method: total_new_1w_pass
84
+
85
+ # :method: total_new_1w_fail
86
+
87
+ # :method: total_new_1w_error
88
+
89
+ # :method: total_new_1w_info
90
+
91
+ # :method: total_new_1w_warn
92
+
93
+ # :method: total_old_fail
94
+
95
+ # :method: total_old_pass
96
+
97
+ # :method: total_old_warn
98
+
99
+ # :method: total_old_error
100
+
101
+ # :method: total_old_info
102
+
103
+ # :method: total_suppressed
104
+
105
+ # :method: total_suppressed_pass
106
+
107
+ # :method: total_suppressed_fail
108
+
109
+ # :method: total_suppressed_warn
110
+
111
+ # :method: total_suppressed_error
112
+
113
+ # :method: total_new_1h
114
+
115
+ # :method: total_new_1d
116
+
117
+ # :method: total_new_1w
118
+
119
+ # :method: total_old
120
+ end
121
+ end
@@ -0,0 +1,121 @@
1
+ module ESP
2
+ class StatRegion < ESP::Resource
3
+ include ESP::StatTotals
4
+
5
+ # The region these stats are for.
6
+ belongs_to :region, class_name: 'ESP::Region'
7
+
8
+ # Returns a paginated collection of region stats for the given stat_id
9
+ # Convenience method to use instead of ::find since a stat_id is required to return region stats.
10
+ #
11
+ # ==== Parameter
12
+ #
13
+ # +stat_id+ | Required | The ID of the stat to list region stats for
14
+ #
15
+ # ==== Example
16
+ # stats = ESP::StatRegion.for_stat(1194)
17
+ def self.for_stat(stat_id = nil)
18
+ fail ArgumentError, "You must supply a stat id." unless stat_id.present?
19
+ from = "#{prefix}stats/#{stat_id}/regions.json"
20
+ find(:all, from: from)
21
+ end
22
+
23
+ # Find a StatRegion by id
24
+ #
25
+ # ==== Parameter
26
+ #
27
+ # +id+ | Required | The ID of the region stat to retrieve
28
+ #
29
+ # :call-seq:
30
+ # find(id)
31
+ def self.find(*arguments)
32
+ scope = arguments.slice!(0)
33
+ options = (arguments.slice!(0) || {}).with_indifferent_access
34
+ return super(scope, options) if scope.is_a?(Numeric) || options[:from].present?
35
+ params = options.fetch(:params, {}).with_indifferent_access
36
+ stat_id = params.delete(:stat_id)
37
+ for_stat(stat_id)
38
+ end
39
+
40
+ # :singleton-method: create
41
+ # Not Implemented. You cannot create a Stat.
42
+
43
+ # :method: save
44
+ # Not Implemented. You cannot create or update a Stat.
45
+
46
+ # :method: destroy
47
+ # Not Implemented. You cannot delete a Stat.
48
+
49
+ # :section: 'total' rollup methods
50
+
51
+ # :method: total
52
+
53
+ # :method: total_pass
54
+
55
+ # :method: total_fail
56
+
57
+ # :method: total_warn
58
+
59
+ # :method: total_error
60
+
61
+ # :method: total_info
62
+
63
+ # :method: total_new_1h_pass
64
+
65
+ # :method: total_new_1h_fail
66
+
67
+ # :method: total_new_1h_warn
68
+
69
+ # :method: total_new_1h_error
70
+
71
+ # :method: total_new_1h_info
72
+
73
+ # :method: total_new_1d_pass
74
+
75
+ # :method: total_new_1d_fail
76
+
77
+ # :method: total_new_1d_warn
78
+
79
+ # :method: total_new_1d_error
80
+
81
+ # :method: total_new_1d_info
82
+
83
+ # :method: total_new_1w_pass
84
+
85
+ # :method: total_new_1w_fail
86
+
87
+ # :method: total_new_1w_error
88
+
89
+ # :method: total_new_1w_info
90
+
91
+ # :method: total_new_1w_warn
92
+
93
+ # :method: total_old_fail
94
+
95
+ # :method: total_old_pass
96
+
97
+ # :method: total_old_warn
98
+
99
+ # :method: total_old_error
100
+
101
+ # :method: total_old_info
102
+
103
+ # :method: total_suppressed
104
+
105
+ # :method: total_suppressed_pass
106
+
107
+ # :method: total_suppressed_fail
108
+
109
+ # :method: total_suppressed_warn
110
+
111
+ # :method: total_suppressed_error
112
+
113
+ # :method: total_new_1h
114
+
115
+ # :method: total_new_1d
116
+
117
+ # :method: total_new_1w
118
+
119
+ # :method: total_old
120
+ end
121
+ end
@@ -0,0 +1,121 @@
1
+ module ESP
2
+ class StatService < ESP::Resource
3
+ include ESP::StatTotals
4
+
5
+ # The service these stats are for.
6
+ belongs_to :service, class_name: 'ESP::Service'
7
+
8
+ # Returns a paginated collection of service stats for the given stat_id
9
+ # Convenience method to use instead of ::find since a stat_id is required to return service stats.
10
+ #
11
+ # ==== Parameter
12
+ #
13
+ # +stat_id+ | Required | The ID of the stat to list service stats for
14
+ #
15
+ # ==== Example
16
+ # stats = ESP::StatService.for_stat(1194)
17
+ def self.for_stat(stat_id = nil)
18
+ fail ArgumentError, "You must supply a stat id." unless stat_id.present?
19
+ from = "#{prefix}stats/#{stat_id}/services.json"
20
+ find(:all, from: from)
21
+ end
22
+
23
+ # Find a StatService by id
24
+ #
25
+ # ==== Parameter
26
+ #
27
+ # +id+ | Required | The ID of the service stat to retrieve
28
+ #
29
+ # :call-seq:
30
+ # find(id)
31
+ def self.find(*arguments)
32
+ scope = arguments.slice!(0)
33
+ options = (arguments.slice!(0) || {}).with_indifferent_access
34
+ return super(scope, options) if scope.is_a?(Numeric) || options[:from].present?
35
+ params = options.fetch(:params, {}).with_indifferent_access
36
+ stat_id = params.delete(:stat_id)
37
+ for_stat(stat_id)
38
+ end
39
+
40
+ # :singleton-method: create
41
+ # Not Implemented. You cannot create a Stat.
42
+
43
+ # :method: save
44
+ # Not Implemented. You cannot create or update a Stat.
45
+
46
+ # :method: destroy
47
+ # Not Implemented. You cannot delete a Stat.
48
+
49
+ # :section: 'total' rollup methods
50
+
51
+ # :method: total
52
+
53
+ # :method: total_pass
54
+
55
+ # :method: total_fail
56
+
57
+ # :method: total_warn
58
+
59
+ # :method: total_error
60
+
61
+ # :method: total_info
62
+
63
+ # :method: total_new_1h_pass
64
+
65
+ # :method: total_new_1h_fail
66
+
67
+ # :method: total_new_1h_warn
68
+
69
+ # :method: total_new_1h_error
70
+
71
+ # :method: total_new_1h_info
72
+
73
+ # :method: total_new_1d_pass
74
+
75
+ # :method: total_new_1d_fail
76
+
77
+ # :method: total_new_1d_warn
78
+
79
+ # :method: total_new_1d_error
80
+
81
+ # :method: total_new_1d_info
82
+
83
+ # :method: total_new_1w_pass
84
+
85
+ # :method: total_new_1w_fail
86
+
87
+ # :method: total_new_1w_error
88
+
89
+ # :method: total_new_1w_info
90
+
91
+ # :method: total_new_1w_warn
92
+
93
+ # :method: total_old_fail
94
+
95
+ # :method: total_old_pass
96
+
97
+ # :method: total_old_warn
98
+
99
+ # :method: total_old_error
100
+
101
+ # :method: total_old_info
102
+
103
+ # :method: total_suppressed
104
+
105
+ # :method: total_suppressed_pass
106
+
107
+ # :method: total_suppressed_fail
108
+
109
+ # :method: total_suppressed_warn
110
+
111
+ # :method: total_suppressed_error
112
+
113
+ # :method: total_new_1h
114
+
115
+ # :method: total_new_1d
116
+
117
+ # :method: total_new_1w
118
+
119
+ # :method: total_old
120
+ end
121
+ end