Webhook supports custom message, Make webhook notification more generic. (e.g. dingtalk/wechat ...)#2378
Webhook supports custom message, Make webhook notification more generic. (e.g. dingtalk/wechat ...)#2378virnet wants to merge 10 commits intoprometheus:mainfrom
Conversation
Signed-off-by: 孙林耀 <sunlinyao@vip.qq.com>
|
Thanks for your contribution! It's already been discussed before (see #701) but we're not sure yet how it can be solved properly. |
notify/webhook/webhook.go
Outdated
| return false, fmt.Errorf("Json格式异常: %s ", body) | ||
| } | ||
| } else if n.conf.Text != "" { | ||
| body, err := n.tmpl.ExecuteTextString(n.conf.Json, data) |
notify/webhook/webhook.go
Outdated
| err = json.NewEncoder(&buf).Encode(body) | ||
| if err != nil { | ||
| return false, err | ||
| } |
There was a problem hiding this comment.
No need to json encode if this is Text template imho, "buf.WriteString(body)" should be sufficient
There was a problem hiding this comment.
No need to json encode if this is Text template imho, "buf.WriteString(body)" should be sufficient
If neither the JSON template nor the text template is configured, then the message should be converted into JSON according to the original logic.
|
I use virnet patch with minor mods (included), so we can notify to webhooks with formencoded content POST API. in alertmanager.yml : In template/form.tmpl : |
|
What's stopping this from being merged? This would be really nice to have. |
57cd3d4 to
dc3a414
Compare
Signed-off-by: 孙林耀 <sunlinyao@vip.qq.com>
Signed-off-by: 孙林耀 <sunlinyao@vip.qq.com>
|
See Simon's comment. I agree that it is awesome to be able to customize the message, but go templates are far from ideal for this. |
|
@roidelapluie @simonpasquier what do you think about jsonnet as an alternative? |
|
@yuri-tceretian I think that @jan--f did an experiment but it wasn't really successful (the processing wasn't really efficient). |
|
Yes the experiment can still be found at https://github.com/jan--f/alertmanager/tree/webhook-text-templates. This is a very naive implementation no doubt but I think I saw 40x - 80x slowdown even for a simple oneline template. |
… alarm messages and avoid disrupting JSON formats due to line breaks, quotation marks, etc. Signed-off-by: 孙林耀 <sunlinyao@vip.qq.com>
Signed-off-by: 孙林耀 <sunlinyao@vip.qq.com>
f3e3637 to
3e9f2a1
Compare
Signed-off-by: 孙林耀 <sunlinyao@vip.qq.com>
Signed-off-by: 孙林耀 <sunlinyao@vip.qq.com>
I also think it's not very wise to generate JSON through go templates, but I haven't found a better solution. When you say 'it's going to be error prone and brick', do you mean that there are special symbols that can cause JSON formatting exceptions when generating JSON? I have come up with a way to use the custom function toJson/safeJson to escape any special characters that may occur, thus avoiding this issue. |
|
My main worry is that it will very hard for people to use and debug. Go templates aren't made to generate structured format like JSON. |
|
IMHO that overlaps with #2184 |
|
I applied this PR to release 0.29 before building because I needed this feature, and it works perfectly: |
|
I am closing this PR in favor of #5011 since it has not had any activity. Kind regards |
Signed-off-by: 孙林耀 sunlinyao@vip.qq.com