2020-05-24 23:13:21 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module AlertManagement
|
|
|
|
class AlertParams
|
|
|
|
MONITORING_TOOLS = {
|
|
|
|
prometheus: 'Prometheus'
|
|
|
|
}.freeze
|
|
|
|
|
|
|
|
def self.from_generic_alert(project:, payload:)
|
2020-07-28 23:09:34 +05:30
|
|
|
parsed_payload = Gitlab::Alerting::NotificationPayloadParser.call(payload, project).with_indifferent_access
|
2020-05-24 23:13:21 +05:30
|
|
|
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'],
|
2020-06-23 00:09:42 +05:30
|
|
|
severity: annotations[:severity],
|
|
|
|
fingerprint: annotations[:fingerprint]
|
2020-05-24 23:13:21 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
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,
|
2020-07-28 23:09:34 +05:30
|
|
|
fingerprint: parsed_alert.gitlab_fingerprint,
|
|
|
|
environment: parsed_alert.environment,
|
|
|
|
prometheus_alert: parsed_alert.gitlab_alert
|
2020-05-24 23:13:21 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|