Alert description templating

113 views
Skip to first unread message

dadi....@cognite.com

unread,
Apr 18, 2018, 1:09:03 PM4/18/18
to Prometheus Users
Hello all,

I am quite stuck on trying to get templating to work in alert descriptions. The alerting rule expression is `sum by (kubernetes_cluster) (kube_node_status_condition{status="true"}) - sum by (kubernetes_cluster) (up{app="node-exporter", container="node-exporter"}) > 0` and returns a list of Kubernetes clusters. I would like to iterate over this list and return all the clusters in the alert description. I tried doing the following 

description: {{ range query "sum by (kubernetes_cluster) (kube_node_status_condition{status="true"}) - sum by (kubernetes_cluster) (up{app="node-exporter", container="node-exporter"}) > 0" }}
                 {{ $labels.kubernetes_cluster }}
             {{ end }}



but I kept getting errors of the form "yaml: line 124: did not find expected key" or "yaml: line 124: did not find expected ',' or '}'". 


I'm on Prometheus v2.0. Thanks a lot in advance. Any help is greatly appreciated.

Cheers.

Regards,
DZ

Brian Brazil

unread,
Apr 18, 2018, 1:14:32 PM4/18/18
to dadi....@cognite.com, Prometheus Users
On 18 April 2018 at 18:09, <dadi....@cognite.com> wrote:
Hello all,

I am quite stuck on trying to get templating to work in alert descriptions. The alerting rule expression is `sum by (kubernetes_cluster) (kube_node_status_condition{status="true"}) - sum by (kubernetes_cluster) (up{app="node-exporter", container="node-exporter"}) > 0` and returns a list of Kubernetes clusters. I would like to iterate over this list and return all the clusters in the alert description. I tried doing the following 

description: {{ range query "sum by (kubernetes_cluster) (kube_node_status_condition{status="true"}) - sum by (kubernetes_cluster) (up{app="node-exporter", container="node-exporter"}) > 0" }}
                 {{ $labels.kubernetes_cluster }}
             {{ end }}



but I kept getting errors of the form "yaml: line 124: did not find expected key" or "yaml: line 124: did not find expected ',' or '}'". 

Try doing:

description: >
  put
  your
  long
  string
  here


Braces are special to yaml, so you need to escape them or choose one of the string formats that handles them.

Brian
 


I'm on Prometheus v2.0. Thanks a lot in advance. Any help is greatly appreciated.

Cheers.

Regards,
DZ

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-users+unsubscribe@googlegroups.com.
To post to this group, send email to prometheus-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/88567be4-e734-41b3-aaa8-dd3e2cbee59a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages