Class: Gitlab::AlertManagement::AlertParams

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/alert_management/alert_params.rb

Constant Summary collapse

MONITORING_TOOLS =
{
  prometheus: 'Prometheus'
}.freeze

Class Method Summary collapse

Class Method Details

.from_generic_alert(project:, payload:) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gitlab/alert_management/alert_params.rb', line 10

def self.from_generic_alert(project:, payload:)
  parsed_payload = Gitlab::Alerting::NotificationPayloadParser.call(payload, project).with_indifferent_access
  annotations = parsed_payload[:annotations]

  {
    project_id: project.id,
    title: annotations[:title],
    description: annotations[:description],
    monitoring_tool: annotations[:monitoring_tool],
    service: annotations[:service],
    hosts: Array(annotations[:hosts]),
    payload: payload,
    started_at: parsed_payload['startsAt'],
    severity: annotations[:severity],
    fingerprint: annotations[:fingerprint],
    environment: annotations[:environment]
  }
end

.from_prometheus_alert(project:, parsed_alert:) ⇒ Object


29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/gitlab/alert_management/alert_params.rb', line 29

def self.from_prometheus_alert(project:, parsed_alert:)
  {
    project_id: project.id,
    title: parsed_alert.title,
    description: parsed_alert.description,
    monitoring_tool: MONITORING_TOOLS[:prometheus],
    payload: parsed_alert.payload,
    started_at: parsed_alert.starts_at,
    ended_at: parsed_alert.ends_at,
    fingerprint: parsed_alert.gitlab_fingerprint,
    environment: parsed_alert.environment,
    prometheus_alert: parsed_alert.gitlab_alert
  }
end