Class: OutgoingWebhook::V3
- Inherits:
-
Integration
- Object
- Integration
- OutgoingWebhook::V3
- Defined in:
- app/models/pager_tree/integrations/outgoing_webhook/v3.rb
Constant Summary collapse
- OPTIONS =
[ {key: :webhook_url, type: :string, default: nil}, {key: :username, type: :string, default: nil}, {key: :password, type: :string, default: nil}, {key: :alert_created, type: :boolean, default: false}, {key: :alert_open, type: :boolean, default: false}, {key: :alert_acknowledged, type: :boolean, default: false}, {key: :alert_rejected, type: :boolean, default: false}, {key: :alert_timeout, type: :boolean, default: false}, {key: :alert_resolved, type: :boolean, default: false}, {key: :alert_dropped, type: :boolean, default: false}, {key: :alert_handoff, type: :boolean, default: false}, {key: :template, type: :string, default: nil}, {key: :send_linked, type: :boolean, default: false}, {key: :outgoing_rules, type: :string, default: nil} ]
Instance Method Summary collapse
- #adapter_outgoing_interest?(event_name) ⇒ Boolean
- #adapter_process_outgoing ⇒ Object
- #adapter_show_outgoing_webhook_delivery? ⇒ Boolean
- #adapter_supports_description_template? ⇒ Boolean
- #adapter_supports_outgoing? ⇒ Boolean
- #adapter_supports_title_template? ⇒ Boolean
Instance Method Details
#adapter_outgoing_interest?(event_name) ⇒ Boolean
62 63 64 |
# File 'app/models/pager_tree/integrations/outgoing_webhook/v3.rb', line 62 def adapter_outgoing_interest?(event_name) try("option_#{event_name}") || false end |
#adapter_process_outgoing ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/models/pager_tree/integrations/outgoing_webhook/v3.rb', line 66 def adapter_process_outgoing body = nil event_type = adapter_outgoing_event.event_name.to_s.tr("_", ".") # Do the custom templating portion for outgoing hooks if self.option_template.present? begin body = JSON.parse((self.option_template, { alert: adapter_outgoing_event.alert.try(:v3_format) || adapter_outgoing_event.alert, event: { type: event_type } })) rescue JSON::ParserError => e logs.create(message: "Error parsing JSON, abort custom format for option template. Error: #{e.}") rescue => e Rails.logger.error "Error while processing option_template for #{id}: #{e.}" end end body ||= { data: adapter_outgoing_event.alert.try(:v3_format) || adapter_outgoing_event.alert, type: event_type } url = adapter_outgoing_event.outgoing_rules_data.dig("webhook_url") || option_webhook_url body.merge!(adapter_outgoing_event.outgoing_rules_data.except("webhook_url")) outgoing_webhook_delivery = OutgoingWebhookDelivery.factory( resource: self, url: url, auth: {username: option_username, password: option_password}, body: body ) outgoing_webhook_delivery.save! outgoing_webhook_delivery.deliver_later outgoing_webhook_delivery end |
#adapter_show_outgoing_webhook_delivery? ⇒ Boolean
50 51 52 |
# File 'app/models/pager_tree/integrations/outgoing_webhook/v3.rb', line 50 def adapter_show_outgoing_webhook_delivery? true end |
#adapter_supports_description_template? ⇒ Boolean
58 59 60 |
# File 'app/models/pager_tree/integrations/outgoing_webhook/v3.rb', line 58 def adapter_supports_description_template? false end |
#adapter_supports_outgoing? ⇒ Boolean
46 47 48 |
# File 'app/models/pager_tree/integrations/outgoing_webhook/v3.rb', line 46 def adapter_supports_outgoing? true end |
#adapter_supports_title_template? ⇒ Boolean
54 55 56 |
# File 'app/models/pager_tree/integrations/outgoing_webhook/v3.rb', line 54 def adapter_supports_title_template? false end |