mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-15 16:30:55 +01:00
fa9601a0f1
Before, relabeling for notifier configured via file was supported only for target labels discovered via SD. With this change, new config field `alert_relabel_configs` is introduced for applying relabeling to labels of sent alerts. Signed-off-by: hagen1778 <roman@victoriametrics.com>
37 lines
1018 B
Plaintext
37 lines
1018 B
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 %}
|
|
{
|
|
"startsAt":{%q= alert.Start.Format(time.RFC3339Nano) %},
|
|
"generatorURL": {%q= generatorURL(alert) %},
|
|
{% if !alert.End.IsZero() %}
|
|
"endsAt":{%q= alert.End.Format(time.RFC3339Nano) %},
|
|
{% endif %}
|
|
"labels": {
|
|
"alertname":{%q= alert.Name %}
|
|
{% code lbls := alert.toPromLabels(relabelCfg) %}
|
|
{% for _, l := range lbls %}
|
|
,{%q= l.Name %}:{%q= l.Value %}
|
|
{% 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 %}
|