debian-mirror-gitlab/app/controllers/projects/prometheus/alerts_controller.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

65 lines
1.6 KiB
Ruby
Raw Normal View History

2020-04-22 19:07:51 +05:30
# frozen_string_literal: true
module Projects
module Prometheus
class AlertsController < Projects::ApplicationController
include MetricsDashboard
respond_to :json
protect_from_forgery except: [:notify]
skip_before_action :project, only: [:notify]
prepend_before_action :repository, :project_without_auth, only: [:notify]
before_action :authorize_read_prometheus_alerts!, except: [:notify]
2022-07-23 23:45:48 +05:30
before_action :alert, only: [:metrics_dashboard]
2020-04-22 19:07:51 +05:30
2021-02-22 17:27:13 +05:30
feature_category :incident_management
2022-07-16 23:28:13 +05:30
urgency :low
2021-01-03 14:25:43 +05:30
2020-04-22 19:07:51 +05:30
def notify
token = extract_alert_manager_token(request)
result = notify_service.execute(token)
2023-01-13 00:05:48 +05:30
head result.http_status
2020-04-22 19:07:51 +05:30
end
private
def notify_service
Projects::Prometheus::Alerts::NotifyService
2021-02-22 17:27:13 +05:30
.new(project, params.permit!)
2020-04-22 19:07:51 +05:30
end
def alert
@alert ||= alerts_finder(metric: params[:id]).execute.first || render_404
end
def alerts_finder(opts = {})
Projects::Prometheus::AlertsFinder.new({
project: project,
environment: params[:environment_id]
}.reverse_merge(opts))
end
def extract_alert_manager_token(request)
Doorkeeper::OAuth::Token.from_bearer_authorization(request)
end
def project_without_auth
@project ||= Project
.find_by_full_path("#{params[:namespace_id]}/#{params[:project_id]}")
end
def metrics_dashboard_params
{
embedded: true,
prometheus_alert_id: alert.id
}
end
end
end
end