Custom Template Alertmanager (NGOT)#
This documentation describes how to:
- use the default template
- add a notification template
Before starting, we will export the variables below and modify the values based on your needs:
export GIT_PATH="$HOME/git/"
export TEMPLATE_NAME="XXX.tmpl"
export TEMPLATE_PATH=</template/path/where/is/located/$TEMPLATE_NAME>
export ZONE=<service_zone_monitoring> # example: "svc-monitoring-stack-client-test05"
export PRODUCT=$(sd get zones | jq -r --arg z "$ZONE" '."\($z)".product')
export LINE=$(sd get zones | jq -r --arg z "$ZONE" '."\($z)".metadata.line')
export CONTRACT=$(sd get zones | jq -r --arg z "$ZONE" '."\($z)".contract_zone_name')
export CLIENT=$(sd get zones | jq -r --arg c "$CONTRACT" '."\($c)".client_name')
Using the default notification template#
Envs-ng#
Add the default template in the client service zone definition, then deploy.
Edit the client zone file : "$ENVS_NG_PATH/zones/ngot_zones/client-$CLIENT.cue"
Then, in "svc-monitoring-stack-client-$CLIENT"."monitoring-stack".alertmanager.notifications_targets, add the following lines:
#MonitoringStackNotificationsTargetMail & {
name: "mail-XXX"
receiver: {
to: "XXX"
}
}
generate-static-zones-files
trackbone plan -z $ZONE -c alertmanager
git pull
git switch -c "template_for_$CONTRACT"
git add ../../gen/ "client-$CLIENT.cue"
git commit -m "PRD: NGOT: alertmanager: add notification template for $CONTRACT"
git push
Request a review and follow the normal change procedure to apply the alertmanager configuration.
Adding a notification template#
Helm Chart#
The notification template in .tmpl format must be added in the Alertmanager repository in a custom notifications_templates directory:
cd "$GIT_PATH/caascad/applications/caascad-alertmanager/helm/alertmanager-v2/"
mkdir "notifications_templates/$PRODUCT/$LINE/$CONTRACT"
cp "$TEMPLATE_PATH" "notifications_templates/$PRODUCT/$LINE/$CONTRACT"
Before committing/pushing the template, it is preferable to check the file contents and ensure that it does not contain trailing spaces so that the ConfigMap indentation is correct:
git switch -c "template_for_$CONTRACT"
git add "notifications_templates/$PRODUCT/$LINE/$CONTRACT"
git commit -m "alertmanager-v2: add notification template for $CONTRACT"
git push
Request a review, then merge.
Envs-ng#
Add the template name in the client service zone definition, then deploy.
Edit the client zone file : "$ENVS_NG_PATH/zones/ngot_zones/client-$CLIENT.cue"
Then, in "svc-monitoring-stack-client-$CLIENT"."monitoring-stack".alertmanager.notifications_targets, add the following lines:
// html and headers values should be retrieved in the template file.
#MonitoringStackNotificationsTargetMail & {
name: "mail-XXX"
template_name: "\(contract_zone_name)/$TEMPLATE_NAME"
receiver: {
to: "XXX"
html: "{{ template \"XXX\" . }}"
headers: {
subject: "{{ template \"XXX\" . }}"
}
}
}
You can refer to the client-test05.cue file for inspiration.
generate-static-zones-files
trackbone plan -z $ZONE -c alertmanager
If the plan meets your expectations and the ConfigMap is well indented, you can request a review and follow the normal change procedure to apply the new alertmanager configuration.
git pull
git switch -c "template_for_$CONTRACT"
git add ../../gen "client-$CLIENT.cue"
git commit -m "PRD: NGOT: alertmanager: add notification template for $CONTRACT"
git push