mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-21 07:56:26 +01:00
c7fc0d0d2f
…pair
`alert_relabel_configs` in [notifier
config](https://docs.victoriametrics.com/vmalert/#notifier-configuration-file)
can drop alert labels when used to filter different tenant alert message
to different notifier.
alertmanager would report error like `msg="Failed to validate alerts"
err="at least one label pair required"` in this case, but the rest of
the alerts inside one request would still be valid in alertmanager, so
it's not severe.
(cherry picked from commit ae4d376e41
)
38 lines
1.1 KiB
Plaintext
38 lines
1.1 KiB
Plaintext
{% import (
|
|
"time"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promrelabel"
|
|
) %}
|
|
{% stripspace %}
|
|
|
|
{% func amRequest(alerts []Alert, generatorURL func(Alert) string, relabelCfg *promrelabel.ParsedConfigs) %}
|
|
[
|
|
{% for i, alert := range alerts %}
|
|
{% code lbls := alert.applyRelabelingIfNeeded(relabelCfg) %}
|
|
{% if len(lbls) == 0 %} {% continue %} {% endif %}
|
|
{
|
|
"startsAt":{%q= alert.Start.Format(time.RFC3339Nano) %},
|
|
"generatorURL": {%q= generatorURL(alert) %},
|
|
{% if !alert.End.IsZero() %}
|
|
"endsAt":{%q= alert.End.Format(time.RFC3339Nano) %},
|
|
{% endif %}
|
|
"labels": {
|
|
{% code ll := len(lbls) %}
|
|
{% for idx, l := range lbls %}
|
|
{%q= l.Name %}:{%q= l.Value %}{% if idx != ll-1 %}, {% endif %}
|
|
{% endfor %}
|
|
},
|
|
"annotations": {
|
|
{% code c := len(alert.Annotations) %}
|
|
{% for k,v := range alert.Annotations %}
|
|
{% code c = c-1 %}
|
|
{%q= k %}:{%q= v %}{% if c > 0 %},{% endif %}
|
|
{% endfor %}
|
|
}
|
|
}
|
|
{% if i != len(alerts)-1 %},{% endif %}
|
|
{% endfor %}
|
|
]
|
|
{% endfunc %}
|
|
{% endstripspace %}
|