Aleksei Sviridkin c15466fb98 feat(monitoring): take an Alertmanager template file for alert emails (#5110)
## What this PR does

The email receiver from #3800 sends the default Alertmanager subject and
HTML body. The subject strings together every common label of the group,
for a stuck DaemonSet it reads like `[FIRING:1]
KubeDaemonSetRolloutStuck prod cozy-linstor (kubernetes-apps
kube-state-metrics linstor-satellite.node1 http
cozy-linstor/linstor-satellite.node1 ...)`, and the body is a table of
labels and annotations. #3800 left subject and body templates out of the
values on purpose, because Alertmanager parses inline templates only
when it sends, so a broken one drops mail with nothing but a log line.

`alerta.alerts.email.template` takes the text of an Alertmanager
template file instead. The chart stores it in the
`alertmanager-email-template` ConfigMap and lists it in
`VMAlertmanager.spec.templates`. The operator (v0.68.4) mounts it, adds
the path to the configuration `templates` and passes the mount to the
config reloader as a watched directory, so Alertmanager parses the file
while loading its configuration. A file that does not parse fails that
load, and a running Alertmanager keeps the configuration it has. A
template that parses but fails on a notification, for example on a
missing key, still drops that email, and the field description says so.
Defining `email.default.subject` and `email.default.html` in the file
replaces the subject and the body of every email, for example to mark
the severity or to link to Alerta.

The text has to contain a `define` action, a value that is not text
fails the render, and `template` counts as a set field for the check
that rejects a partial email configuration.

We run the same setup by hand on three clusters, a ConfigMap plus
`spec.templates` with Alertmanager v0.31.0 and operator v0.68.4, and
mail arrives with the custom subject and body for firing and resolved
alerts. This PR moves it into the chart, so a platform upgrade does not
drop it.

Checks run for this change.

- `helm unittest` 1.1.2, the version CI pins.
`packages/system/monitoring` passes 309 of 309, five of them new,
`packages/extra/monitoring` passes 31 of 31.
- Each part of the change was taken out in turn, no `spec.templates`, no
`define` check, `template` missing from the set fields and the text
trimmed, and each time exactly one new case failed.
- `make generate` in `packages/extra/monitoring` with cozyvalues-gen
v1.7.0 changes the README, the schema and the cozyrd and nothing else,
and a second run leaves the tree unchanged.

### Screenshots

Not a UI change.

### Downstream repositories

Walked the trigger map in `docs/agents/contributing.md` against the
diff. It adds one field to `packages/extra/monitoring` and changes a
template in `packages/system/monitoring`. The Terraform provider does
not model Monitoring. Monitoring is in the website `SERVICES` list, so
its reference page is regenerated from the README on the next tag.
Nothing under `hack/`, the installer or a CRD changes.

- [x] No downstream repository is affected by this change
- [ ] [cozystack/website](https://github.com/cozystack/website) -
follow-up:
- [ ]
[cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack)
- follow-up:
- [ ]
[cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack)
- follow-up:
- [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up:
- [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up:
- [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) -
follow-up:
- [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) -
follow-up:
- [ ]
[cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server)
- follow-up:
- [ ]
[cozystack/external-apps-example](https://github.com/cozystack/external-apps-example)
- follow-up:
- [ ] [cozystack/examples](https://github.com/cozystack/examples) -
follow-up:
- [ ] [cozystack/community](https://github.com/cozystack/community) -
follow-up:

### Release note

```release-note
feat(monitoring): alerta.alerts.email.template takes the text of an Alertmanager template file for alert emails. Define email.default.subject and email.default.html in it to change the subject and the HTML body of every email. The chart stores the file in the alertmanager-email-template ConfigMap, and Alertmanager loads it with its configuration.
```


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **New Features**
* Alertmanager email alerts can use a custom template for the email
subject and HTML body. Leave the template empty to retain the default
format.
* Templates must include a named definition. Invalid templates prevent
configuration from loading or the monitoring pod from starting; errors
while rendering a notification can prevent that email from being sent.

* **Documentation**
* Added guidance on configuring email templates and their validation and
delivery behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-16 14:34:01 +03:00
2026-11-04 00:56:56 +01:00
2025-10-08 09:43:34 +05:00
2024-02-08 12:04:32 +01:00

Cozystack Cozystack

GitHub Release Apache-2.0 License Commit activity OpenSSF Best Practices OpenSSF Scorecard CLOMonitor Support

Cozystack

Cozystack is a free and open-source platform and framework for building clouds.

Cozystack is a CNCF Sandbox project that was originally built and sponsored by Ænix.

With Cozystack, you can transform a bunch of servers into an intelligent system with a simple REST API for spawning Kubernetes clusters, Database-as-a-Service, virtual machines, load balancers, HTTP caching services, and other services with ease.

Use Cozystack to build your own cloud or provide a cost-effective development environment.

Cozystack user interface

Use-Cases

Documentation

The documentation is located on the cozystack.io website.

Read the Getting Started section for a quick start.

If you encounter any difficulties, start with the troubleshooting guide and work your way through the process that we've outlined.

Versioning

Versioning adheres to the Semantic Versioning principles.
A full list of the available releases is available in the GitHub repository's Release section.

Contributions

Contributions are highly appreciated and very welcomed!

In case of bugs, please check if the issue has already been opened by checking the GitHub Issues section. If it isn't, you can open a new one. A detailed report will help us replicate it, assess it, and work on a fix.

You are welcome to take on the fix yourself. Commits are used to generate the changelog, and their author will be referenced in it.

If you have a concrete feature request, open an issue. For a cross-cutting or architectural change, open a design proposal in the community repo. For questions or early ideas, use GitHub Discussions. See CONTRIBUTING.md for the full routing.

Community

You are welcome to join us in #cozystack, on either CNCF Slack (get an invite) or Kubernetes Slack (get an invite), in our Telegram group, and at our community meetings. Add them to your Google Calendar or iCal for convenience.

Project documents

Document What it covers
Governance How decisions are made and who makes them
Contributor Ladder How to grow from contributor to maintainer
Maintainers Who maintains the project
Code of Conduct What we expect of each other
Security Policy Reporting a vulnerability, and which releases get fixes
Adopters Who runs Cozystack in production
Roadmap Where the project is going

License

Cozystack is licensed under Apache 2.0.
The code is provided as-is with no warranties.

Commercial Support

A list of companies providing commercial support for this project can be found on official site.

Languages
Go 52%
Shell 34%
TypeScript 6.8%
Go Template 4.7%
Makefile 1.3%
Other 1.1%