2020-02-21 21:15:05 +00:00
|
|
|
{% import (
|
|
|
|
"time"
|
2022-04-09 06:21:16 +00:00
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promrelabel"
|
2020-02-21 21:15:05 +00:00
|
|
|
) %}
|
|
|
|
{% stripspace %}
|
|
|
|
|
2022-04-09 06:21:16 +00:00
|
|
|
{% func amRequest(alerts []Alert, generatorURL func(Alert) string, relabelCfg *promrelabel.ParsedConfigs) %}
|
2020-03-13 10:19:31 +00:00
|
|
|
[
|
|
|
|
{% for i, alert := range alerts %}
|
2024-09-09 11:34:48 +00:00
|
|
|
{% code lbls := alert.applyRelabelingIfNeeded(relabelCfg) %}
|
|
|
|
{% if len(lbls) == 0 %} {% continue %} {% endif %}
|
2020-02-21 21:15:05 +00:00
|
|
|
{
|
2020-06-21 10:32:46 +00:00
|
|
|
"startsAt":{%q= alert.Start.Format(time.RFC3339Nano) %},
|
|
|
|
"generatorURL": {%q= generatorURL(alert) %},
|
2020-02-21 21:15:05 +00:00
|
|
|
{% if !alert.End.IsZero() %}
|
|
|
|
"endsAt":{%q= alert.End.Format(time.RFC3339Nano) %},
|
|
|
|
{% endif %}
|
|
|
|
"labels": {
|
2022-10-10 07:44:58 +00:00
|
|
|
{% code ll := len(lbls) %}
|
|
|
|
{% for idx, l := range lbls %}
|
|
|
|
{%q= l.Name %}:{%q= l.Value %}{% if idx != ll-1 %}, {% endif %}
|
2020-02-21 21:15:05 +00:00
|
|
|
{% endfor %}
|
|
|
|
},
|
|
|
|
"annotations": {
|
2020-03-13 10:19:31 +00:00
|
|
|
{% code c := len(alert.Annotations) %}
|
|
|
|
{% for k,v := range alert.Annotations %}
|
|
|
|
{% code c = c-1 %}
|
|
|
|
{%q= k %}:{%q= v %}{% if c > 0 %},{% endif %}
|
|
|
|
{% endfor %}
|
2020-02-21 21:15:05 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-13 10:19:31 +00:00
|
|
|
{% if i != len(alerts)-1 %},{% endif %}
|
|
|
|
{% endfor %}
|
|
|
|
]
|
2020-02-21 21:15:05 +00:00
|
|
|
{% endfunc %}
|
|
|
|
{% endstripspace %}
|