Skip to content

Commit

Permalink
Datadog ReTrigger Event (#125)
Browse files Browse the repository at this point in the history
* Adds the retriggered event

* Add the test for the recreate event type
  • Loading branch information
armiiller authored Nov 12, 2024
1 parent 61c08f1 commit d4dad5e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
13 changes: 10 additions & 3 deletions app/models/pager_tree/integrations/datadog/v3.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
module PagerTree::Integrations
class Datadog::V3 < Integration
OPTIONS = []
OPTIONS = [
{key: :support_retriggered_event, type: :boolean, default: false}
]
store_accessor :options, *OPTIONS.map { |x| x[:key] }.map(&:to_s), prefix: "option"

after_initialize do
self.option_support_retriggered_event ||= false
end

def adapter_supports_incoming?
Expand All @@ -24,8 +27,12 @@ def adapter_thirdparty_id

def adapter_action
case _transition
when "Triggered" then :create
when "Recovered" then :resolve
when "Triggered"
:create
when "Recovered"
:resolve
when "Re-Triggered"
self.option_support_retriggered_event == true ? :recreate : :other
else
:other
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="grid grid-cols-1 gap-4">
<div class="form-group group">
<%= form.check_box :option_support_retriggered_event, class: "form-checkbox" %>
<%= form.label :option_support_retriggered_event, class: "inline-block" %>
<p class="form-hint md:inline-block"><%== t(".option_support_retriggered_event_hint_html") %></p>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="sm:col-span-1">
<dt class="text-sm font-medium text-gray-500">
<%= t("activerecord.attributes.pager_tree/integrations/datadog/v3.option_support_retriggered_event") %>
</dt>
<dd class="mt-1 text-sm text-gray-900">
<div class="flex items-center gap-2">
<p class="text-sm truncate">
<%= render partial: "shared/components/badge_enabled", locals: { enabled: integration.option_support_retriggered_event } %>
</p>
</div>
</dd>
</div>
6 changes: 6 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ en:
v3:
form_options:
option_webhook_secret_hint_html: "Cloudflare Webhook Secret"
datadog:
v3:
form_options:
option_support_retriggered_event_hint_html: "Create a new alert when the 'Re-Triggered' event is sent by Datadog"
email:
v3:
form_options:
Expand Down Expand Up @@ -157,6 +161,8 @@ en:
option_time_zone: "Display Time Zone"
"pager_tree/integrations/cloudflare/v3":
option_webhook_secret: "Webhook Secret"
"pager_tree/integrations/datadog/v3":
option_support_retriggered_event: "Retriggered Event"
"pager_tree/integrations/email/v3":
option_allow_spam: "Allow Spam"
option_dedup_threads: "Dedup Threads"
Expand Down
10 changes: 10 additions & 0 deletions test/models/pager_tree/integrations/datadog/v3_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class Datadog::V3Test < ActiveSupport::TestCase
@resolve_request = @create_request.deep_dup
@resolve_request[:ALERT_TRANSITION] = "Recovered"

@retriggered_request = @create_request.deep_dup
@retriggered_request[:ALERT_TRANSITION] = "Re-Triggered"

@other_request = @create_request.deep_dup
@other_request[:ALERT_TRANSITION] = "baaad"
end
Expand All @@ -54,6 +57,13 @@ class Datadog::V3Test < ActiveSupport::TestCase

@integration.adapter_incoming_request_params = @other_request
assert_equal :other, @integration.adapter_action

@integration.adapter_incoming_request_params = @retriggered_request
assert_equal :other, @integration.adapter_action

@integration.option_support_retriggered_event = true
@integration.adapter_incoming_request_params = @retriggered_request
assert_equal :recreate, @integration.adapter_action
end

test "adapter_thirdparty_id" do
Expand Down

0 comments on commit d4dad5e

Please sign in to comment.