-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Severities to template data and hasString to template function #3847
Conversation
Signed-off-by: Jan-Otto Kröpke <[email protected]>
Hi! 👋 Alertmanager doesn't have severity, and Prometheus users are not required to set use a severity label, so I'm not sure if this is something that will be accepted. Is it not possible to template the severity for Opsgenie using the existing templating infrastructure? |
Hey!
I know. In that cases, the list is just empty. It won't break anything. While AM doesn't have severity, it would be great if AM can assists users they are using commonly-known pattern.
If you show me, how this is possible, we can close the PR. What I need is loop through all alerts, look for a specific. I tires something like
would result into In Helm templating engine, something like this is possible:
But the Pulling https://github.com/Masterminds/sprig may resolve this issues, it allows to do crazy things inside go template. Looking at #3770 it unclear, if this is getting accepted. The current approach show me that creating functions that are required would be the way to go. |
If this is too severity specifc, what about an alternative solution that provides all possible label values? Like an variables, map[string][]string, which has label names as keys and all possible label values as label Then, in go template this would be possible:
but alternatives are possible, too:
|
What about this?
|
But the issue with that, it give P1 back if there is an alert with severity=critical. If not, then nothing is returned.
result into P1P2, if there are multiple alerts with different severities. In native go, I would use |
What about this?
You can then execute the template with:
|
I'm impressed, thanks!
|
Motivation of this PR
Some receiver of Alertmanager handling a persistent state of alerts.
Looking at OpsGenie, it can be setup one alert with group of alerts.
However, currently its not really possible to get the highest severity of the alert group. One potential solution is having severity as part of the group_labels, but this results into distinct alerts, because the HashKey of an alert group changes and grouped alerts may get splited.
In conclusion, I added a new template data field
severities
which hold a list of string contains all values of the label severity. In addition, I added a new template funchasString
that maps toslices.Contains
.The result would be a template that could be used to define a OpsGenie priority:
It's also useful for #3590, since the receiver has the capability to update existing issues and it would be great if the priority can be updated as well.