Class: QueuePulse::Notifiers::Webhook
- Defined in:
- lib/queue_pulse/notifiers/webhook.rb
Overview
Posts alerts as JSON to an arbitrary endpoint. Useful for piping into your own systems, PagerDuty Events API, Discord, etc.
Constant Summary
Constants inherited from Base
Base::MAX_RETRIES, Base::OPEN_TIMEOUT, Base::READ_TIMEOUT
Instance Method Summary collapse
- #deliver(alerts) ⇒ Object
-
#initialize(url:, headers: {}) ⇒ Webhook
constructor
A new instance of Webhook.
- #payload(alerts) ⇒ Object
Constructor Details
#initialize(url:, headers: {}) ⇒ Webhook
Returns a new instance of Webhook.
8 9 10 11 12 |
# File 'lib/queue_pulse/notifiers/webhook.rb', line 8 def initialize(url:, headers: {}) super() @url = url @headers = headers end |
Instance Method Details
#deliver(alerts) ⇒ Object
14 15 16 17 18 |
# File 'lib/queue_pulse/notifiers/webhook.rb', line 14 def deliver(alerts) return if alerts.empty? post_json(@url, payload(alerts), headers: @headers) end |
#payload(alerts) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/queue_pulse/notifiers/webhook.rb', line 20 def payload(alerts) { source: "queue_pulse", version: QueuePulse::VERSION, alerts: alerts.map(&:to_h) } end |