Class: RailsErrorDashboard::Services::BaselineAlertPayloadBuilder
- Inherits:
-
Object
- Object
- RailsErrorDashboard::Services::BaselineAlertPayloadBuilder
- Defined in:
- lib/rails_error_dashboard/services/baseline_alert_payload_builder.rb
Overview
Pure algorithm: Build notification payloads for baseline anomaly alerts
No HTTP calls — accepts error + anomaly data, returns platform-specific Hashes.
Constant Summary collapse
- ANOMALY_EMOJIS =
{ critical: "🔴", high: "🟠", elevated: "🟡" }.freeze
- ANOMALY_COLORS =
{ critical: 15158332, # Red high: 16744192, # Orange elevated: 16776960 # Yellow }.freeze
- DEFAULT_EMOJI =
"⚪"- DEFAULT_COLOR =
Gray
9807270
Class Method Summary collapse
-
.anomaly_color(level) ⇒ Integer
Discord color integer.
-
.anomaly_emoji(level) ⇒ String
Emoji.
-
.discord_payload(error_log, anomaly_data) ⇒ Hash
Build Discord embed payload for baseline anomaly.
-
.slack_payload(error_log, anomaly_data) ⇒ Hash
Build Slack Block Kit payload for baseline anomaly.
-
.webhook_payload(error_log, anomaly_data) ⇒ Hash
Build generic webhook payload for baseline anomaly.
Class Method Details
.anomaly_color(level) ⇒ Integer
Returns Discord color integer.
156 157 158 |
# File 'lib/rails_error_dashboard/services/baseline_alert_payload_builder.rb', line 156 def self.anomaly_color(level) ANOMALY_COLORS[level] || DEFAULT_COLOR end |
.anomaly_emoji(level) ⇒ String
Returns Emoji.
150 151 152 |
# File 'lib/rails_error_dashboard/services/baseline_alert_payload_builder.rb', line 150 def self.anomaly_emoji(level) ANOMALY_EMOJIS[level] || DEFAULT_EMOJI end |
.discord_payload(error_log, anomaly_data) ⇒ Hash
Build Discord embed payload for baseline anomaly
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/rails_error_dashboard/services/baseline_alert_payload_builder.rb', line 100 def self.discord_payload(error_log, anomaly_data) { embeds: [ { title: "🚨 Baseline Anomaly Detected", color: anomaly_color(anomaly_data[:level]), fields: [ { name: "Error Type", value: error_log.error_type, inline: true }, { name: "Platform", value: error_log.platform, inline: true }, { name: "Severity", value: anomaly_data[:level].to_s.upcase, inline: true }, { name: "Standard Deviations", value: "#{anomaly_data[:std_devs_above]&.round(1)}σ above baseline", inline: true }, { name: "Threshold", value: "#{anomaly_data[:threshold]&.round(1)} errors", inline: true }, { name: "Baseline Type", value: anomaly_data[:baseline_type] || "N/A", inline: true }, { name: "Message", value: "```#{NotificationHelpers.(error_log., 200)}```", inline: false } ], url: NotificationHelpers.dashboard_url(error_log), timestamp: Time.current.iso8601 } ] } end |
.slack_payload(error_log, anomaly_data) ⇒ Hash
Build Slack Block Kit payload for baseline anomaly
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 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 |
# File 'lib/rails_error_dashboard/services/baseline_alert_payload_builder.rb', line 33 def self.slack_payload(error_log, anomaly_data) { text: "🚨 Baseline Anomaly Alert", blocks: [ { type: "header", text: { type: "plain_text", text: "🚨 Baseline Anomaly Detected" } }, { type: "section", fields: [ { type: "mrkdwn", text: "*Error Type:*\n#{error_log.error_type}" }, { type: "mrkdwn", text: "*Platform:*\n#{error_log.platform}" }, { type: "mrkdwn", text: "*Severity:*\n#{anomaly_emoji(anomaly_data[:level])} #{anomaly_data[:level].to_s.upcase}" }, { type: "mrkdwn", text: "*Standard Deviations:*\n#{anomaly_data[:std_devs_above]&.round(1)}σ above baseline" } ] }, { type: "section", text: { type: "mrkdwn", text: "*Message:*\n```#{NotificationHelpers.(error_log., 200)}```" } }, { type: "section", text: { type: "mrkdwn", text: "*Baseline Info:*\nThreshold: #{anomaly_data[:threshold]&.round(1)} errors\nBaseline Type: #{anomaly_data[:baseline_type]}" } }, { type: "actions", elements: [ { type: "button", text: { type: "plain_text", text: "View in Dashboard" }, url: NotificationHelpers.dashboard_url(error_log) } ] } ] } end |
.webhook_payload(error_log, anomaly_data) ⇒ Hash
Build generic webhook payload for baseline anomaly
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/rails_error_dashboard/services/baseline_alert_payload_builder.rb', line 126 def self.webhook_payload(error_log, anomaly_data) { event: "baseline_anomaly", timestamp: Time.current.iso8601, error: { id: error_log.id, type: error_log.error_type, message: error_log., platform: error_log.platform, severity: error_log.severity.to_s, occurred_at: error_log.occurred_at.iso8601 }, anomaly: { level: anomaly_data[:level].to_s, std_devs_above: anomaly_data[:std_devs_above], threshold: anomaly_data[:threshold], baseline_type: anomaly_data[:baseline_type] }, dashboard_url: NotificationHelpers.dashboard_url(error_log) } end |