Skip to content

Commit ee29cd1

Browse files
authored
Alerting: Update webhook receiver with http_config, headers, and payload (#2331)
* Add support for nested schema packing/unpacking * Support http_config for webhooks Adds support for http_config in a way that is easily extendable to other notifiers when they gain support as well. * Support custom headers and payload for webhooks * Generate docs * Linting
1 parent a268948 commit ee29cd1

File tree

6 files changed

+848
-31
lines changed

6 files changed

+848
-31
lines changed

docs/resources/contact_point.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,9 +523,12 @@ Optional:
523523
- `basic_auth_password` (String, Sensitive) The username to use in basic auth headers attached to the request. If omitted, basic auth will not be used.
524524
- `basic_auth_user` (String) The username to use in basic auth headers attached to the request. If omitted, basic auth will not be used.
525525
- `disable_resolve_message` (Boolean) Whether to disable sending resolve messages. Defaults to `false`.
526+
- `headers` (Map of String) Custom headers to attach to the request.
527+
- `http_config` (Block Set, Max: 1) Common HTTP client options. (see [below for nested schema](#nestedblock--webhook--http_config))
526528
- `http_method` (String) The HTTP method to use in the request. Defaults to `POST`.
527529
- `max_alerts` (Number) The maximum number of alerts to send in a single request. This can be helpful in limiting the size of the request body. The default is 0, which indicates no limit.
528530
- `message` (String) Custom message. You can use template variables.
531+
- `payload` (Block Set, Max: 1) Optionally provide a templated payload. Overrides 'Message' and 'Title' field. (see [below for nested schema](#nestedblock--webhook--payload))
529532
- `settings` (Map of String, Sensitive) Additional custom properties to attach to the notifier. Defaults to `map[]`.
530533
- `title` (String) Templated title of the message.
531534
- `tls_config` (Map of String, Sensitive) Allows configuring TLS for the webhook notifier.
@@ -534,6 +537,65 @@ Read-Only:
534537

535538
- `uid` (String) The UID of the contact point.
536539

540+
<a id="nestedblock--webhook--http_config"></a>
541+
### Nested Schema for `webhook.http_config`
542+
543+
Optional:
544+
545+
- `oauth2` (Block Set, Max: 1) OAuth2 configuration options. (see [below for nested schema](#nestedblock--webhook--http_config--oauth2))
546+
547+
<a id="nestedblock--webhook--http_config--oauth2"></a>
548+
### Nested Schema for `webhook.http_config.oauth2`
549+
550+
Required:
551+
552+
- `client_id` (String) Client ID to use when authenticating.
553+
- `client_secret` (String, Sensitive) Client secret to use when authenticating.
554+
- `token_url` (String) URL for the access token endpoint.
555+
556+
Optional:
557+
558+
- `endpoint_params` (Map of String) Optional parameters to append to the access token request.
559+
- `proxy_config` (Block Set, Max: 1) Optional proxy configuration for OAuth2 requests. (see [below for nested schema](#nestedblock--webhook--http_config--oauth2--proxy_config))
560+
- `scopes` (List of String) Optional scopes to request when obtaining an access token.
561+
- `tls_config` (Block Set, Max: 1) Optional TLS configuration options for OAuth2 requests. (see [below for nested schema](#nestedblock--webhook--http_config--oauth2--tls_config))
562+
563+
<a id="nestedblock--webhook--http_config--oauth2--proxy_config"></a>
564+
### Nested Schema for `webhook.http_config.oauth2.proxy_config`
565+
566+
Optional:
567+
568+
- `no_proxy` (String) Comma-separated list of addresses that should not use a proxy.
569+
- `proxy_connect_header` (Map of String) Optional headers to send to proxies during CONNECT requests.
570+
- `proxy_from_environment` (Boolean) Use environment HTTP_PROXY, HTTPS_PROXY and NO_PROXY to determine proxies. Defaults to `false`.
571+
- `proxy_url` (String) HTTP proxy server to use to connect to the targets.
572+
573+
574+
<a id="nestedblock--webhook--http_config--oauth2--tls_config"></a>
575+
### Nested Schema for `webhook.http_config.oauth2.tls_config`
576+
577+
Optional:
578+
579+
- `ca_certificate` (String, Sensitive) Certificate in PEM format to use when verifying the server's certificate chain.
580+
- `client_certificate` (String, Sensitive) Client certificate in PEM format to use when connecting to the server.
581+
- `client_key` (String, Sensitive) Client key in PEM format to use when connecting to the server.
582+
- `insecure_skip_verify` (Boolean) Do not verify the server's certificate chain and host name. Defaults to `false`.
583+
584+
585+
586+
587+
<a id="nestedblock--webhook--payload"></a>
588+
### Nested Schema for `webhook.payload`
589+
590+
Required:
591+
592+
- `template` (String) Custom payload template.
593+
594+
Optional:
595+
596+
- `vars` (Map of String) Optionally provide a variables to be used in the payload template. They will be available in the template as `.Vars.<variable_name>`.
597+
598+
537599

538600
<a id="nestedblock--wecom"></a>
539601
### Nested Schema for `wecom`
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
resource "grafana_contact_point" "receiver_types" {
2+
name = "Receiver Types since v12.0"
3+
4+
webhook {
5+
url = "http://my-url"
6+
headers = {
7+
Content-Type = "test-content-type"
8+
X-Test-Header = "test-header-value"
9+
}
10+
payload {
11+
template = "{{ .Receiver }}: {{ .Vars.var1 }}"
12+
vars = {
13+
var1 = "variable value"
14+
}
15+
}
16+
}
17+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
resource "grafana_contact_point" "receiver_types" {
2+
name = "Receiver Types since v12.1"
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+
http_config {
19+
oauth2 {
20+
client_id = "client_id"
21+
client_secret = "client_secret"
22+
token_url = "http://oauth2-token-url"
23+
scopes = ["scope1", "scope2"]
24+
endpoint_params = {
25+
"param1" = "value1"
26+
"param2" = "value2"
27+
}
28+
proxy_config {
29+
proxy_url = "http://proxy-url"
30+
proxy_from_environment = false
31+
no_proxy = "localhost"
32+
proxy_connect_header = {
33+
"X-Proxy-Header" = "proxy-value"
34+
}
35+
}
36+
tls_config {
37+
insecure_skip_verify = true
38+
ca_certificate = <<EOF
39+
-----BEGIN CERTIFICATE-----
40+
MIGrMF+gAwIBAgIBATAFBgMrZXAwADAeFw0yNDExMTYxMDI4MzNaFw0yNTExMTYx
41+
MDI4MzNaMAAwKjAFBgMrZXADIQCf30GvRnHbs9gukA3DLXDK6W5JVgYw6mERU/60
42+
2M8+rjAFBgMrZXADQQCGmeaRp/AcjeqmJrF5Yh4d7aqsMSqVZvfGNDc0ppXyUgS3
43+
WMQ1+3T+/pkhU612HR0vFd3vyFhmB4yqFoNV8RML
44+
-----END CERTIFICATE-----
45+
EOF
46+
client_certificate = <<EOF
47+
-----BEGIN CERTIFICATE-----
48+
MIIBhTCCASugAwIBAgIQIRi6zePL6mKjOipn+dNuaTAKBggqhkjOPQQDAjASMRAw
49+
DgYDVQQKEwdBY21lIENvMB4XDTE3MTAyMDE5NDMwNloXDTE4MTAyMDE5NDMwNlow
50+
EjEQMA4GA1UEChMHQWNtZSBDbzBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABD0d
51+
7VNhbWvZLWPuj/RtHFjvtJBEwOkhbN/BnnE8rnZR8+sbwnc/KhCk3FhnpHZnQz7B
52+
5aETbbIgmuvewdjvSBSjYzBhMA4GA1UdDwEB/wQEAwICpDATBgNVHSUEDDAKBggr
53+
BgEFBQcDATAPBgNVHRMBAf8EBTADAQH/MCkGA1UdEQQiMCCCDmxvY2FsaG9zdDo1
54+
NDUzgg4xMjcuMC4wLjE6NTQ1MzAKBggqhkjOPQQDAgNIADBFAiEA2zpJEPQyz6/l
55+
Wf86aX6PepsntZv2GYlA5UpabfT2EZICICpJ5h/iI+i341gBmLiAFQOyTDT+/wQc
56+
6MF9+Yw1Yy0t
57+
-----END CERTIFICATE-----
58+
EOF
59+
client_key = <<EOF
60+
-----BEGIN EC PRIVATE KEY-----
61+
MHcCAQEEIIrYSSNQFaA2Hwf1duRSxKtLYX5CB04fSeQ6tF1aY/PuoAoGCCqGSM49
62+
AwEHoUQDQgAEPR3tU2Fta9ktY+6P9G0cWO+0kETA6SFs38GecTyudlHz6xvCdz8q
63+
EKTcWGekdmdDPsHloRNtsiCa697B2O9IFA==
64+
-----END EC PRIVATE KEY-----
65+
EOF
66+
}
67+
}
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)