pagerduty-sdk 1.0.2 → 1.0.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.
- checksums.yaml +4 -4
- data/README.md +5 -144
- data/lib/pagerduty.rb +9 -0
- data/lib/pagerduty/core.rb +91 -9
- data/lib/pagerduty/models/alerts.rb +6 -0
- data/lib/pagerduty/models/escalationpolicies.rb +4 -3
- data/lib/pagerduty/models/incident.rb +22 -70
- data/lib/pagerduty/models/incidents.rb +18 -0
- data/lib/pagerduty/models/notes.rb +7 -0
- data/lib/pagerduty/models/user.rb +6 -5
- data/lib/pagerduty/pagerduty.rb +883 -134
- data/lib/pagerduty/requests/alerts.rb +53 -0
- data/lib/pagerduty/requests/incident.rb +66 -0
- data/pagerduty-sdk.gemspec +2 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb62479652d262b0920666828da1fcf7742dde8a
|
4
|
+
data.tar.gz: 4d3ce2efa6fcb9ac163af176f9d406fb1aa431b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc7611edc60bb045e1cc14599fc519565b45a05331ae6a0008b5bfdd20ecf197608e53283adc8cc2fae2a0ce7b6e2afc248496d2da2d6a6af46da26c70df2809
|
7
|
+
data.tar.gz: c44e5ff4d83db5e29cd8aedcb3462b05b90e122bd0b3fad820ca76715bf7c32d25f56c9b305a326d86f19e0f009a51c0225baeeae21b938f7c106f2d75b35d44
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
pagerduty-sdk
|
2
2
|
=============
|
3
3
|
|
4
|
-
pagerduty-sdk is a Ruby Gem for communicating with the
|
4
|
+
pagerduty-sdk is a Ruby Gem for communicating with the entire
|
5
5
|
[Pagerduty](http://www.pagerduty.com) API. It was designed to be as
|
6
6
|
fully object-oriented as possible. Although it is still under some
|
7
7
|
construction, it is functional and ready for use.
|
@@ -9,160 +9,21 @@ construction, it is functional and ready for use.
|
|
9
9
|
I plan to do much more work on this gem, and your feedback is greatly
|
10
10
|
appreciated!
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
I have just pushed my first commit of this gem to Github. I will be
|
16
|
-
refactoring a lot of the code (and completing the last couple of
|
17
|
-
functions) as soon as I can. Since I haven't generated any documentation
|
18
|
-
for the gem, please know that you can pass the parameters as expected by
|
19
|
-
any of the API methods below to the functions I've listed at the end of
|
20
|
-
this README.
|
21
|
-
|
22
|
-
Example: If the `get_user` Users API method expects a user id, you would
|
23
|
-
call the Pagerduty function as follows: `pagerduty.get_user(id:
|
24
|
-
"#{USERID}")`
|
25
|
-
|
26
|
-
This Gem is under construction!
|
27
|
-
|
28
|
-
#### Alerts
|
29
|
-
http://developer.pagerduty.com/documentation/rest/alerts
|
30
|
-
|
31
|
-
#### Users
|
32
|
-
http://developer.pagerduty.com/documentation/rest/users
|
33
|
-
|
34
|
-
#### Incidents
|
35
|
-
http://developer.pagerduty.com/documentation/rest/incidents
|
36
|
-
|
37
|
-
#### Escalation Policies
|
38
|
-
http://developer.pagerduty.com/documentation/rest/escalation_policies
|
39
|
-
|
40
|
-
#### Escalation Rules
|
41
|
-
http://developer.pagerduty.com/documentation/rest/escalation_policies/escalation_rules
|
42
|
-
|
43
|
-
#### Log Entries
|
44
|
-
http://developer.pagerduty.com/documentation/rest/log_entries
|
45
|
-
|
46
|
-
#### Maintenance Windows
|
47
|
-
http://developer.pagerduty.com/documentation/rest/maintenance_windows
|
48
|
-
|
49
|
-
#### Reports
|
50
|
-
http://developer.pagerduty.com/documentation/rest/reports
|
51
|
-
|
52
|
-
#### Schedules
|
53
|
-
http://developer.pagerduty.com/documentation/rest/schedules
|
54
|
-
- [x] GET schedules List existing on-call schedules.
|
55
|
-
- [x] GET schedules/:id Show detailed information about a schedule, including entries for each layer and sub-schedule.
|
56
|
-
- [x] GET schedules/:id/users List all the users on-call in a given schedule for a given time range.
|
57
|
-
- [ ] POST schedules Create a new on-call schedule.
|
58
|
-
- [ ] PUT schedules/:id Update an existing on-call schedule.
|
59
|
-
- [ ] POST schedules/preview Preview the configuration of an on-call schedule.
|
60
|
-
- [ ] DELETE schedules/:id Delete an on-call schedule.
|
61
|
-
- [ ] GET schedules/:id/entries List schedule entries that are active for a given time range for a specified on-call schedule.
|
62
|
-
|
63
|
-
#### Services
|
64
|
-
http://developer.pagerduty.com/documentation/rest/services
|
65
|
-
- [x] GET services List existing services.
|
66
|
-
- [x] GET services/:id Get details about an existing service.
|
67
|
-
- [x] POST services Create a new service.
|
68
|
-
- [ ] PUT services/:id Update an existing service.
|
69
|
-
- [ ] DELETE services/:id Delete an existing service. Once the service is deleted, it will not be accessible from the web UI and new incidents won't be able to be created for this service.
|
70
|
-
- [ ] PUT services/:id/disable Disable a service. Once a service is disabled, it will not be able to create incidents until it is enabled again.
|
71
|
-
- [ ] PUT services/:id/enable Enable a previously disabled service.
|
72
|
-
- [ ] POST services/:id/regenerate_key Regenerate a new service key for an existing service.
|
73
|
-
|
74
|
-
|
12
|
+
## Requirements
|
13
|
+
* Ruby 1.9.3+
|
14
|
+
* A Pagerduty account token
|
75
15
|
|
76
16
|
## Installation
|
77
|
-
|
78
17
|
```
|
79
18
|
gem install pagerduty-sdk
|
80
19
|
```
|
81
20
|
|
82
|
-
|
83
21
|
## Usage
|
84
|
-
|
85
|
-
Example of getting all incidents within the past 24 hours:
|
86
|
-
|
87
22
|
```ruby
|
88
23
|
require 'pagerduty'
|
89
24
|
|
90
25
|
pagerduty = Pagerduty.new(token: "#{token}", subdomain: "#{subdomain}")
|
91
26
|
#<Pagerduty:0x007f9a340fc410>
|
92
|
-
|
93
|
-
pagerduty.incidents
|
94
|
-
|
95
|
-
[<Pagerduty::Incident
|
96
|
-
id=
|
97
|
-
incident_number=
|
98
|
-
created_on=
|
99
|
-
status=
|
100
|
-
html_url=
|
101
|
-
incident_key=
|
102
|
-
service=#<Service:0x007f9a35106dd8 @id="", @name="", @html_url="", @delete_at=nil>
|
103
|
-
escalation_policy=#<EscalationPolicy:0x007f9a35105168 @id="", @name="", @description=nil, @escalation_rules=[], @services=#<Set: {}>, @num_loops=nil>
|
104
|
-
assigned_to_user=nil
|
105
|
-
trigger_summary_data=#<TriggerSummaryData:0x007f9a3510d6d8 @subject="">
|
106
|
-
trigger_details_html_url=""
|
107
|
-
trigger_type=""
|
108
|
-
last_status_change_on=""
|
109
|
-
last_status_change_by=#<LastStatusChangeBy:0x007f9a3510c440 @id="", @name="", @email="", @html_url="">
|
110
|
-
number_of_escalations=0
|
111
|
-
resolved_by_user=#<ResolvedByUser:0x007f9a3511cd90 @id="", @name="", @email="", @html_url="">
|
112
|
-
>]
|
113
|
-
```
|
114
|
-
|
115
|
-
You can filter the incidents returned by their status (triggered,
|
116
|
-
acknowledged, resolved) by using the accessor method on the array of
|
117
|
-
incidents (`pagerduty.incidents.triggered`)
|
118
|
-
|
119
|
-
You can acknowledge or resolve an incident easily by calling the
|
120
|
-
`acknowledge` or `resolve` methods of the `Pagerduty::Incident` object
|
121
|
-
|
122
|
-
You can also reassign the incident to another user by calling the
|
123
|
-
`reassign` method. This method takes accepts a hash with the expected
|
124
|
-
API parameters which you can see from the Pagerduty documentation link
|
125
|
-
above.
|
126
|
-
|
127
|
-
|
128
|
-
Here's a list of other supported functions (until I have the full
|
129
|
-
documentation up)
|
130
|
-
|
131
|
-
```
|
132
|
-
> pagerduty.interesting_methods
|
133
|
-
[
|
134
|
-
[ 0] :alerts,
|
135
|
-
[ 1] :alerts_per_time,
|
136
|
-
[ 2] :create_escalation_policy,
|
137
|
-
[ 3] :create_maintenance_window,
|
138
|
-
[ 4] :create_service,
|
139
|
-
[ 5] :create_user,
|
140
|
-
[ 6] :curl,
|
141
|
-
[ 7] :escalation_policies,
|
142
|
-
[ 8] :escalation_rules,
|
143
|
-
[ 9] :get_escalation_policy,
|
144
|
-
[10] :get_escalation_rule,
|
145
|
-
[11] :get_incident,
|
146
|
-
[12] :get_incident_counts,
|
147
|
-
[13] :get_log_entries,
|
148
|
-
[14] :get_log_entry,
|
149
|
-
[15] :get_maintenance_window,
|
150
|
-
[16] :get_maintenance_windows,
|
151
|
-
[17] :get_schedule,
|
152
|
-
[18] :get_schedule_users,
|
153
|
-
[19] :get_schedules,
|
154
|
-
[20] :get_service,
|
155
|
-
[21] :get_services,
|
156
|
-
[22] :get_user,
|
157
|
-
[23] :get_users,
|
158
|
-
[24] :has_requirements?,
|
159
|
-
[25] :incidents,
|
160
|
-
[26] :incidents_per_time,
|
161
|
-
[27] :notes,
|
162
|
-
[28] :subdomain,
|
163
|
-
[29] :token
|
164
|
-
]
|
165
27
|
```
|
166
28
|
|
167
|
-
|
168
|
-
|
29
|
+
See [YARD documentation](http://rubydoc.info/gems/pagerduty-sdk/1.0.2/frames) for specific function usage.
|
data/lib/pagerduty.rb
CHANGED
@@ -8,8 +8,11 @@ require 'net/https'
|
|
8
8
|
require 'uri'
|
9
9
|
require 'virtus'
|
10
10
|
|
11
|
+
# Core
|
11
12
|
require 'pagerduty/core'
|
12
13
|
require 'pagerduty/pagerduty'
|
14
|
+
|
15
|
+
# Models
|
13
16
|
require 'pagerduty/models/report'
|
14
17
|
require 'pagerduty/models/agent'
|
15
18
|
require 'pagerduty/models/assigneduser'
|
@@ -25,7 +28,13 @@ require 'pagerduty/models/notification'
|
|
25
28
|
require 'pagerduty/models/log_entry'
|
26
29
|
require 'pagerduty/models/channels'
|
27
30
|
require 'pagerduty/models/alert'
|
31
|
+
require 'pagerduty/models/alerts'
|
28
32
|
require 'pagerduty/models/note'
|
33
|
+
require 'pagerduty/models/notes'
|
29
34
|
require 'pagerduty/models/incident'
|
35
|
+
require 'pagerduty/models/incidents'
|
30
36
|
require 'pagerduty/models/services'
|
31
37
|
|
38
|
+
# Requests
|
39
|
+
require 'pagerduty/requests/incident'
|
40
|
+
#require 'pagerduty/requests/alerts'
|
data/lib/pagerduty/core.rb
CHANGED
@@ -1,12 +1,94 @@
|
|
1
|
-
class
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
class Pagerduty
|
2
|
+
module Core
|
3
|
+
|
4
|
+
###################################################################################
|
5
|
+
# def curl
|
6
|
+
#
|
7
|
+
# Purpose: Performs a CURL request
|
8
|
+
#
|
9
|
+
# Params: options<~Hash> - The options Hash to send
|
10
|
+
# uri<~String> - The URI to curl
|
11
|
+
# ssl<~Boolean><Optional> - Whether or not to use SSL
|
12
|
+
# port<~Integer><Optional> - The port number to connect to
|
13
|
+
# params<~Hash><Optional> - The params to send in the curl request
|
14
|
+
# headers<~Hash><Optional> - The headers to send in the curl request
|
15
|
+
# method<~String> - The HTTP method to perform
|
16
|
+
# basic_auth<~Hash><Optional>
|
17
|
+
# user<~String> - Basic auth user
|
18
|
+
# password<~String> - Basic auth password
|
19
|
+
#
|
20
|
+
# Returns: <String>
|
21
|
+
###################################################################################
|
22
|
+
def curl(options)
|
23
|
+
|
24
|
+
curl_request = {
|
25
|
+
ssl: true,
|
26
|
+
port: 443,
|
27
|
+
headers: {
|
28
|
+
"Content-Type" => "application/json",
|
29
|
+
"Authorization" => "Token token=#{Pagerduty.class_variable_get(:@@token)}",
|
30
|
+
},
|
31
|
+
}
|
32
|
+
|
33
|
+
options.merge! curl_request
|
34
|
+
|
35
|
+
url = URI.parse(options[:uri])
|
36
|
+
|
37
|
+
if options[:params]
|
38
|
+
parameters = options[:params].map { |k,v| "#{k}=#{v}" }.join("&")
|
39
|
+
url += "?#{parameters}"
|
40
|
+
end
|
41
|
+
|
42
|
+
http = Net::HTTP.new(url.host, 443)
|
43
|
+
http.use_ssl = true
|
44
|
+
|
45
|
+
request = case options[:method]
|
46
|
+
when 'DELETE'
|
47
|
+
Net::HTTP::Delete.new(url)
|
48
|
+
when 'GET'
|
49
|
+
Net::HTTP::Get.new(url)
|
50
|
+
when 'POST'
|
51
|
+
Net::HTTP::Post.new(url)
|
52
|
+
when 'PUT'
|
53
|
+
Net::HTTP::Put.new(url)
|
54
|
+
end
|
55
|
+
|
56
|
+
if options.has_key?(:data)
|
57
|
+
request.set_form_data(options[:data])
|
58
|
+
end
|
59
|
+
|
60
|
+
if options.has_key?(:basic_auth)
|
61
|
+
request.basic_auth options[:basic_auth][:user], options[:basic_auth][:password]
|
62
|
+
end
|
63
|
+
|
64
|
+
request.body = options[:body]
|
65
|
+
|
66
|
+
options[:headers].each { |key,val| request.add_field(key,val) }
|
67
|
+
|
68
|
+
response = if options[:method] == 'POST'
|
69
|
+
http.post(url.path,options[:data].to_json,options[:headers])
|
70
|
+
elsif options[:method] == 'PUT'
|
71
|
+
http.put(url.path,options[:data].to_json,options[:headers])
|
72
|
+
else
|
73
|
+
http.request(request)
|
74
|
+
end
|
75
|
+
|
76
|
+
options[:raw_response] == true ? response : JSON.parse(response.body)
|
9
77
|
end
|
10
|
-
end
|
11
78
|
|
79
|
+
|
80
|
+
# Check a Hash object for expected keys
|
81
|
+
#
|
82
|
+
# ==== Parameters
|
83
|
+
# * 'keys'<~Array><~Object> - An array of objects expected to be found as keys in the supplied Hash
|
84
|
+
# * 'options'<~Hash> - The Hash to perform the check on
|
85
|
+
#
|
86
|
+
# ==== Returns
|
87
|
+
# * Boolean
|
88
|
+
#
|
89
|
+
def has_requirements?(keys,options)
|
90
|
+
(keys - options.keys).empty?
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
12
94
|
end
|
@@ -52,18 +52,19 @@ class EscalationRule < Pagerduty
|
|
52
52
|
def delete
|
53
53
|
res = curl({
|
54
54
|
uri: "https://#@@subdomain.pagerduty.com/api/v1/escalation_policies/#{parent_policy.id}/escalation_rules/#{self.id}",
|
55
|
-
method: 'DELETE'
|
55
|
+
method: 'DELETE',
|
56
|
+
raw_response: true
|
56
57
|
})
|
57
58
|
|
58
59
|
res.code == '200' ? 'Successfully deleted' : JSON.parse(res.body)
|
59
60
|
end
|
60
61
|
|
61
62
|
def save
|
62
|
-
self.attributes =
|
63
|
+
self.attributes = curl({
|
63
64
|
uri: "https://#@@subdomain.pagerduty.com/api/v1/escalation_policies/#{parent_policy.id}/escalation_rules/#{self.id}",
|
64
65
|
data: self.hashify,
|
65
66
|
method: 'PUT'
|
66
|
-
})
|
67
|
+
})['escalation_rule']
|
67
68
|
end
|
68
69
|
|
69
70
|
end
|
@@ -1,74 +1,26 @@
|
|
1
|
-
class
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
self.attributes.each { |attr,val|
|
24
|
-
puts "\t#{attr}=#{val.class == Class ? "BLOCK" : val.inspect}"
|
25
|
-
}
|
26
|
-
puts ">"
|
27
|
-
|
28
|
-
self.attributes
|
29
|
-
end
|
30
|
-
|
31
|
-
def notes
|
32
|
-
super(self.id)
|
33
|
-
end
|
34
|
-
|
35
|
-
def acknowledge
|
36
|
-
JSON.parse(curl({
|
37
|
-
uri: "https://#@@subdomain.pagerduty.com/api/v1/incidents/#{self.id}/acknowledge",
|
38
|
-
data: { 'requester_id' => self.assigned_to_user.id },
|
39
|
-
method: 'PUT'
|
40
|
-
}).body)
|
41
|
-
end
|
42
|
-
|
43
|
-
def resolve
|
44
|
-
JSON.parse(curl({
|
45
|
-
uri: "https://#@@subdomain.pagerduty.com/api/v1/incidents/#{self.id}/resolve",
|
46
|
-
data: { 'requester_id' => self.assigned_to_user.id },
|
47
|
-
method: 'PUT'
|
48
|
-
}).body)
|
49
|
-
end
|
50
|
-
|
51
|
-
def reassign(options={})
|
52
|
-
|
53
|
-
unless has_requirements?([:escalation_level, :assigned_to_user], options)
|
54
|
-
puts "#> This function requires arguments :escalation_level, :assigned_to_user"
|
55
|
-
puts "Please see: http://developer.pagerduty.com/documentation/rest/incidents/reassign"
|
56
|
-
return
|
1
|
+
class Pagerduty
|
2
|
+
class Incidents
|
3
|
+
|
4
|
+
class Incident
|
5
|
+
include Virtus.model
|
6
|
+
|
7
|
+
attribute :id
|
8
|
+
attribute :incident_number
|
9
|
+
attribute :created_on
|
10
|
+
attribute :status
|
11
|
+
attribute :html_url
|
12
|
+
attribute :incident_key
|
13
|
+
attribute :service, Service
|
14
|
+
attribute :escalation_policy, EscalationPolicy
|
15
|
+
attribute :assigned_to_user, AssignedUser
|
16
|
+
attribute :trigger_summary_data, TriggerSummaryData
|
17
|
+
attribute :trigger_details_html_url
|
18
|
+
attribute :trigger_type
|
19
|
+
attribute :last_status_change_on
|
20
|
+
attribute :last_status_change_by, LastStatusChangeBy
|
21
|
+
attribute :number_of_escalations
|
22
|
+
attribute :resolved_by_user, ResolvedByUser
|
57
23
|
end
|
58
24
|
|
59
|
-
JSON.parse(curl({
|
60
|
-
uri: "https://#@@subdomain.pagerduty.com/api/v1/incidents/#{self.id}/resolve",
|
61
|
-
data: { 'requester_id' => self.assigned_to_user.id, }.merge(options),
|
62
|
-
method: 'PUT'
|
63
|
-
}).body)
|
64
|
-
end
|
65
|
-
|
66
|
-
def log_entries(options={})
|
67
|
-
LogEntries.new(JSON.parse(curl({
|
68
|
-
uri: "https://#@@subdomain.pagerduty.com/api/v1/incidents/#{self.id}/log_entries",
|
69
|
-
params: options,
|
70
|
-
method: 'GET'
|
71
|
-
}).body))
|
72
25
|
end
|
73
26
|
end
|
74
|
-
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Pagerduty
|
2
|
+
class Incidents
|
3
|
+
include Virtus.model
|
4
|
+
|
5
|
+
attribute :incidents, Array[Pagerduty::Incidents::Incident]
|
6
|
+
|
7
|
+
self.instance_eval do
|
8
|
+
%w(triggered open acknowledged resolved).each do |status|
|
9
|
+
define_method(status) {
|
10
|
+
self.incidents.select { |incident|
|
11
|
+
incident.status == "#{status}"
|
12
|
+
}
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|