Skip to content

Commit 0a3fa18

Browse files
authored
Alerting: Contact point schema based packing/unpacking (#2330)
* Improve test coverage * Support automated packing of nested schemas Previously schema packing was manual for both non-sensitive and sensitive fields. Sensitive fields were enumerated in `secureFields` and non-sensitive fields were packed/unpacked individually in their respective methods. This change creates functions packNotifier/unpackNotifier which packs and unpacks state according to the given schema. This should reduce maintenance burden keeping them in sync and allows the exceptions (ex. field aliases and type conversions) to be the sole purpose of the custom notifier pack/unpack methods. Only added to webhook for now. * Convert other notifiers to new pack/unpack logic and cleanup * Simplify redundant packing/unpacking logic * Remove support for nested schema packing/unpacking Since it's not used by anything yet, will add back when those new fields are introduced * Address PR comments
1 parent 2c668ac commit 0a3fa18

8 files changed

+1033
-1365
lines changed

examples/resources/grafana_contact_point/_acc_receiver_types.tf

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ resource "grafana_contact_point" "receiver_types" {
106106
message = "message"
107107
}
108108

109+
slack {
110+
endpoint_url = "http://custom-slack-endpoint"
111+
url = "http://custom-slack-url"
112+
recipient = "#channel"
113+
text = "message"
114+
title = "title"
115+
username = "bot"
116+
icon_emoji = ":icon:"
117+
icon_url = "http://domain/icon.png"
118+
mention_channel = "here"
119+
mention_users = "user"
120+
mention_groups = "group"
121+
color = "color"
122+
}
123+
109124
slack {
110125
endpoint_url = "http://custom-slack-url"
111126
token = "xoxb-token"
@@ -169,12 +184,6 @@ resource "grafana_contact_point" "receiver_types" {
169184
max_alerts = 100
170185
message = "Custom message"
171186
title = "Custom title"
172-
tls_config = {
173-
insecure_skip_verify = true
174-
ca_certificate = "ca.crt"
175-
client_certificate = "client.crt"
176-
client_key = "client.key"
177-
}
178187
}
179188

180189
wecom {

examples/resources/grafana_contact_point/_acc_receiver_types_10_2.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,13 @@ resource "grafana_contact_point" "receiver_types" {
1010
message = "Custom message"
1111
title = "Custom title"
1212
}
13+
oncall {
14+
url = "http://my-url"
15+
http_method = "POST"
16+
authorization_scheme = "Basic"
17+
authorization_credentials = "dXNlcjpwYXNzd29yZA=="
18+
max_alerts = 100
19+
message = "Custom message"
20+
title = "Custom title"
21+
}
1322
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
resource "grafana_contact_point" "receiver_types" {
2+
name = "Receiver Types since v11.4"
3+
4+
webhook {
5+
url = "http://my-url"
6+
http_method = "POST"
7+
basic_auth_user = "user"
8+
basic_auth_password = "password"
9+
max_alerts = 100
10+
message = "Custom message"
11+
title = "Custom title"
12+
tls_config = {
13+
insecure_skip_verify = true
14+
ca_certificate = "ca.crt"
15+
client_certificate = "client.crt"
16+
client_key = "client.key"
17+
}
18+
}
19+
20+
webhook {
21+
url = "http://my-url"
22+
http_method = "POST"
23+
authorization_scheme = "Basic"
24+
authorization_credentials = "dXNlcjpwYXNzd29yZA=="
25+
max_alerts = 100
26+
message = "Custom message"
27+
title = "Custom title"
28+
tls_config = {
29+
insecure_skip_verify = true
30+
ca_certificate = "ca.crt"
31+
client_certificate = "client.crt"
32+
client_key = "client.key"
33+
}
34+
}
35+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
resource "grafana_contact_point" "receiver_types" {
2+
name = "Receiver Types since v9.3"
3+
4+
victorops {
5+
url = "http://victor-ops-url"
6+
message_type = "CRITICAL"
7+
title = "title"
8+
description = "description"
9+
}
10+
11+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
resource "grafana_contact_point" "minimal_receivers" {
2+
name = "Minimal Receivers"
3+
4+
alertmanager {
5+
url = "http://my-am"
6+
}
7+
8+
dingding {
9+
url = "http://dingding-url"
10+
}
11+
12+
discord {
13+
url = "http://discord-url"
14+
}
15+
16+
email {
17+
18+
}
19+
20+
googlechat {
21+
url = "http://googlechat-url"
22+
}
23+
24+
kafka {
25+
rest_proxy_url = "http://kafka-rest-proxy-url"
26+
topic = "mytopic"
27+
}
28+
29+
line {
30+
token = "token"
31+
}
32+
33+
oncall {
34+
url = "http://oncall-url"
35+
}
36+
37+
opsgenie {
38+
api_key = "token"
39+
}
40+
41+
pagerduty {
42+
integration_key = "token"
43+
}
44+
45+
pushover {
46+
user_key = "userkey"
47+
api_token = "token"
48+
}
49+
50+
sensugo {
51+
url = "http://sensugo-url"
52+
api_key = "key"
53+
}
54+
55+
slack {
56+
token = "xoxb-token"
57+
recipient = "#channel"
58+
}
59+
60+
slack {
61+
url = "http://custom-slack-url"
62+
}
63+
64+
teams {
65+
url = "http://teams-webhook"
66+
}
67+
68+
telegram {
69+
token = "token"
70+
chat_id = "chat-id"
71+
}
72+
73+
threema {
74+
gateway_id = "*gateway"
75+
recipient_id = "*target1"
76+
api_secret = "secret"
77+
}
78+
79+
victorops {
80+
url = "http://victor-ops-url"
81+
}
82+
83+
webex {
84+
token = "token"
85+
room_id = "room_id"
86+
}
87+
88+
webhook {
89+
url = "http://webhook-url"
90+
}
91+
92+
wecom {
93+
url = "http://wecom-url"
94+
}
95+
96+
wecom {
97+
secret = "secret"
98+
corp_id = "corp_id"
99+
agent_id = "agent_id"
100+
}
101+
}

0 commit comments

Comments
 (0)