lex-pagerduty 0.2.1
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/.github/workflows/ci.yml +16 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +53 -0
- data/CHANGELOG.md +12 -0
- data/CLAUDE.md +72 -0
- data/Dockerfile +6 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +171 -0
- data/LICENSE.txt +21 -0
- data/README.md +70 -0
- data/lex-pagerduty.gemspec +37 -0
- data/lib/legion/extensions/pagerduty/client.rb +51 -0
- data/lib/legion/extensions/pagerduty/helpers/client.rb +22 -0
- data/lib/legion/extensions/pagerduty/runners/abilities.rb +28 -0
- data/lib/legion/extensions/pagerduty/runners/escalation_policies.rb +58 -0
- data/lib/legion/extensions/pagerduty/runners/incidents.rb +98 -0
- data/lib/legion/extensions/pagerduty/runners/log_entries.rb +31 -0
- data/lib/legion/extensions/pagerduty/runners/maintenance_windows.rb +59 -0
- data/lib/legion/extensions/pagerduty/runners/notifications.rb +25 -0
- data/lib/legion/extensions/pagerduty/runners/on_calls.rb +29 -0
- data/lib/legion/extensions/pagerduty/runners/priorities.rb +24 -0
- data/lib/legion/extensions/pagerduty/runners/schedules.rb +71 -0
- data/lib/legion/extensions/pagerduty/runners/services.rb +82 -0
- data/lib/legion/extensions/pagerduty/runners/tags.rb +57 -0
- data/lib/legion/extensions/pagerduty/runners/teams.rb +58 -0
- data/lib/legion/extensions/pagerduty/runners/users.rb +78 -0
- data/lib/legion/extensions/pagerduty/runners/vendors.rb +29 -0
- data/lib/legion/extensions/pagerduty/version.rb +9 -0
- data/lib/legion/extensions/pagerduty.rb +27 -0
- metadata +188 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/pagerduty/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Pagerduty
|
|
8
|
+
module Runners
|
|
9
|
+
module Incidents
|
|
10
|
+
include Legion::Extensions::Pagerduty::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def list_incidents(statuses: [], service_ids: [], urgencies: [], per_page: 25, page: 0, **)
|
|
13
|
+
params = { limit: per_page, offset: page * per_page }
|
|
14
|
+
params['statuses[]'] = statuses unless statuses.empty?
|
|
15
|
+
params['service_ids[]'] = service_ids unless service_ids.empty?
|
|
16
|
+
params['urgencies[]'] = urgencies unless urgencies.empty?
|
|
17
|
+
response = connection(**).get('/incidents', params)
|
|
18
|
+
{ result: response.body }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def get_incident(id:, **)
|
|
22
|
+
response = connection(**).get("/incidents/#{id}")
|
|
23
|
+
{ result: response.body }
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def create_incident(title:, service_id:, type: 'incident', urgency: nil, body: nil, escalation_policy_id: nil, **)
|
|
27
|
+
payload = { incident: { type: type, title: title, service: { id: service_id, type: 'service_reference' } } }
|
|
28
|
+
payload[:incident][:urgency] = urgency if urgency
|
|
29
|
+
payload[:incident][:body] = { type: 'incident_body', details: body } if body
|
|
30
|
+
payload[:incident][:escalation_policy] = { id: escalation_policy_id, type: 'escalation_policy_reference' } if escalation_policy_id
|
|
31
|
+
response = connection(**).post('/incidents', payload)
|
|
32
|
+
{ result: response.body }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def update_incident(id:, from:, status: nil, title: nil, urgency: nil, escalation_policy_id: nil, **)
|
|
36
|
+
payload = { incident: { type: 'incident_reference' } }
|
|
37
|
+
payload[:incident][:status] = status if status
|
|
38
|
+
payload[:incident][:title] = title if title
|
|
39
|
+
payload[:incident][:urgency] = urgency if urgency
|
|
40
|
+
payload[:incident][:escalation_policy] = { id: escalation_policy_id, type: 'escalation_policy_reference' } if escalation_policy_id
|
|
41
|
+
conn = connection(**)
|
|
42
|
+
conn.headers['From'] = from
|
|
43
|
+
response = conn.put("/incidents/#{id}", payload)
|
|
44
|
+
{ result: response.body }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def merge_incidents(id:, from:, source_incident_ids:, **)
|
|
48
|
+
source = source_incident_ids.map { |sid| { id: sid, type: 'incident_reference' } }
|
|
49
|
+
conn = connection(**)
|
|
50
|
+
conn.headers['From'] = from
|
|
51
|
+
response = conn.put("/incidents/#{id}/merge", { source_incidents: source })
|
|
52
|
+
{ result: response.body }
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def snooze_incident(id:, from:, duration:, **)
|
|
56
|
+
conn = connection(**)
|
|
57
|
+
conn.headers['From'] = from
|
|
58
|
+
response = conn.post("/incidents/#{id}/snooze", { duration: duration })
|
|
59
|
+
{ result: response.body }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def list_incident_notes(id:, **)
|
|
63
|
+
response = connection(**).get("/incidents/#{id}/notes")
|
|
64
|
+
{ result: response.body }
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def create_incident_note(id:, from:, content:, **)
|
|
68
|
+
conn = connection(**)
|
|
69
|
+
conn.headers['From'] = from
|
|
70
|
+
response = conn.post("/incidents/#{id}/notes", { note: { content: content } })
|
|
71
|
+
{ result: response.body }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def list_incident_alerts(id:, per_page: 25, page: 0, **)
|
|
75
|
+
params = { limit: per_page, offset: page * per_page }
|
|
76
|
+
response = connection(**).get("/incidents/#{id}/alerts", params)
|
|
77
|
+
{ result: response.body }
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def get_incident_alert(incident_id:, alert_id:, **)
|
|
81
|
+
response = connection(**).get("/incidents/#{incident_id}/alerts/#{alert_id}")
|
|
82
|
+
{ result: response.body }
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def update_incident_alert(incident_id:, alert_id:, from:, status:, **)
|
|
86
|
+
conn = connection(**)
|
|
87
|
+
conn.headers['From'] = from
|
|
88
|
+
response = conn.put("/incidents/#{incident_id}/alerts/#{alert_id}", { alert: { type: 'alert', status: status } })
|
|
89
|
+
{ result: response.body }
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
93
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/pagerduty/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Pagerduty
|
|
8
|
+
module Runners
|
|
9
|
+
module LogEntries
|
|
10
|
+
include Legion::Extensions::Pagerduty::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def list_log_entries(since_time: nil, until_time: nil, per_page: 25, page: 0, **)
|
|
13
|
+
params = { limit: per_page, offset: page * per_page }
|
|
14
|
+
params[:since] = since_time if since_time
|
|
15
|
+
params[:until] = until_time if until_time
|
|
16
|
+
response = connection(**).get('/log_entries', params)
|
|
17
|
+
{ result: response.body }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def get_log_entry(id:, **)
|
|
21
|
+
response = connection(**).get("/log_entries/#{id}")
|
|
22
|
+
{ result: response.body }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
26
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/pagerduty/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Pagerduty
|
|
8
|
+
module Runners
|
|
9
|
+
module MaintenanceWindows
|
|
10
|
+
include Legion::Extensions::Pagerduty::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def list_maintenance_windows(service_ids: [], query: nil, per_page: 25, page: 0, **)
|
|
13
|
+
params = { limit: per_page, offset: page * per_page }
|
|
14
|
+
params['service_ids[]'] = service_ids unless service_ids.empty?
|
|
15
|
+
params[:query] = query if query
|
|
16
|
+
response = connection(**).get('/maintenance_windows', params)
|
|
17
|
+
{ result: response.body }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def get_maintenance_window(id:, **)
|
|
21
|
+
response = connection(**).get("/maintenance_windows/#{id}")
|
|
22
|
+
{ result: response.body }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def create_maintenance_window(start_time:, end_time:, service_ids:, description: nil, **)
|
|
26
|
+
services = service_ids.map { |sid| { id: sid, type: 'service_reference' } }
|
|
27
|
+
payload = {
|
|
28
|
+
maintenance_window: {
|
|
29
|
+
type: 'maintenance_window',
|
|
30
|
+
start_time: start_time,
|
|
31
|
+
end_time: end_time,
|
|
32
|
+
services: services
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
payload[:maintenance_window][:description] = description if description
|
|
36
|
+
response = connection(**).post('/maintenance_windows', payload)
|
|
37
|
+
{ result: response.body }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def update_maintenance_window(id:, **opts)
|
|
41
|
+
payload = opts.slice(:start_time, :end_time, :description)
|
|
42
|
+
payload[:services] = opts[:service_ids].map { |sid| { id: sid, type: 'service_reference' } } if opts[:service_ids]
|
|
43
|
+
response = connection(**opts).put("/maintenance_windows/#{id}",
|
|
44
|
+
{ maintenance_window: { type: 'maintenance_window', **payload } })
|
|
45
|
+
{ result: response.body }
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def delete_maintenance_window(id:, **)
|
|
49
|
+
response = connection(**).delete("/maintenance_windows/#{id}")
|
|
50
|
+
{ result: response.status == 204 }
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
54
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/pagerduty/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Pagerduty
|
|
8
|
+
module Runners
|
|
9
|
+
module Notifications
|
|
10
|
+
include Legion::Extensions::Pagerduty::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def list_notifications(since_time:, until_time:, filter: nil, per_page: 25, page: 0, **)
|
|
13
|
+
params = { since: since_time, until: until_time, limit: per_page, offset: page * per_page }
|
|
14
|
+
params[:filter] = filter if filter
|
|
15
|
+
response = connection(**).get('/notifications', params)
|
|
16
|
+
{ result: response.body }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
20
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/pagerduty/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Pagerduty
|
|
8
|
+
module Runners
|
|
9
|
+
module OnCalls
|
|
10
|
+
include Legion::Extensions::Pagerduty::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def list_on_calls(schedule_ids: [], escalation_policy_ids: [], since_time: nil, until_time: nil,
|
|
13
|
+
per_page: 25, page: 0, **)
|
|
14
|
+
params = { limit: per_page, offset: page * per_page }
|
|
15
|
+
params['schedule_ids[]'] = schedule_ids unless schedule_ids.empty?
|
|
16
|
+
params['escalation_policy_ids[]'] = escalation_policy_ids unless escalation_policy_ids.empty?
|
|
17
|
+
params[:since] = since_time if since_time
|
|
18
|
+
params[:until] = until_time if until_time
|
|
19
|
+
response = connection(**).get('/oncalls', params)
|
|
20
|
+
{ result: response.body }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
24
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/pagerduty/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Pagerduty
|
|
8
|
+
module Runners
|
|
9
|
+
module Priorities
|
|
10
|
+
include Legion::Extensions::Pagerduty::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def list_priorities(per_page: 25, page: 0, **)
|
|
13
|
+
params = { limit: per_page, offset: page * per_page }
|
|
14
|
+
response = connection(**).get('/priorities', params)
|
|
15
|
+
{ result: response.body }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
19
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/pagerduty/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Pagerduty
|
|
8
|
+
module Runners
|
|
9
|
+
module Schedules
|
|
10
|
+
include Legion::Extensions::Pagerduty::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def list_schedules(query: nil, per_page: 25, page: 0, **)
|
|
13
|
+
params = { limit: per_page, offset: page * per_page }
|
|
14
|
+
params[:query] = query if query
|
|
15
|
+
response = connection(**).get('/schedules', params)
|
|
16
|
+
{ result: response.body }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def get_schedule(id:, since_time: nil, until_time: nil, **)
|
|
20
|
+
params = {}
|
|
21
|
+
params[:since] = since_time if since_time
|
|
22
|
+
params[:until] = until_time if until_time
|
|
23
|
+
response = connection(**).get("/schedules/#{id}", params)
|
|
24
|
+
{ result: response.body }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def create_schedule(schedule:, **)
|
|
28
|
+
response = connection(**).post('/schedules', { schedule: schedule })
|
|
29
|
+
{ result: response.body }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def update_schedule(id:, schedule:, **)
|
|
33
|
+
response = connection(**).put("/schedules/#{id}", { schedule: schedule })
|
|
34
|
+
{ result: response.body }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def delete_schedule(id:, **)
|
|
38
|
+
response = connection(**).delete("/schedules/#{id}")
|
|
39
|
+
{ result: response.status == 204 }
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def list_schedule_overrides(id:, since_time:, until_time:, **)
|
|
43
|
+
response = connection(**).get("/schedules/#{id}/overrides", since: since_time, until: until_time)
|
|
44
|
+
{ result: response.body }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def create_schedule_override(id:, overrides:, **)
|
|
48
|
+
response = connection(**).post("/schedules/#{id}/overrides", { overrides: overrides })
|
|
49
|
+
{ result: response.body }
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def delete_schedule_override(schedule_id:, override_id:, **)
|
|
53
|
+
response = connection(**).delete("/schedules/#{schedule_id}/overrides/#{override_id}")
|
|
54
|
+
{ result: response.status == 204 }
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def list_on_call_users(id:, since_time: nil, until_time: nil, **)
|
|
58
|
+
params = {}
|
|
59
|
+
params[:since] = since_time if since_time
|
|
60
|
+
params[:until] = until_time if until_time
|
|
61
|
+
response = connection(**).get("/schedules/#{id}/users", params)
|
|
62
|
+
{ result: response.body }
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
66
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/pagerduty/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Pagerduty
|
|
8
|
+
module Runners
|
|
9
|
+
module Services
|
|
10
|
+
include Legion::Extensions::Pagerduty::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def list_services(per_page: 25, page: 0, query: nil, **)
|
|
13
|
+
params = { limit: per_page, offset: page * per_page }
|
|
14
|
+
params[:query] = query if query
|
|
15
|
+
response = connection(**).get('/services', params)
|
|
16
|
+
{ result: response.body }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def get_service(id:, **)
|
|
20
|
+
response = connection(**).get("/services/#{id}")
|
|
21
|
+
{ result: response.body }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def create_service(name:, escalation_policy_id:, description: nil, auto_resolve_timeout: nil,
|
|
25
|
+
acknowledgement_timeout: nil, **)
|
|
26
|
+
payload = {
|
|
27
|
+
service: {
|
|
28
|
+
type: 'service',
|
|
29
|
+
name: name,
|
|
30
|
+
escalation_policy: { id: escalation_policy_id, type: 'escalation_policy_reference' }
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
payload[:service][:description] = description if description
|
|
34
|
+
payload[:service][:auto_resolve_timeout] = auto_resolve_timeout if auto_resolve_timeout
|
|
35
|
+
payload[:service][:acknowledgement_timeout] = acknowledgement_timeout if acknowledgement_timeout
|
|
36
|
+
response = connection(**).post('/services', payload)
|
|
37
|
+
{ result: response.body }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def update_service(id:, **opts)
|
|
41
|
+
payload = opts.slice(:name, :description, :auto_resolve_timeout, :acknowledgement_timeout, :status)
|
|
42
|
+
response = connection(**opts).put("/services/#{id}", { service: { type: 'service', **payload } })
|
|
43
|
+
{ result: response.body }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def delete_service(id:, **)
|
|
47
|
+
response = connection(**).delete("/services/#{id}")
|
|
48
|
+
{ result: response.status == 204 }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def list_integrations(service_id:, **)
|
|
52
|
+
response = connection(**).get("/services/#{service_id}/integrations")
|
|
53
|
+
{ result: response.body }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def create_integration(service_id:, type: 'generic_events_api_inbound_integration', name: nil, vendor_id: nil, **)
|
|
57
|
+
payload = { integration: { type: type } }
|
|
58
|
+
payload[:integration][:name] = name if name
|
|
59
|
+
payload[:integration][:vendor] = { id: vendor_id, type: 'vendor_reference' } if vendor_id
|
|
60
|
+
response = connection(**).post("/services/#{service_id}/integrations", payload)
|
|
61
|
+
{ result: response.body }
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def get_integration(service_id:, integration_id:, **)
|
|
65
|
+
response = connection(**).get("/services/#{service_id}/integrations/#{integration_id}")
|
|
66
|
+
{ result: response.body }
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def update_integration(service_id:, integration_id:, **opts)
|
|
70
|
+
payload = opts.slice(:name, :type)
|
|
71
|
+
response = connection(**opts).put("/services/#{service_id}/integrations/#{integration_id}",
|
|
72
|
+
{ integration: { type: 'generic_events_api_inbound_integration', **payload } })
|
|
73
|
+
{ result: response.body }
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
77
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/pagerduty/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Pagerduty
|
|
8
|
+
module Runners
|
|
9
|
+
module Tags
|
|
10
|
+
include Legion::Extensions::Pagerduty::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def list_tags(query: nil, per_page: 25, page: 0, **)
|
|
13
|
+
params = { limit: per_page, offset: page * per_page }
|
|
14
|
+
params[:query] = query if query
|
|
15
|
+
response = connection(**).get('/tags', params)
|
|
16
|
+
{ result: response.body }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def get_tag(id:, **)
|
|
20
|
+
response = connection(**).get("/tags/#{id}")
|
|
21
|
+
{ result: response.body }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def create_tag(label:, **)
|
|
25
|
+
response = connection(**).post('/tags', { tag: { type: 'tag', label: label } })
|
|
26
|
+
{ result: response.body }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def delete_tag(id:, **)
|
|
30
|
+
response = connection(**).delete("/tags/#{id}")
|
|
31
|
+
{ result: response.status == 204 }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def list_entity_tags(entity_type:, entity_id:, **)
|
|
35
|
+
response = connection(**).get("/#{entity_type}/#{entity_id}/tags")
|
|
36
|
+
{ result: response.body }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def assign_tags(entity_type:, entity_id:, tags:, **)
|
|
40
|
+
add = tags.map { |t| t.is_a?(Hash) ? t : { type: 'tag_reference', id: t } }
|
|
41
|
+
response = connection(**).post("/#{entity_type}/#{entity_id}/change_tags", { add: add, remove: [] })
|
|
42
|
+
{ result: response.status == 200 }
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def remove_tags(entity_type:, entity_id:, tags:, **)
|
|
46
|
+
remove = tags.map { |t| t.is_a?(Hash) ? t : { type: 'tag_reference', id: t } }
|
|
47
|
+
response = connection(**).post("/#{entity_type}/#{entity_id}/change_tags", { add: [], remove: remove })
|
|
48
|
+
{ result: response.status == 200 }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
52
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/pagerduty/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Pagerduty
|
|
8
|
+
module Runners
|
|
9
|
+
module Teams
|
|
10
|
+
include Legion::Extensions::Pagerduty::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def list_teams(query: nil, per_page: 25, page: 0, **)
|
|
13
|
+
params = { limit: per_page, offset: page * per_page }
|
|
14
|
+
params[:query] = query if query
|
|
15
|
+
response = connection(**).get('/teams', params)
|
|
16
|
+
{ result: response.body }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def get_team(id:, **)
|
|
20
|
+
response = connection(**).get("/teams/#{id}")
|
|
21
|
+
{ result: response.body }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def create_team(name:, description: nil, **)
|
|
25
|
+
payload = { team: { type: 'team', name: name } }
|
|
26
|
+
payload[:team][:description] = description if description
|
|
27
|
+
response = connection(**).post('/teams', payload)
|
|
28
|
+
{ result: response.body }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def update_team(id:, **opts)
|
|
32
|
+
payload = opts.slice(:name, :description)
|
|
33
|
+
response = connection(**opts).put("/teams/#{id}", { team: { type: 'team', **payload } })
|
|
34
|
+
{ result: response.body }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def delete_team(id:, **)
|
|
38
|
+
response = connection(**).delete("/teams/#{id}")
|
|
39
|
+
{ result: response.status == 204 }
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def add_member(team_id:, user_id:, role: 'member', **)
|
|
43
|
+
response = connection(**).put("/teams/#{team_id}/users/#{user_id}", { role: role })
|
|
44
|
+
{ result: response.status == 204 }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def remove_member(team_id:, user_id:, **)
|
|
48
|
+
response = connection(**).delete("/teams/#{team_id}/users/#{user_id}")
|
|
49
|
+
{ result: response.status == 204 }
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
53
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/pagerduty/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Pagerduty
|
|
8
|
+
module Runners
|
|
9
|
+
module Users
|
|
10
|
+
include Legion::Extensions::Pagerduty::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def list_users(query: nil, per_page: 25, page: 0, **)
|
|
13
|
+
params = { limit: per_page, offset: page * per_page }
|
|
14
|
+
params[:query] = query if query
|
|
15
|
+
response = connection(**).get('/users', params)
|
|
16
|
+
{ result: response.body }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def get_user(id:, **)
|
|
20
|
+
response = connection(**).get("/users/#{id}")
|
|
21
|
+
{ result: response.body }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def create_user(name:, email:, role: 'user', description: nil, **)
|
|
25
|
+
payload = { user: { type: 'user', name: name, email: email, role: role } }
|
|
26
|
+
payload[:user][:description] = description if description
|
|
27
|
+
response = connection(**).post('/users', payload)
|
|
28
|
+
{ result: response.body }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def update_user(id:, **opts)
|
|
32
|
+
payload = opts.slice(:name, :email, :role, :description)
|
|
33
|
+
response = connection(**opts).put("/users/#{id}", { user: { type: 'user', **payload } })
|
|
34
|
+
{ result: response.body }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def delete_user(id:, **)
|
|
38
|
+
response = connection(**).delete("/users/#{id}")
|
|
39
|
+
{ result: response.status == 204 }
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def list_contact_methods(user_id:, **)
|
|
43
|
+
response = connection(**).get("/users/#{user_id}/contact_methods")
|
|
44
|
+
{ result: response.body }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def create_contact_method(user_id:, type:, label:, address:, country_code: nil, **)
|
|
48
|
+
payload = { contact_method: { type: type, label: label, address: address } }
|
|
49
|
+
payload[:contact_method][:country_code] = country_code.to_i if country_code
|
|
50
|
+
response = connection(**).post("/users/#{user_id}/contact_methods", payload)
|
|
51
|
+
{ result: response.body }
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def list_notification_rules(user_id:, **)
|
|
55
|
+
response = connection(**).get("/users/#{user_id}/notification_rules")
|
|
56
|
+
{ result: response.body }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def create_notification_rule(user_id:, start_delay_in_minutes:, contact_method_id:, type: 'assignment_notification_rule', urgency: 'high', **)
|
|
60
|
+
payload = {
|
|
61
|
+
notification_rule: {
|
|
62
|
+
type: type,
|
|
63
|
+
start_delay_in_minutes: start_delay_in_minutes,
|
|
64
|
+
contact_method: { id: contact_method_id, type: 'contact_method_reference' },
|
|
65
|
+
urgency: urgency
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
response = connection(**).post("/users/#{user_id}/notification_rules", payload)
|
|
69
|
+
{ result: response.body }
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
73
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/pagerduty/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Pagerduty
|
|
8
|
+
module Runners
|
|
9
|
+
module Vendors
|
|
10
|
+
include Legion::Extensions::Pagerduty::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def list_vendors(per_page: 25, page: 0, **)
|
|
13
|
+
params = { limit: per_page, offset: page * per_page }
|
|
14
|
+
response = connection(**).get('/vendors', params)
|
|
15
|
+
{ result: response.body }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def get_vendor(id:, **)
|
|
19
|
+
response = connection(**).get("/vendors/#{id}")
|
|
20
|
+
{ result: response.body }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
24
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|