1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# frozen_string_literal: true
module QA
module Flow
module AlertSettings
extend self
def go_to_monitor_settings
Page::Project::Menu.perform(&:go_to_monitor_settings)
end
def setup_http_endpoint_integration(integration_name: random_word)
Page::Project::Settings::Monitor.perform do |setting|
setting.expand_alerts do |alert|
alert.add_new_integration
alert.select_http_endpoint
alert.enter_integration_name(integration_name)
alert.activate_integration
alert.save_and_create_alert
end
end
end
def setup_prometheus_integration
Page::Project::Settings::Monitor.perform do |setting|
setting.expand_alerts do |alert|
alert.add_new_integration
alert.select_prometheus
alert.activate_integration
alert.save_and_create_alert
end
end
end
def send_test_alert(integration_type: 'http', payload: nil)
payload ||= integration_type == 'http' ? http_payload : prometheus_payload
Page::Project::Settings::Alerts.perform do |alert|
alert.fill_in_test_payload(payload.to_json)
alert.send_test_alert
end
end
def integration_credentials
credentials = {}
Page::Project::Settings::Alerts.perform do |alert|
alert.go_to_view_credentials
credentials = { url: alert.webhook_url, auth_key: alert.authorization_key }
end
credentials
end
def enable_create_incident
Page::Project::Settings::Monitor.perform do |setting|
setting.expand_alerts do |alert|
alert.go_to_alert_settings
alert.enable_incident_for_alert
alert.save_alert_settings
alert.click_button('Collapse')
end
end
end
def enable_email_notification
Page::Project::Settings::Monitor.perform do |setting|
setting.expand_alerts do |alert|
alert.go_to_alert_settings
alert.enable_email_notification
alert.save_alert_settings
alert.click_button('Collapse')
end
end
end
private
def random_word
Faker::Lorem.word
end
def http_payload
{ title: random_word, description: random_word }
end
def prometheus_payload
{
version: '4',
groupKey: nil,
status: 'firing',
receiver: '',
groupLabels: {},
commonLabels: {},
commonAnnotations: {},
externalURL: '',
alerts: [
{
startsAt: Time.now,
generatorURL: Faker::Internet.url,
endsAt: nil,
status: 'firing',
labels: { gitlab_environment_name: Faker::Lorem.word },
annotations:
{
title: random_word,
gitlab_y_label: 'status'
}
}
]
}
end
end
end
end
|