summaryrefslogtreecommitdiff
path: root/app/serializers/prometheus_alert_entity.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/serializers/prometheus_alert_entity.rb')
-rw-r--r--app/serializers/prometheus_alert_entity.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/app/serializers/prometheus_alert_entity.rb b/app/serializers/prometheus_alert_entity.rb
new file mode 100644
index 00000000000..413be511903
--- /dev/null
+++ b/app/serializers/prometheus_alert_entity.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class PrometheusAlertEntity < Grape::Entity
+ include RequestAwareEntity
+
+ expose :id
+ expose :title
+ expose :query
+ expose :threshold
+
+ expose :operator do |prometheus_alert|
+ prometheus_alert.computed_operator
+ end
+
+ expose :alert_path do |prometheus_alert|
+ project_prometheus_alert_path(prometheus_alert.project, prometheus_alert.prometheus_metric_id, environment_id: prometheus_alert.environment.id, format: :json)
+ end
+
+ private
+
+ alias_method :prometheus_alert, :object
+
+ def can_read_prometheus_alerts?
+ can?(request.current_user, :read_prometheus_alerts, prometheus_alert.project)
+ end
+end