Burrow icon indicating copy to clipboard operation
Burrow copied to clipboard

error "can't evaluate field templateJSONEncoder in type struct" when using "{{call .templateJSONEncoder .Result.Partitions}}" on slack template notification

Open hectorgarzon opened this issue 7 years ago • 9 comments

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

hectorgarzon avatar Jan 29 '18 18:01 hectorgarzon

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}}]}

toddpalino avatar Jan 29 '18 19:01 toddpalino

You can also call it {{jsonencoder .Result.Partitions}} which is probably more readable and correct

toddpalino avatar Jan 29 '18 19:01 toddpalino

Docs updated

toddpalino avatar Jan 29 '18 19:01 toddpalino

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

hectorgarzon avatar Jan 30 '18 08:01 hectorgarzon

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}]}]}

toddpalino avatar Jan 30 '18 17:01 toddpalino

I've tried with this: {"title": "Partitions","value": {{ jsonencoder .Result.Partitions}},"short": false} and there is no error but it shows nothing

hectorgarzon avatar Jan 31 '18 08:01 hectorgarzon

What's the full output from the template when that happens?

toddpalino avatar Jan 31 '18 15:01 toddpalino

I show you an example of output on Slack. Partit field should have some text: screen shot 2018-02-01 at 16 50 42

hectorgarzon avatar Feb 01 '18 15:02 hectorgarzon

I am facing the same issue as mentioned above. Getting no result for partitions and also ERR for the lag. Screenshot 2020-09-11 at 12 54 21 PM

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

akku16 avatar Sep 11 '20 07:09 akku16