gitlab_support_readiness 1.0.0
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.
- checksums.yaml +7 -0
- data/lib/support_readiness/client.rb +108 -0
- data/lib/support_readiness/gitlab/client.rb +64 -0
- data/lib/support_readiness/gitlab/configuration.rb +46 -0
- data/lib/support_readiness/gitlab/groups.rb +180 -0
- data/lib/support_readiness/gitlab/issues.rb +410 -0
- data/lib/support_readiness/gitlab/namespaces.rb +190 -0
- data/lib/support_readiness/gitlab/projects.rb +510 -0
- data/lib/support_readiness/gitlab/repositories.rb +267 -0
- data/lib/support_readiness/gitlab/users.rb +488 -0
- data/lib/support_readiness/gitlab.rb +19 -0
- data/lib/support_readiness/pagerduty/client.rb +66 -0
- data/lib/support_readiness/pagerduty/configuration.rb +43 -0
- data/lib/support_readiness/pagerduty/escalation_policies.rb +123 -0
- data/lib/support_readiness/pagerduty/schedules.rb +223 -0
- data/lib/support_readiness/pagerduty/services.rb +132 -0
- data/lib/support_readiness/pagerduty.rb +16 -0
- data/lib/support_readiness/redis.rb +90 -0
- data/lib/support_readiness/zendesk/articles.rb +210 -0
- data/lib/support_readiness/zendesk/automations.rb +304 -0
- data/lib/support_readiness/zendesk/client.rb +84 -0
- data/lib/support_readiness/zendesk/configuration.rb +49 -0
- data/lib/support_readiness/zendesk/group_memberships.rb +256 -0
- data/lib/support_readiness/zendesk/groups.rb +249 -0
- data/lib/support_readiness/zendesk/job_statuses.rb +188 -0
- data/lib/support_readiness/zendesk/macros.rb +267 -0
- data/lib/support_readiness/zendesk/organization_fields.rb +233 -0
- data/lib/support_readiness/zendesk/organization_memberships.rb +257 -0
- data/lib/support_readiness/zendesk/organizations.rb +515 -0
- data/lib/support_readiness/zendesk/roles.rb +194 -0
- data/lib/support_readiness/zendesk/search.rb +159 -0
- data/lib/support_readiness/zendesk/sla_policies.rb +232 -0
- data/lib/support_readiness/zendesk/ticket_fields.rb +222 -0
- data/lib/support_readiness/zendesk/ticket_forms.rb +290 -0
- data/lib/support_readiness/zendesk/tickets.rb +854 -0
- data/lib/support_readiness/zendesk/triggers.rb +269 -0
- data/lib/support_readiness/zendesk/users.rb +946 -0
- data/lib/support_readiness/zendesk/views.rb +469 -0
- data/lib/support_readiness/zendesk.rb +31 -0
- data/lib/support_readiness.rb +29 -0
- metadata +215 -0
@@ -0,0 +1,123 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module Readiness.
|
4
|
+
module Readiness
|
5
|
+
# Defines the module Pagerduty
|
6
|
+
module Pagerduty
|
7
|
+
##
|
8
|
+
# Defines the class EscalationPolicies within the module {Readiness::Pagerduty}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.0
|
12
|
+
# @todo Create an escalation policy
|
13
|
+
# @todo Delete an escalation policy
|
14
|
+
# @todo Update en escalation policy
|
15
|
+
# @todo List audit records for an escalation policy
|
16
|
+
class EscalationPolicies < Readiness::Client
|
17
|
+
attr_accessor :description, :escalation_rules, :html_url, :id, :name, :num_loops, :on_call_handoff_notifications, :self, :services, :summary, :teams, :type
|
18
|
+
|
19
|
+
##
|
20
|
+
# Creates a new {Readiness::Pagerduty::EscalationPolicies} instance
|
21
|
+
#
|
22
|
+
# @author Jason Colyer
|
23
|
+
# @since 1.0.0
|
24
|
+
# @param object [Object] An instance of {Readiness::Pagerduty::EscalationPolicies}
|
25
|
+
# @example
|
26
|
+
# require 'support_readiness'
|
27
|
+
# Readiness::Pagerduty::EscalationPolicies.new
|
28
|
+
def initialize(object = {})
|
29
|
+
@description = object['description']
|
30
|
+
@escalation_rules = object['escalation_rules']
|
31
|
+
@html_url = object['html_url']
|
32
|
+
@id = object['id']
|
33
|
+
@name = object['name']
|
34
|
+
@num_loops = object['num_loops']
|
35
|
+
@on_call_handoff_notifications = object['on_call_handoff_notifications']
|
36
|
+
@self = object['self']
|
37
|
+
@services = object['services']
|
38
|
+
@summary = object['summary']
|
39
|
+
@teams = object['teams']
|
40
|
+
@type = object['type']
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# Lists escalation policies
|
45
|
+
#
|
46
|
+
# @author Jason Colyer
|
47
|
+
# @since 1.0.0
|
48
|
+
# @param client [Object] An instance of {Readiness::Pagerduty::Client}
|
49
|
+
# @return [Array]
|
50
|
+
# @see https://developer.pagerduty.com/api-reference/51b21014a4f5a-list-escalation-policies Pagerduty API > Escalation Policies > List escalation poliices
|
51
|
+
# @example
|
52
|
+
# require 'support_readiness'
|
53
|
+
# config = Readiness::Pagerduty::Configuration.new
|
54
|
+
# config.token = 'test123abc'
|
55
|
+
# client = Readiness::Pagerduty::Client.new(config)
|
56
|
+
# policies = Readiness::Pagerduty::EscalationPolicies.list(client)
|
57
|
+
# pp policies.first.type
|
58
|
+
# # => "escalation_policy"
|
59
|
+
def self.list(client)
|
60
|
+
array = []
|
61
|
+
offset = 0
|
62
|
+
loop do
|
63
|
+
response = client.connection.get "escalation_policies?limit=100&offset=#{offset}"
|
64
|
+
handle_request_error(0, 'Pagerduty', response.status) unless response.status == 200
|
65
|
+
body = Oj.load(response.body)
|
66
|
+
array += body['escalation_policies'].map { |e| EscalationPolicies.new(e) }
|
67
|
+
break unless body['more']
|
68
|
+
|
69
|
+
offset += 1
|
70
|
+
end
|
71
|
+
array
|
72
|
+
end
|
73
|
+
|
74
|
+
##
|
75
|
+
# Locates an escalation policy within Pagerduty. This will not exit on error (except Authentication errors)
|
76
|
+
#
|
77
|
+
# @author Jason Colyer
|
78
|
+
# @since 1.0.0
|
79
|
+
# @param client [Object] An instance of {Readiness::Pagerduty::Client}
|
80
|
+
# @param pid [String] The escalation policy ID to find
|
81
|
+
# @return [Hash]
|
82
|
+
# @see https://developer.pagerduty.com/api-reference/3db5a206585e1-get-an-escalation-policy Pagerduty API > Escalation Policies > Get an escalation policy
|
83
|
+
# @example
|
84
|
+
# require 'support_readiness'
|
85
|
+
# config = Readiness::Pagerduty::Configuration.new
|
86
|
+
# config.token = 'test123abc'
|
87
|
+
# client = Readiness::Pagerduty::Client.new(config)
|
88
|
+
# policy = Readiness::Pagerduty::EscalationPolicies.find(client, 'PANZZEQ')
|
89
|
+
# pp policy.name
|
90
|
+
# # => "Engineering Escalation Policy"
|
91
|
+
def self.find(client, pid)
|
92
|
+
response = client.connection.get("escalation_policies/#{pid}")
|
93
|
+
handle_request_error(0, 'Pagerduty', response.status, { action: 'get', id: pid }) unless response.status == 200
|
94
|
+
return EscalationPolicies.new(Oj.load(response.body)['escalation_policy']) if response.status == 200
|
95
|
+
|
96
|
+
Oj.load(response.body)
|
97
|
+
end
|
98
|
+
|
99
|
+
##
|
100
|
+
# Locates an escalation policy within Pagerduty. This will exit on error
|
101
|
+
#
|
102
|
+
# @author Jason Colyer
|
103
|
+
# @since 1.0.0
|
104
|
+
# @param client [Object] An instance of {Readiness::Pagerduty::Client}
|
105
|
+
# @param pid [String] The escalation policy ID to find
|
106
|
+
# @return [Hash]
|
107
|
+
# @see https://developer.pagerduty.com/api-reference/3db5a206585e1-get-an-escalation-policy Pagerduty API > Escalation Policies > Get an escalation policy
|
108
|
+
# @example
|
109
|
+
# require 'support_readiness'
|
110
|
+
# config = Readiness::Pagerduty::Configuration.new
|
111
|
+
# config.token = 'test123abc'
|
112
|
+
# client = Readiness::Pagerduty::Client.new(config)
|
113
|
+
# policy = Readiness::Pagerduty::EscalationPolicies.find!(client, 'PANZZEQ')
|
114
|
+
# pp policy.name
|
115
|
+
# # => "Engineering Escalation Policy"
|
116
|
+
def self.find!(client, pid)
|
117
|
+
response = client.connection.get("escalation_policies/#{pid}")
|
118
|
+
handle_request_error(1, 'Pagerduty', response.status, { action: 'Find escalation policy', id: pid }) unless response.status == 200
|
119
|
+
EscalationPolicies.new(Oj.load(response.body)['escalation_policy'])
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,223 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module Readiness.
|
4
|
+
module Readiness
|
5
|
+
# Defines the module Pagerduty
|
6
|
+
module Pagerduty
|
7
|
+
##
|
8
|
+
# Defines the class Schedules within the module {Readiness::Pagerduty}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.0
|
12
|
+
# @todo Create a schedule
|
13
|
+
# @todo Update a scehdule
|
14
|
+
# @todo List audit records for a schedule
|
15
|
+
# @todo List users on call
|
16
|
+
# @todo Preview a schedule
|
17
|
+
class Schedules < Readiness::Client
|
18
|
+
attr_accessor :description, :escalation_policies, :final_schedule, :html_url, :id, :name, :overrides_subschedule, :schedule_layers, :self, :summary, :teams, :time_zone, :type, :users
|
19
|
+
|
20
|
+
##
|
21
|
+
# Creates a new {Readiness::Pagerduty::Schedules} instance
|
22
|
+
#
|
23
|
+
# @author Jason Colyer
|
24
|
+
# @since 1.0.0
|
25
|
+
# @param object [Object] An instance of {Readiness::Pagerduty::Schedules}
|
26
|
+
# @example
|
27
|
+
# require 'support_readiness'
|
28
|
+
# Readiness::Pagerduty::Schedules.new
|
29
|
+
def initialize(object = {})
|
30
|
+
@description = object['description']
|
31
|
+
@escalation_policies = object['escalation_policies']
|
32
|
+
@final_schedule = object['final_schedule']
|
33
|
+
@html_url = object['html_url']
|
34
|
+
@id = object['id']
|
35
|
+
@name = object['name']
|
36
|
+
@overrides_subschedule = object['overrides_subschedule']
|
37
|
+
@schedule_layers = object['schedule_layers']
|
38
|
+
@self = object['self']
|
39
|
+
@summary = object['summary']
|
40
|
+
@teams = object['teams']
|
41
|
+
@time_zone = object['time_zone']
|
42
|
+
@type = object['type']
|
43
|
+
@users = object['users']
|
44
|
+
end
|
45
|
+
|
46
|
+
##
|
47
|
+
# Lists schedules
|
48
|
+
#
|
49
|
+
# @author Jason Colyer
|
50
|
+
# @since 1.0.0
|
51
|
+
# @param client [Object] An instance of {Readiness::Pagerduty::Client}
|
52
|
+
# @return [Array]
|
53
|
+
# @see https://developer.pagerduty.com/api-reference/846ecf84402bb-list-schedules Pagerduty API > Schedules > List schedules
|
54
|
+
# @example
|
55
|
+
# require 'support_readiness'
|
56
|
+
# config = Readiness::Pagerduty::Configuration.new
|
57
|
+
# config.token = 'test123abc'
|
58
|
+
# client = Readiness::Pagerduty::Client.new(config)
|
59
|
+
# schedules = Readiness::Pagerduty::Schedules.list(client)
|
60
|
+
# pp schedules.first.name
|
61
|
+
# # => "Daily Engineering Rotation"
|
62
|
+
def self.list(client)
|
63
|
+
array = []
|
64
|
+
offset = 0
|
65
|
+
loop do
|
66
|
+
response = client.connection.get "schedules?limit=100&offset=#{offset}"
|
67
|
+
handle_request_error(0, 'Pagerduty', response.status) unless response.status == 200
|
68
|
+
body = Oj.load(response.body)
|
69
|
+
array += body['schedules'].map { |e| Schedules.new(e) }
|
70
|
+
break unless body['more']
|
71
|
+
|
72
|
+
offset += 1
|
73
|
+
end
|
74
|
+
array
|
75
|
+
end
|
76
|
+
|
77
|
+
##
|
78
|
+
# Locates a schedule within Pagerduty. This will not exit on error (except Authentication errors)
|
79
|
+
#
|
80
|
+
# @author Jason Colyer
|
81
|
+
# @since 1.0.0
|
82
|
+
# @param client [Object] An instance of {Readiness::Pagerduty::Client}
|
83
|
+
# @param sid [String] The schedule ID to find
|
84
|
+
# @return [Hash]
|
85
|
+
# @see https://developer.pagerduty.com/api-reference/3f03afb2c84a4-get-a-schedule Pagerduty API > Schedules > Get a schedule
|
86
|
+
# @example
|
87
|
+
# require 'support_readiness'
|
88
|
+
# config = Readiness::Pagerduty::Configuration.new
|
89
|
+
# config.token = 'test123abc'
|
90
|
+
# client = Readiness::Pagerduty::Client.new(config)
|
91
|
+
# schedule = Readiness::Pagerduty::Schedules.find(client, 'PI7DH85')
|
92
|
+
# pp schedule.name
|
93
|
+
# # => "Daily Engineering Rotation"
|
94
|
+
def self.find(client, sid)
|
95
|
+
response = client.connection.get("schedules/#{sid}")
|
96
|
+
handle_request_error(0, 'Pagerduty', response.status, { action: 'get', id: sid }) unless response.status == 200
|
97
|
+
return Schedules.new(Oj.load(response.body)['schedule']) if response.status == 200
|
98
|
+
|
99
|
+
Oj.load(response.body)
|
100
|
+
end
|
101
|
+
|
102
|
+
##
|
103
|
+
# Locates a schedule within Pagerduty. This will exit on error
|
104
|
+
#
|
105
|
+
# @author Jason Colyer
|
106
|
+
# @since 1.0.0
|
107
|
+
# @param client [Object] An instance of {Readiness::Pagerduty::Client}
|
108
|
+
# @param sid [String] The schedule ID to find
|
109
|
+
# @return [Object] A {Readiness::Pagerduty::Schedules} instance
|
110
|
+
# @see https://developer.pagerduty.com/api-reference/3f03afb2c84a4-get-a-schedule Pagerduty API > Schedules > Get a schedule
|
111
|
+
# @example
|
112
|
+
# require 'support_readiness'
|
113
|
+
# config = Readiness::Pagerduty::Configuration.new
|
114
|
+
# config.token = 'test123abc'
|
115
|
+
# client = Readiness::Pagerduty::Client.new(config)
|
116
|
+
# schedule = Readiness::Pagerduty::Schedules.find!(client, 'PI7DH85')
|
117
|
+
# pp schedule.name
|
118
|
+
# # => "Daily Engineering Rotation"
|
119
|
+
def self.find!(client, sid)
|
120
|
+
response = client.connection.get("schedules/#{sid}")
|
121
|
+
handle_request_error(1, 'Pagerduty', response.status, { action: 'Find schedule', id: sid }) unless response.status == 200
|
122
|
+
Schedules.new(Oj.load(response.body)['schedule'])
|
123
|
+
end
|
124
|
+
|
125
|
+
##
|
126
|
+
# Lists overrides for a schedule within Pagerduty. This will exit on error
|
127
|
+
#
|
128
|
+
# @author Jason Colyer
|
129
|
+
# @since 1.0.0
|
130
|
+
# @param client [Object] An instance of {Readiness::Pagerduty::Client}
|
131
|
+
# @param schedule [Object] A {Readiness::Pagerduty::Schedules} instance
|
132
|
+
# @param start_time [Time] The start time to use (must be ISO format)
|
133
|
+
# @param end_time [Time] The end time to use (must be ISO format)
|
134
|
+
# @param editable [Boolean] Only show overrides that can be edited (ones in the future)
|
135
|
+
# @return [Array]
|
136
|
+
# @see https://developer.pagerduty.com/api-reference/cb747199f63a9-list-overrides Pagerduty API > Schedules > List overrides
|
137
|
+
# @example
|
138
|
+
# require 'support_readiness'
|
139
|
+
# config = Readiness::Pagerduty::Configuration.new
|
140
|
+
# config.token = 'test123abc'
|
141
|
+
# client = Readiness::Pagerduty::Client.new(config)
|
142
|
+
# schedule = Readiness::Pagerduty::Schedules.find(client, 'PI7DH85')
|
143
|
+
# overrides = Readiness::Pagerduty::Schedules.overrides(client, schedule)
|
144
|
+
# pp overrides.first['user']['summary']
|
145
|
+
# # => "Aurelio Rice"
|
146
|
+
def self.overrides(client, schedule, start_time = Time.now.utc.iso8601, end_time = (Time.now.utc + 1.hours).iso8601, editable = true)
|
147
|
+
response = client.connection.get "schedules/#{schedule.id}/overrides?editable=#{editable}&since=#{start_time}&until=#{end_time}"
|
148
|
+
handle_request_error(1, 'Pagerduty', response.status, { action: 'List overrides', id: schedule.id }) unless response.status == 201
|
149
|
+
Oj.load(response.body)['overrides']
|
150
|
+
end
|
151
|
+
|
152
|
+
##
|
153
|
+
# Create overrides on a schedule within Pagerduty. This will exit on error
|
154
|
+
#
|
155
|
+
# @author Jason Colyer
|
156
|
+
# @since 1.0.0
|
157
|
+
# @param client [Object] An instance of {Readiness::Pagerduty::Client}
|
158
|
+
# @param schedule [Object] A {Readiness::Pagerduty::Schedules} instance
|
159
|
+
# @param list [Array] An array of overrides to create
|
160
|
+
# @return [Array]
|
161
|
+
# @see https://developer.pagerduty.com/api-reference/41d0a7c3c3a01-create-one-or-more-overrides Pagerduty API > Schedules > Create one of more overrides
|
162
|
+
# @example
|
163
|
+
# require 'support_readiness'
|
164
|
+
# config = Readiness::Pagerduty::Configuration.new
|
165
|
+
# config.token = 'test123abc'
|
166
|
+
# client = Readiness::Pagerduty::Client.new(config)
|
167
|
+
# schedule = Readiness::Pagerduty::Schedules.find(client, 'PI7DH85')
|
168
|
+
# overrides = [
|
169
|
+
# {
|
170
|
+
# start: '2012-07-01T00:00:00-04:00',
|
171
|
+
# end: '2012-07-02T00:00:00-04:00',
|
172
|
+
# user: {
|
173
|
+
# id: 'PEYSGVA',
|
174
|
+
# type: 'user_reference'
|
175
|
+
# },
|
176
|
+
# time_zone: 'UTC'
|
177
|
+
# },
|
178
|
+
# {
|
179
|
+
# start: '2012-07-03T00:00:00-04:00',
|
180
|
+
# end: '2012-07-04T00:00:00-04:00',
|
181
|
+
# user: {
|
182
|
+
# id: 'PEYSGVF',
|
183
|
+
# type: 'user_reference'
|
184
|
+
# },
|
185
|
+
# time_zone: 'UTC'
|
186
|
+
# }
|
187
|
+
# ]
|
188
|
+
# created_overrides = Readiness::Pagerduty::Schedules.create_overrides(client, schedule, overrides)
|
189
|
+
# pp created_overrides.map { |c| c['status'] }
|
190
|
+
# # => [201, 201]
|
191
|
+
def self.create_overrides(client, schedule, list)
|
192
|
+
response = client.connection.post "schedules/#{schedule.id}/overrides", { overrides: list }.to_json
|
193
|
+
handle_request_error(1, 'Pagerduty', response.status, { action: 'Create overrides', id: schedule.id }) unless response.status == 201
|
194
|
+
Oj.load(response.body)
|
195
|
+
end
|
196
|
+
|
197
|
+
##
|
198
|
+
# Delete an override on a schedule within Pagerduty. This will exit on error
|
199
|
+
#
|
200
|
+
# @author Jason Colyer
|
201
|
+
# @since 1.0.0
|
202
|
+
# @param client [Object] An instance of {Readiness::Pagerduty::Client}
|
203
|
+
# @param schedule [Object] A {Readiness::Pagerduty::Schedules} instance
|
204
|
+
# @param oid [String] An override ID
|
205
|
+
# @return [Boolean]
|
206
|
+
# @see https://developer.pagerduty.com/api-reference/7740a1ba2d8a7-delete-an-override Pagerduty API > Schedules > Delete an override
|
207
|
+
# @example
|
208
|
+
# require 'support_readiness'
|
209
|
+
# config = Readiness::Pagerduty::Configuration.new
|
210
|
+
# config.token = 'test123abc'
|
211
|
+
# client = Readiness::Pagerduty::Client.new(config)
|
212
|
+
# schedule = Readiness::Pagerduty::Schedules.find(client, 'PI7DH85')
|
213
|
+
# delete = Readiness::Pagerduty::Schedules.delete_override!(client, schedule, 'Q3X6MJ1LUKD6QW')
|
214
|
+
# pp delete
|
215
|
+
# # => true
|
216
|
+
def self.delete_override!(client, schedule, oid)
|
217
|
+
response = client.connection.delete "schedules/#{schedule.id}/overrides/#{oid}"
|
218
|
+
handle_request_error(1, 'Pagerduty', response.status, { action: 'Delete an override', id: schedule.id }) unless [200, 204].include?(response.status)
|
219
|
+
true
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module Readiness.
|
4
|
+
module Readiness
|
5
|
+
# Defines the module Pagerduty
|
6
|
+
module Pagerduty
|
7
|
+
##
|
8
|
+
# Defines the class Services within the module {Readiness::Pagerduty}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.0
|
12
|
+
# @todo Create a service
|
13
|
+
# @todo Delete a service
|
14
|
+
# @todo Update a service
|
15
|
+
# @todo List audit records for a service
|
16
|
+
# @todo Creat a new integration
|
17
|
+
# @todo Update an existing integration
|
18
|
+
# @todo View an integration
|
19
|
+
class Services < Readiness::Client
|
20
|
+
attr_accessor :acknowledgement_timeout, :alert_creation, :auto_pause_notifications_parameters, :auto_resolve_timeout, :created_at, :escalation_policy, :html_url, :id, :incident_urgency_rule, :integrations, :name, :scheduled_actions, :self, :status, :summary, :support_hours, :teams, :type
|
21
|
+
|
22
|
+
##
|
23
|
+
# Creates a new {Readiness::Pagerduty::Services} instance
|
24
|
+
#
|
25
|
+
# @author Jason Colyer
|
26
|
+
# @since 1.0.0
|
27
|
+
# @param object [Object] An instance of {Readiness::Pagerduty::Services}
|
28
|
+
# @example
|
29
|
+
# require 'support_readiness'
|
30
|
+
# Readiness::Pagerduty::Services.new
|
31
|
+
def initialize(object = {})
|
32
|
+
@acknowledgement_timeout = object['acknowledgement_timeout']
|
33
|
+
@alert_creation = object['alert_creation']
|
34
|
+
@auto_pause_notifications_parameters = object['auto_pause_notifications_parameters']
|
35
|
+
@auto_resolve_timeout = object['auto_resolve_timeout']
|
36
|
+
@created_at = object['created_at']
|
37
|
+
@escalation_policy = object['escalation_policy']
|
38
|
+
@html_url = object['html_url']
|
39
|
+
@id = object['id']
|
40
|
+
@incident_urgency_rule = object['incident_urgency_rule']
|
41
|
+
@integrations = object['integrations']
|
42
|
+
@name = object['name']
|
43
|
+
@scheduled_actions = object['scheduled_actions']
|
44
|
+
@self = object['self']
|
45
|
+
@status = object['status']
|
46
|
+
@summary = object['summary']
|
47
|
+
@support_hours = object['support_hours']
|
48
|
+
@teams = object['teams']
|
49
|
+
@type = object['type']
|
50
|
+
end
|
51
|
+
|
52
|
+
##
|
53
|
+
# Lists services
|
54
|
+
#
|
55
|
+
# @author Jason Colyer
|
56
|
+
# @since 1.0.0
|
57
|
+
# @param client [Object] An instance of {Readiness::Pagerduty::Client}
|
58
|
+
# @return [Array]
|
59
|
+
# @see https://developer.pagerduty.com/api-reference/e960cca205c0f-list-services Pagerduty API > Services > List services
|
60
|
+
# @example
|
61
|
+
# require 'support_readiness'
|
62
|
+
# config = Readiness::Pagerduty::Configuration.new
|
63
|
+
# config.token = 'test123abc'
|
64
|
+
# client = Readiness::Pagerduty::Client.new(config)
|
65
|
+
# services = Readiness::Pagerduty::Services.list(client)
|
66
|
+
# pp services.first.name
|
67
|
+
# # => "My Application Service"
|
68
|
+
def self.list(client)
|
69
|
+
array = []
|
70
|
+
offset = 0
|
71
|
+
loop do
|
72
|
+
response = client.connection.get "services?limit=100&offset=#{offset}"
|
73
|
+
handle_request_error(0, 'Pagerduty', response.status) unless response.status == 200
|
74
|
+
body = Oj.load(response.body)
|
75
|
+
array += body['services'].map { |e| Services.new(e) }
|
76
|
+
break unless body['more']
|
77
|
+
|
78
|
+
offset += 1
|
79
|
+
end
|
80
|
+
array
|
81
|
+
end
|
82
|
+
|
83
|
+
##
|
84
|
+
# Locates a service within Pagerduty. This will not exit on error (except Authentication errors)
|
85
|
+
#
|
86
|
+
# @author Jason Colyer
|
87
|
+
# @since 1.0.0
|
88
|
+
# @param client [Object] An instance of {Readiness::Pagerduty::Client}
|
89
|
+
# @param sid [String] The service ID to find
|
90
|
+
# @return [Hash]
|
91
|
+
# @see https://developer.pagerduty.com/api-reference/165ad96a22ffd-get-a-service Pagerduty API > Services > Get a service
|
92
|
+
# @example
|
93
|
+
# require 'support_readiness'
|
94
|
+
# config = Readiness::Pagerduty::Configuration.new
|
95
|
+
# config.token = 'test123abc'
|
96
|
+
# client = Readiness::Pagerduty::Client.new(config)
|
97
|
+
# service = Readiness::Pagerduty::Services.find(client, "PIJ90N7")
|
98
|
+
# pp service.name
|
99
|
+
# # => "My Application Service"
|
100
|
+
def self.find(client, sid)
|
101
|
+
response = client.connection.get("services/#{sid}")
|
102
|
+
handle_request_error(0, 'Pagerduty', response.status, { action: 'get', id: sid }) unless response.status == 200
|
103
|
+
return Services.new(Oj.load(response.body)['service']) if response.status == 200
|
104
|
+
|
105
|
+
Oj.load(response.body)
|
106
|
+
end
|
107
|
+
|
108
|
+
##
|
109
|
+
# Locates a service within Pagerduty. This will exit on error
|
110
|
+
#
|
111
|
+
# @author Jason Colyer
|
112
|
+
# @since 1.0.0
|
113
|
+
# @param client [Object] An instance of {Readiness::Pagerduty::Client}
|
114
|
+
# @param sid [String] The service ID to find
|
115
|
+
# @return [Object] A {Readiness::Pagerduty::Services} instance
|
116
|
+
# @see https://developer.pagerduty.com/api-reference/165ad96a22ffd-get-a-service Pagerduty API > Services > Get a service
|
117
|
+
# @example
|
118
|
+
# require 'support_readiness'
|
119
|
+
# config = Readiness::Pagerduty::Configuration.new
|
120
|
+
# config.token = 'test123abc'
|
121
|
+
# client = Readiness::Pagerduty::Client.new(config)
|
122
|
+
# service = Readiness::Pagerduty::Services.find!(client, "PIJ90N7")
|
123
|
+
# pp service.name
|
124
|
+
# # => "My Application Service"
|
125
|
+
def self.find!(client, sid)
|
126
|
+
response = client.connection.get("services/#{sid}")
|
127
|
+
handle_request_error(1, 'Pagerduty', response.status, { action: 'Find service', id: sid }) unless response.status == 200
|
128
|
+
Services.new(Oj.load(response.body)['service'])
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module Readiness.
|
4
|
+
module Readiness
|
5
|
+
##
|
6
|
+
# Defines the module Pagerduty
|
7
|
+
# @author Jason Colyer
|
8
|
+
# @since 1.0.0
|
9
|
+
module Pagerduty
|
10
|
+
require "#{__dir__}/pagerduty/client"
|
11
|
+
require "#{__dir__}/pagerduty/configuration"
|
12
|
+
require "#{__dir__}/pagerduty/escalation_policies"
|
13
|
+
require "#{__dir__}/pagerduty/schedules"
|
14
|
+
require "#{__dir__}/pagerduty/services"
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module Readiness.
|
4
|
+
module Readiness
|
5
|
+
##
|
6
|
+
# Defines the class Redis within the module {Readiness}.
|
7
|
+
#
|
8
|
+
# @author Jason Colyer
|
9
|
+
# @since 1.0.0
|
10
|
+
class Redis
|
11
|
+
attr_accessor :connection
|
12
|
+
|
13
|
+
##
|
14
|
+
# Creates a new {Readiness::Redis} instance
|
15
|
+
#
|
16
|
+
# @author Jason Colyer
|
17
|
+
# @since 1.0.0
|
18
|
+
# @param host [String] The hostname to use in Redis connections
|
19
|
+
# @param port [Integer] The port number to use in Redis connections
|
20
|
+
# @param password [String] The password to use in Redis connections
|
21
|
+
# @example
|
22
|
+
# require 'support_readiness'
|
23
|
+
# redis = Readiness::Redis.new('domain.com', 6379, 'p@assw0rd!')
|
24
|
+
def initialize(host, port, password)
|
25
|
+
@connection = generate_client(host, port, password)
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
# Returns a Redis connection
|
30
|
+
#
|
31
|
+
# @author Jason Colyer
|
32
|
+
# @since 1.0.0
|
33
|
+
# @param host [String] The hostname to use in Redis connections
|
34
|
+
# @param port [Integer] The port number to use in Redis connections
|
35
|
+
# @param password [String] The password to use in Redis connections
|
36
|
+
def generate_client(host, port, password)
|
37
|
+
::Redis.new(host: host,
|
38
|
+
port: port,
|
39
|
+
password: password,
|
40
|
+
ssl: true)
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# Returns the value stored in a Redis key
|
45
|
+
#
|
46
|
+
# @author Jason Colyer
|
47
|
+
# @since 1.0.0
|
48
|
+
# @param client [Object] A {Readiness::Redis} instance
|
49
|
+
# @param key [String] The Redis key to get the value of
|
50
|
+
# @example
|
51
|
+
# require 'support_readiness'
|
52
|
+
# redis = Readiness::Redis.new('domain.com', 6379, 'p@assw0rd!')
|
53
|
+
# puts Readiness::Redis.get(redis, 'foo')
|
54
|
+
# # => bar
|
55
|
+
def self.get(client, key)
|
56
|
+
Marshal.load client.connection.get(key)
|
57
|
+
end
|
58
|
+
|
59
|
+
##
|
60
|
+
# Sets the value stored in a Redis key
|
61
|
+
#
|
62
|
+
# @author Jason Colyer
|
63
|
+
# @since 1.0.0
|
64
|
+
# @param client [Object] A {Readiness::Redis} instance
|
65
|
+
# @param key [String] The Redis key to set the value of
|
66
|
+
# @param value The value to set within the key
|
67
|
+
# @example
|
68
|
+
# require 'support_readiness'
|
69
|
+
# redis = Readiness::Redis.new('domain.com', 6379, 'p@assw0rd!')
|
70
|
+
# Readiness::Redis.set(redis, 'foo', 'bar2')
|
71
|
+
def self.set(client, key, value)
|
72
|
+
client.connection.set(key, Marhsal.dump(value))
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
# Deletes the key and value stored in a Redis
|
77
|
+
#
|
78
|
+
# @author Jason Colyer
|
79
|
+
# @since 1.0.0
|
80
|
+
# @param client [Object] A {Readiness::Redis} instance
|
81
|
+
# @param key [String] The Redis key to delete
|
82
|
+
# @example
|
83
|
+
# require 'support_readiness'
|
84
|
+
# redis = Readiness::Redis.new('domain.com', 6379, 'p@assw0rd!')
|
85
|
+
# Readiness::Redis.del(redis, 'foo')
|
86
|
+
def self.del(client, key)
|
87
|
+
client.connection.del(key)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|