Module: PagerDuty::Client::Incidents
- Included in:
- PagerDuty::Client
- Defined in:
- lib/pager_duty/client/incidents.rb
Overview
Module encompassing interactions with the incidents API endpoint
Instance Method Summary collapse
-
#create_incident_note(incident_id, from_email_address, options = {}) ⇒ Sawyer::Resource
Create a new note for the specified incident.
-
#incident(id, options = {}) ⇒ Sawyer::Resource
(also: #get_incident)
Show detailed information about an incident.
-
#incident_alert(incident_id, alert_id, options = {}) ⇒ Sawyer::Resource
(also: #get_incident_alert)
Show detailed information about an alert.
-
#incident_alerts(incident_id, options = {}) ⇒ Array<Sawyer::Resource>
(also: #get_alerts_for_incident)
List alerts for the specified incident.
-
#incident_log_entries(incident_id, options = {}) ⇒ Array<Sawyer::Resource>
List log entries for the specified incident.
-
#incident_notes(incident_id, options = {}) ⇒ Sawyer::Resource
List existing notes for the specified incident.
-
#incidents(options = {}) ⇒ Array<Sawyer::Resource>
(also: #list_incidents)
List incidents.
-
#merge_incidents(incident_id, from_email_address, source_incidents, options = {}) ⇒ Sawyer::Resource
Merge a list of source incidents into this incident.
-
#snooze_incident(incident_id, from_email_address, duration, options = {}) ⇒ Sawyer::Resource
Snooze an incident.
-
#update_incidents(from_email_address, incidents, options = {}) ⇒ Array<Sawyer::Resource>
Acknowledge, resolve, escalate or reassign one or more incidents.
Instance Method Details
#create_incident_note(incident_id, from_email_address, options = {}) ⇒ Sawyer::Resource
Create a new note for the specified incident. /incidents/id/notes
213 214 215 216 217 218 219 220 221 |
# File 'lib/pager_duty/client/incidents.rb', line 213 def create_incident_note(incident_id, from_email_address, = {}) if from_email_address [:headers] ||= {} [:headers][:from] = from_email_address end response = post "/incidents/#{incident_id}/notes", response[:note] end |
#incident(id, options = {}) ⇒ Sawyer::Resource Also known as: get_incident
Show detailed information about an incident. Accepts either an incident id, or an incident number. /incidents/id
58 59 60 61 |
# File 'lib/pager_duty/client/incidents.rb', line 58 def incident(id, = {}) response = get "/incidents/#{id}", response[:incident] end |
#incident_alert(incident_id, alert_id, options = {}) ⇒ Sawyer::Resource Also known as: get_incident_alert
Show detailed information about an alert. Accepts an alert id. /incidents/id/alerts/alert_id/
93 94 95 96 |
# File 'lib/pager_duty/client/incidents.rb', line 93 def incident_alert(incident_id, alert_id, = {}) response = get "/incidents/{incident_id}/alerts/{alert_id}", response[:alert] end |
#incident_alerts(incident_id, options = {}) ⇒ Array<Sawyer::Resource> Also known as: get_alerts_for_incident
List alerts for the specified incident. /incidents/id/alerts
75 76 77 78 79 80 81 82 |
# File 'lib/pager_duty/client/incidents.rb', line 75 def incident_alerts(incident_id, = {}) query_params = Hash.new query_params[:statuses] = .fetch(:statuses, []) query_params[:alert_key] = [:alert_key] if [:alert_key] query_params[:sort_by] = [:sort_by] if [:sort_by] response = get "/incidents/#{incident_id}/alerts", .merge({query: query_params}) response[:alerts] end |
#incident_log_entries(incident_id, options = {}) ⇒ Array<Sawyer::Resource>
List log entries for the specified incident. /incidents/incident_id/log_entries
107 108 109 110 111 112 113 114 115 |
# File 'lib/pager_duty/client/incidents.rb', line 107 def incident_log_entries(incident_id, = {}) query_params = Hash.new query_params[:time_zone] = [:time_zone] if [:time_zone] query_params[:is_overview] = [:is_overview] if [:is_overview] query_params[:include] = [:include] if [:include] response = get "/incidents/#{incident_id}/log_entries", .merge({query: query_params}) response[:log_entries] end |
#incident_notes(incident_id, options = {}) ⇒ Sawyer::Resource
List existing notes for the specified incident. /incidents/id/notes
124 125 126 127 |
# File 'lib/pager_duty/client/incidents.rb', line 124 def incident_notes(incident_id, = {}) response = get "/incidents/#{incident_id}/notes", response[:notes] end |
#incidents(options = {}) ⇒ Array<Sawyer::Resource> Also known as: list_incidents
List incidents
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/pager_duty/client/incidents.rb', line 23 def incidents( = {}) query_params = Hash.new if [:date_range] # they passed in a value and we'll assume it's all query_params[:date_range] = "all" else query_params[:since] = [:since].utc.iso8601 if [:since] query_params[:until] = [:until].utc.iso8601 if [:until] end query_params[:incident_key] = [:incident_key] if [:incident_key] query_params[:time_zone] = [:time_zone] if [:time_zone] query_params[:sort_by] = [:sort_by] if [:sort_by] user_ids = .fetch(:user_ids, []) team_ids = .fetch(:team_ids, []) query_params["statuses"] = .fetch(:statuses, []) query_params["service_ids[]"] = [:service_ids].join(", ") if [:service_ids] query_params["team_ids[]"] = team_ids.join(",") if team_ids.length > 0 query_params["user_ids[]"] = user_ids.join(",") if user_ids.length > 0 query_params["urgencies"] = [:urgencies] if [:urgencies] query_params["include"] = [:include] if [:include] response = get "/incidents", .merge({query: query_params}) response[:incidents] end |
#merge_incidents(incident_id, from_email_address, source_incidents, options = {}) ⇒ Sawyer::Resource
Merge a list of source incidents into this incident. /incidents/id/merge
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/pager_duty/client/incidents.rb', line 159 def merge_incidents(incident_id, from_email_address, source_incidents, = {}) [:source_incidents] = source_incidents.map { |incident_id| { id: incident_id, type: "incident_reference" } } if from_email_address [:headers] ||= {} [:headers][:from] = from_email_address end response = put "/incidents/#{incident_id}/merge", response[:incident] end |
#snooze_incident(incident_id, from_email_address, duration, options = {}) ⇒ Sawyer::Resource
Snooze an incident. /incidents/id/snooze
137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/pager_duty/client/incidents.rb', line 137 def snooze_incident(incident_id, from_email_address, duration, = {}) query_params = Hash.new query_params[:duration] = duration if from_email_address [:headers] ||= {} [:headers][:from] = from_email_address end response = post "/incidents/#{incident_id}/snooze", .merge({query: query_params}) response[:incident] end |
#update_incidents(from_email_address, incidents, options = {}) ⇒ Array<Sawyer::Resource>
Acknowledge, resolve, escalate or reassign one or more incidents. /incidents
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/pager_duty/client/incidents.rb', line 184 def update_incidents(from_email_address, incidents, = {}) [:incidents] = incidents.map { |incident| item = { id: incident[:id], type: "incident_reference" } item[:status] = incident[:status] if incident[:status] item[:resolution] = incident[:resolution] if incident[:resolution] item[:title] = incident[:title] if incident[:title] item[:escalation_level] = incident[:escalation_level] if incident[:escalation_level] item[:assignments] = incident[:assignments] if incident[:assignments] item[:escalation_policy] = incident[:escalation_policy] if incident[:escalation_policy] item } if from_email_address [:headers] ||= {} [:headers][:from] = from_email_address end response = put "/incidents", response[:incidents] end |