Burrow
Burrow copied to clipboard
error "can't evaluate field templateJSONEncoder in type struct" when using "{{call .templateJSONEncoder .Result.Partitions}}" on slack template notification
I'm trying to use {{call .templateJSONEncoder .Result.Partitions}} on a Slack template but I get this error:
"template: default-slack-open.tmpl:1:341: executing "default-slack-open.tmpl" at <.templateJSONEncoder>: can't evaluate field templateJSONEncoder in type struct { Cluster string; Group string; ID string; Start time.Time; Extras map[string]string; Result protocol.ConsumerGroupStatus }"
I'm using the following Template content for slack notification:
{ "attachments": [{"color": "danger","title": "Alert from open condition (burrow)!","fields": [{"title": "Group","value": "{{ .Group }}", "short": false},{"title": "Cluster","value": "{{ .Cluster }}","short": true},{"title": "Status constant value","value": "{{ .Result.Status}}","short": true},{"title": "Partition status","value": {{call .templateJSONEncoder .Result.Partitions}},"short": false}}]}
Could anyone tell me was wrong with this template? Is there any example template for slack which shows partition status (not just consumer group status)?
Thanks
The documentation is flawed here (I will update it). The mapped function templateJSONEncoder has been removed in 1.0, and the helper function is now jsonencoder. It should be called like this:
{{.Result.Partitions | jsonencoder}}
This would make your template:
{ "attachments": [{"color": "danger","title": "Alert from open condition (burrow)!","fields": [{"title": "Group","value": "{{ .Group }}", "short": false},{"title": "Cluster","value": "{{ .Cluster }}","short": true},{"title": "Status constant value","value": "{{ .Result.Status}}","short": true},{"title": "Partition status","value": {{.Result.Partitions | jsonencoder}},"short": false}}]}
You can also call it {{jsonencoder .Result.Partitions}} which is probably more readable and correct
Docs updated
Thanks for updating docs.
I've tried again with new syntax:
{ "attachments": [{"color": "danger","title": "Alert from open condition (burrow)!","fields": [{"title": "Group","value": "{{ .Group }}", "short": false},{"title": "Cluster","value": "{{ .Cluster }}","short": true},{"title": "Status constant value","value": "{{ .Result.Status}}","short": true},{"title": "Partition","value": "{{jsonencoder .Result.Partitions}}","short": true}, {"title": "Start","value": "{{ .Start.Format "2006-01-02T15:04:05Z07:00" }}","short": true}]}]}
but I get this error:
{"level":"error","ts":1516996108.0308669,"msg":"failed to send","type":"module","coordinator":"notifier","class":"http","name":"default","cluster":"local","group":"connect-consumer-offsets-file-sink-2","id":"13009d52-928a-442e-a125-6dc8f127fa68","status":"ERR","response":400}
If I remove the jsonencoder chunk it works fine.
What I'm doing wrong?
Thanks
jsonencoder outputs a string that is valid JSON. You're enclosing it in quotes (I missed that the first time around), and as that output string will include double quotes in it, you'll end up with bad syntax. Try this:
{ "attachments": [{"color": "danger","title": "Alert from open condition (burrow)!","fields": [{"title": "Group","value": "{{ .Group }}", "short": false},{"title": "Cluster","value": "{{ .Cluster }}","short": true},{"title": "Status constant value","value": "{{ .Result.Status}}","short": true},{"title": "Partition","value": {{jsonencoder .Result.Partitions}},"short": true}, {"title": "Start","value": "{{ .Start.Format "2006-01-02T15:04:05Z07:00" }}","short": true}]}]}
I've tried with this:
{"title": "Partitions","value": {{ jsonencoder .Result.Partitions}},"short": false}
and there is no error but it shows nothing
What's the full output from the template when that happens?
I show you an example of output on Slack. Partit field should have some text:

I am facing the same issue as mentioned above. Getting no result for partitions and also ERR for the lag.

Also i want to display the topic name in the alert but im unable to do the same. Kindly help.