# Alert template not working

**URL:** <https://community.influxdata.com/t/alert-template-not-working/6315>\
**Category:** Kapacitor\
**Tags:** kapacitor\
**Created:** [August 21, 2018, 4:38pm UTC](https://community.influxdata.com/t/alert-template-not-working/6315 "2018-08-21T16:38:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hellobhaskar](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/hellobhaskar/32/2088_2.png) [@hellobhaskar](https://community.influxdata.com/u/hellobhaskar)\
**Post date:** [August 21, 2018, 4:38pm UTC](https://community.influxdata.com/t/alert-template-not-working/6315/1 "2018-08-21T16:38:55Z")

</div>

We are trying to find a way to integrate Kapacitor with alertmanager (prometheus).  
As the incoming format for alertmanager is different from “post” format of kapacitor we tried to customise it using alert template.

We tried both alert-template and alert-template-file irrespective whatever we customise the JSON payload is not changing(we get default Kapacitor JSON post format). any idea ?

We are setting web hook url in tick script using post(‘url’) syntax

---

<div class="post-metadata">

**Author:** ![Ashish\_Sikarwar](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/ashish_sikarwar/32/2074_2.png) [@Ashish\_Sikarwar](https://community.influxdata.com/u/Ashish_Sikarwar)\
**Post date:** [November 7, 2018, 3:25pm UTC](https://community.influxdata.com/t/alert-template-not-working/6315/2 "2018-11-07T15:25:38Z")

</div>

Check this

> <https://github.com/influxdata/kapacitor/issues/1589>
>
> This is a feature request for the ability to specify custom JSON output for the …Alert Post and HttpPost nodes. As it stands now there is no control over how the JSON looks and adding additional elements to it is not a trivial task.
> 
> In thinking how this might be implemented I could see a parameter that might point to a template file that could perform the mapping:
> 
> .template(String template, Boolean appendUnusedValues)
> templateFIle -- The path and name pf the template file or a string with the template definition. This would allow you to specify the template in the TICK script as a var or separately as a file
> appendUnusedValues -- If true would append any remaining tags or fields to the end of the json. This would provide the ability to transform certain tags or fields while retaining many of the original tags and fields. If false only the tag or field values specified in the template will be in the output json
> 
> stream
> |httpPost()
> .template('myTemplate.tmpl', true)
> .endpoint('example')
>             
> Where the template file might look like:
> {
> "myParam1": {{tag.tagName}},
> "myParam2": {{field.fieldName}}
> }
> 
> Thoughts?

---

<div class="post-metadata">

**Author:** ![geographer](https://avatars.discourse-cdn.com/v4/letter/g/a8b319/32.png) [@geographer](https://community.influxdata.com/u/geographer)\
**Post date:** [May 9, 2020, 3:40am UTC](https://community.influxdata.com/t/alert-template-not-working/6315/3 "2020-05-09T03:40:10Z")

</div>

Hi. I’ve been trying to read through that and the instructions are not very clear. Can someone please point me to some documentation that will help on how to write custom json template.

Thanks.

---

<div class="post-metadata">

**Author:** ![Ashish\_Sikarwar](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/ashish_sikarwar/32/2074_2.png) [@Ashish\_Sikarwar](https://community.influxdata.com/u/Ashish_Sikarwar)\
**Post date:** [May 12, 2020, 4:35pm UTC](https://community.influxdata.com/t/alert-template-not-working/6315/4 "2020-05-12T16:35:52Z")

</div>

Try this:

> [@Solution: Create custom HTTP body and access .tags and values. using row-template](https://community.influxdata.com/t/solution-create-custom-http-body-and-access-tags-and-values-using-row-template/13775):
>
> Main challenge was to access .tags and fields from template to create custom json body. ANd with alert-template you cannot access fields outside {{.Message}}, atleast what I had noticed. Check this out for more details: or Solution Use |alert node & httpPost() node in your tickscript Batch/Stream it works with both: Note you can also add custom tags… by using default() node. |alert() .details(‘details’) .crit(lambda: “cpuusage” \> crit) .message(message) .id(idVar) .idTag(idTag) .l…

Let me know if you get stuck.
