83 lines
3.2 KiB
Markdown
83 lines
3.2 KiB
Markdown
# Modules for Grafana alerts and dashboards
|
|
|
|
## Alerting
|
|
|
|
Please check documentation about Grafana alerting [here](https://itdoc.schwarz/x/X11nf) and [official documentation](https://grafana.com/docs/grafana/latest/alerting/) for deeper look.
|
|
|
|
The Terraform modules are separated per resource type, check README in each module directory for spefic examples.
|
|
Below is example for alerts using „**Prometheus/Thanos**“ datasorce and sending notification to „**Google Chat**“.
|
|
|
|
|
|
|
|
```hcl title="main.tf"
|
|
# Datasource
|
|
module "datasource" {
|
|
source = "git::https://commerce-platform.git.onstackit.cloud/commerce-platform-public/terraform-modules//grafana/datasource?ref=main"
|
|
datasource_name = "Thanos - Myteam"
|
|
datasource_url = var.datasource_url
|
|
datasource_username = var.datasource_username
|
|
datasource_password = var.datasource_password
|
|
}
|
|
|
|
# Alert Receiver / Contact Point
|
|
module "gchat-contact-point" {
|
|
source = "git::https://commerce-platform.git.onstackit.cloud/commerce-platform-public/terraform-modules//grafana/contact-point-gchat?ref=main"
|
|
gchat-url = var.google_chat_url
|
|
contact-point-name = "gchat"
|
|
}
|
|
|
|
|
|
# Alert Rule Folders
|
|
module "alert-folder" {
|
|
source = "git::https://commerce-platform.git.onstackit.cloud/commerce-platform-public/terraform-modules//grafana/alert-folder?ref=main"
|
|
alert-folder = "Alerts"
|
|
}
|
|
|
|
|
|
# Template for messages
|
|
module "message-templates" {
|
|
source = "git::https://commerce-platform.git.onstackit.cloud/commerce-platform-public/terraform-modules//grafana/message-template?ref=main"
|
|
templates_dir = "templates"
|
|
disable_provenance = true
|
|
}
|
|
|
|
# Notification policies
|
|
module "notification-policy" {
|
|
source = "git::https://commerce-platform.git.onstackit.cloud/commerce-platform-public/terraform-modules//grafana/notification-policy?ref=main"
|
|
|
|
default_contact_point_uid = module.gchat-contact-point.contact_name
|
|
group_by = ["alertname"]
|
|
|
|
folder_policies = {
|
|
"Alerts" = module.gchat-contact-point.contact_name
|
|
}
|
|
}
|
|
|
|
# Alert definition
|
|
module "alerting" {
|
|
source = "git::https://commerce-platform.git.onstackit.cloud/commerce-platform-public/terraform-modules//grafana/alerts?ref=main"
|
|
|
|
alerts_dir = "alerts"
|
|
default_datasource_uid = module.datasource.datasource_uid
|
|
default_receiver = module.gchat-contact-point.contact_name
|
|
default_folder_uid = module.alert-folder.folder_uid
|
|
default_interval_seconds = 60
|
|
disable_provenance = true
|
|
}
|
|
```
|
|
With this configuration you need to place your notification templates into `templates` folder and alert definitions in YAML format to `alerts` folder in same directoty where `main.tf`is located.
|
|
You can example for both in [examples](./examples/) folder.
|
|
For this example you need export your secret variables e.g. with lookup in Secret Manager.
|
|
|
|
```sh
|
|
export TF_VAR_grafana_url="<GRAFANA URL>"
|
|
export TF_VAR_grafana_username="admin"
|
|
export TF_VAR_grafana_password="xxxxxxx"
|
|
export TF_VAR_google_chat_url="https://chat.googleapis.com/v1/spaces/xxxxx"
|
|
export TF_VAR_datasource_url="https://xxxxx.stackit.cloud/instances/xxxxxx"
|
|
export TF_VAR_datasource_username="stackit9_xxxxx"
|
|
export TF_VAR_datasource_password="xxxxxx"
|
|
```
|
|
|
|
## Dashboard
|
|
TODO
|