diff --git a/app/models/pager_tree/integrations/datadog/v3.rb b/app/models/pager_tree/integrations/datadog/v3.rb index 4cc7d5e..3609109 100644 --- a/app/models/pager_tree/integrations/datadog/v3.rb +++ b/app/models/pager_tree/integrations/datadog/v3.rb @@ -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? @@ -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 diff --git a/app/views/pager_tree/integrations/datadog/v3/_form_options.html.erb b/app/views/pager_tree/integrations/datadog/v3/_form_options.html.erb index e69de29..a9c8edb 100644 --- a/app/views/pager_tree/integrations/datadog/v3/_form_options.html.erb +++ b/app/views/pager_tree/integrations/datadog/v3/_form_options.html.erb @@ -0,0 +1,7 @@ +
+
+ <%= form.check_box :option_support_retriggered_event, class: "form-checkbox" %> + <%= form.label :option_support_retriggered_event, class: "inline-block" %> +

<%== t(".option_support_retriggered_event_hint_html") %>

+
+
\ No newline at end of file diff --git a/app/views/pager_tree/integrations/datadog/v3/_show_options.html.erb b/app/views/pager_tree/integrations/datadog/v3/_show_options.html.erb index e69de29..c78a6bd 100644 --- a/app/views/pager_tree/integrations/datadog/v3/_show_options.html.erb +++ b/app/views/pager_tree/integrations/datadog/v3/_show_options.html.erb @@ -0,0 +1,12 @@ +
+
+ <%= t("activerecord.attributes.pager_tree/integrations/datadog/v3.option_support_retriggered_event") %> +
+
+
+

+ <%= render partial: "shared/components/badge_enabled", locals: { enabled: integration.option_support_retriggered_event } %> +

+
+
+
\ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 5947132..757f098 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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: @@ -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" diff --git a/test/models/pager_tree/integrations/datadog/v3_test.rb b/test/models/pager_tree/integrations/datadog/v3_test.rb index f21be7d..78fb81c 100644 --- a/test/models/pager_tree/integrations/datadog/v3_test.rb +++ b/test/models/pager_tree/integrations/datadog/v3_test.rb @@ -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 @@ -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