debian-mirror-gitlab/app/services/system_notes/alert_management_service.rb

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

68 lines
2.1 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
module SystemNotes
class AlertManagementService < ::SystemNotes::BaseService
2020-11-24 15:15:51 +05:30
# Called when the a new AlertManagement::Alert has been created
#
# alert - AlertManagement::Alert object.
#
# Example Note text:
#
# "GitLab Alert Bot logged an alert from Prometheus"
#
# Returns the created Note object
def create_new_alert(monitoring_tool)
body = "logged an alert from **#{monitoring_tool}**"
create_note(NoteSummary.new(noteable, project, User.alert_bot, body, action: 'new_alert_added'))
end
2020-07-28 23:09:34 +05:30
# Called when the status of an AlertManagement::Alert has changed
#
# alert - AlertManagement::Alert object.
#
# Example Note text:
#
# "changed the status to Acknowledged"
2022-04-04 11:22:00 +05:30
# "changed the status to Acknowledged by changing the incident status of #540"
2020-07-28 23:09:34 +05:30
#
# Returns the created Note object
2022-04-04 11:22:00 +05:30
def change_alert_status(reason)
status = noteable.state.to_s.titleize
body = "changed the status to **#{status}**#{reason}"
2020-07-28 23:09:34 +05:30
create_note(NoteSummary.new(noteable, project, author, body, action: 'status'))
end
# Called when an issue is created based on an AlertManagement::Alert
#
# issue - Issue object.
#
# Example Note text:
#
2022-04-04 11:22:00 +05:30
# "created incident #17 for this alert"
2020-07-28 23:09:34 +05:30
#
# Returns the created Note object
2020-10-24 23:57:45 +05:30
def new_alert_issue(issue)
2022-04-04 11:22:00 +05:30
body = "created incident #{issue.to_reference(project)} for this alert"
2020-07-28 23:09:34 +05:30
create_note(NoteSummary.new(noteable, project, author, body, action: 'alert_issue_added'))
end
2020-10-24 23:57:45 +05:30
2021-04-17 20:07:23 +05:30
# Called when an alert is resolved due to received resolving alert payload
#
# alert - AlertManagement::Alert object.
#
# Example Note text:
#
# "changed the status to Resolved by closing issue #17"
#
# Returns the created Note object
def log_resolving_alert(monitoring_tool)
2021-04-29 21:17:54 +05:30
body = "logged a recovery alert from **#{monitoring_tool}**"
2021-04-17 20:07:23 +05:30
create_note(NoteSummary.new(noteable, project, User.alert_bot, body, action: 'new_alert_added'))
end
2020-07-28 23:09:34 +05:30
end
end