[[httppost]] alert-template-file equivalent in flux

Hello,

Do we have an [[httppost]] alert-template-file equivalent in flux for constructing a custom HTTP body?
Without a template, will have to repeat the same thing in every alert.

Thanks

Hello @Ashish_Sikarwar,
You can clone an Alert in the UI if you want to duplicate it quickly. What do you wish was templatized? Can you provide me with an example so I can try to create a template?
Thanks. :slight_smile:

Hello @Anaisdg,

Thank you for looking into this.

Reference: https://docs.influxdata.com/kapacitor/v1.5/event_handlers/post/

In kapacitor we have this …

kapacitor.conf

[[httppost]]
endpoint = “my_customapi”
url = “http://localhost:8080
#basic-auth =
headers = {Content-Type = “application/json”}
alert-template-file = " /temp/template/post.html"

My post.html looks like this

{
“records”:[{
“source”: “SupportOne”,
“event_class”: “Kapacitor”,
“node”: “{{range .Data.Series}}{{index .Tags “sql_instance”}}{{end}}”,
“metric_name”: “{{range .Data.Series}}{{index .Tags “MetricName”}}{{end}}”,
“type”: “{{.Details}}”,
“resource”: “{{range .Data.Series}}{{index .Tags “Resource”}}{{end}}{{.ID}}”,
“severity”: {{ if eq (.Level | print) “WARNING” }}“3”{{else if eq (.Level | print) “OK”}}“0”{{ end }},
“description”: “{{js .Message}}”,
“additional_info”: “{
{{- .}}“data”: {{js .Data}},
“fqdn”: “{{range .Data.Series}}{{index .Tags “host”}}{{end}}”, “CDH”: “{{range .Data.Series}}{{index .Tags “CDH”}}{{end}}”, “launch_url” :“https://grafana-test/d/{{range .Data.Series}}{{index .Tags “dashboard_folder”}}{{end}}/{{range .Data.Series}}{{index .Tags “dashboard_name”}}{{ end }}?refresh=1m&orgId=1&var-host={{range .Data.Series}}{{index .Tags “host”}}{{ end }}&from={{range .Data.Series}}{{index .Tags “F_timestamp”}}{{ end }}&to={{range .Data.Series}}{{index .Tags “T_timestamp”}}”{{ end }}”,
“message_key”:"{{.Details}}-{{range .Data.Series}}{{index .Tags “host”}}{{ end }}-{{.ID}}-{{range .Data.Series}}{{index .Tags “MetricName”}}{{end}}"
}]}

Finally in kapacitor we simply trigger the alerts and it will load the template to send json data.

This saves time and prevents repetition and makes tasks dynamic.
What do have or how we can leverage this in flux?

Thanks
Ashish

1 Like