Files
ubicloud/prog/page_nexus.rb
Enes Cakir a2cd35fcaf Add extra data and severity to pages
The `severity` field allows us to designate the alert's severity level.
PagerDuty uses this field to assess the alert's urgency. The severity
field can be assigned one of the following values: `critical`, `error`,
`warning`, `info` [^1]. In the past, we assigned the `error` value to
all alerts.

Additionally, I added the `extra_data` parameter. This facilitates the
addition of extra details to incidents, along with related resources.
For instance, we can include utilization in capacity incidents.

While I usually appreciate the splat operator `*tag_parts`, its
comprehension becomes challenging as the number of parameters increases.
Therefore, I modified it to accept a list of tags.

[^1]: https://support.pagerduty.com/docs/dynamic-notifications#severity-and-urgency-mapping
2024-07-12 14:36:29 +03:00

31 lines
735 B
Ruby

# frozen_string_literal: true
class Prog::PageNexus < Prog::Base
subject_is :page
semaphore :resolve
def self.assemble(summary, tag_parts, related_resources, severity: "error", extra_data: {})
DB.transaction do
return if Page.from_tag_parts(tag_parts)
pg = Page.create_with_id(summary: summary, details: extra_data.merge({"related_resources" => Array(related_resources)}), tag: Page.generate_tag(tag_parts), severity: severity)
Strand.create(prog: "PageNexus", label: "start") { _1.id = pg.id }
end
end
label def start
page.trigger
hop_wait
end
label def wait
when_resolve_set? do
page.resolve
page.destroy
pop "page is resolved"
end
nap 30
end
end