Class: PagerDuty::MaintenanceClient
Constant Summary
Constants inherited
from Service
Service::STATSD_KEY_PREFIX
Instance Method Summary
collapse
Methods inherited from Service
#headers, #perform
#config, configuration, #connection, #delete, #get, #perform, #post, #put, #raise_backend_exception, #raise_not_authenticated, #request, #sanitize_headers!, #service_name
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata
Instance Method Details
#convert(raw_mws) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/pagerduty/maintenance_client.rb', line 55
def convert(raw_mws)
result = []
raw_mws.each do |mw|
mw['services'].each do |svc|
window = {
pagerduty_id: mw['id'],
external_service: PagerDuty::Configuration.service_map[svc['id']].to_s,
start_time: Time.iso8601(mw['start_time']),
end_time: Time.iso8601(mw['end_time']),
description: mw['description'] ||= ''
}
result << window
end
end
result
end
|
#get_all(options = {}) ⇒ Object
11
12
13
14
15
16
|
# File 'lib/pagerduty/maintenance_client.rb', line 11
def get_all(options = {})
return [] if PagerDuty::Configuration.service_ids.blank?
raw_mws = get_all_raw(options)
convert(raw_mws)
end
|
#get_all_raw(options = {}) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/pagerduty/maintenance_client.rb', line 20
def get_all_raw(options = {})
resp = get_raw(options)
return [] if resp.nil?
windows = resp['maintenance_windows']
while resp['more']
offset = resp['offset'] + resp['limit']
resp = get_raw(options.merge('offset' => offset))
windows += resp['maintenance_windows']
end
windows
end
|
#get_raw(options = {}) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/pagerduty/maintenance_client.rb', line 33
def get_raw(options = {})
query = {
'offset' => 0,
'filter' => 'open',
'service_ids' => PagerDuty::Configuration.service_ids
}.merge(options)
begin
perform(:get, 'maintenance_windows', query).body
rescue => e
if e&.original_status == 400
Rails.logger.error(
"Invalid arguments sent to PagerDuty. One of the following Service IDs is bad: #{query['service_ids']}"
)
else
Rails.logger.error("Querying PagerDuty for maintenance windows failed with the error: #{e.message}")
end
nil
end
end
|