Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请教一个关于企业微信的alertmanager问题 #36

Open
max27149 opened this issue Jul 17, 2019 · 4 comments
Open

请教一个关于企业微信的alertmanager问题 #36

max27149 opened this issue Jul 17, 2019 · 4 comments

Comments

@max27149
Copy link

我使用的版本如下:
alertmanager-0.18.0.linux-amd64
prometheus-2.11.1.linux-amd64
我的告警模板 wechat.tmpl 内容如下:

{{ define "wechat.tmpl" }}
{{ range .Alerts }}
========start==========
告警程序: prometheus_alert
告警级别: {{ .Labels.severity }}
告警类型: {{ .Labels.alertname }}
故障主机: {{ .Labels.instance }}
告警主题: {{ .Annotations.summary }}
告警详情: {{ .Annotations.description }}
触发时间: {{ .StartsAt.Format "2006-01-02 15:04:05" }}
========end==========
{{ end }}
{{ end }}

日志无报错
level=debug ts=2019-07-17T12:53:33.495Z caller=dispatch.go:430 component=dispatcher aggrGroup="{}:{alertname="node_status"}" msg=flushing alerts=[node_status[1a2f380][active]]
level=debug ts=2019-07-17T12:53:38.496Z caller=dispatch.go:430 component=dispatcher aggrGroup="{}:{alertname="node_status"}" msg=flushing alerts=[node_status[1a2f380][active]]

也能收到企业微信告警,但是内容为空

image

尝试找了别的模板,也把alertmanager降了一个版本,还是一样,可能是哪里的问题呢?

@max27149 max27149 changed the title 请教一个问题 请教一个关于企业微信的alertmanager问题 Jul 17, 2019
@lch0000
Copy link
Contributor

lch0000 commented Jul 18, 2019

可以尝试把邮件告警功能开启,看看是否能正常收到告警邮件。而且当你不配置wechat自定义模板时,alertmanager会使用默认模板,可以看看这时能否收到消息。如果这样是正常的,应该就是自定义模板的问题了,可以参考 https://godoc.org/text/template 中的语法说明自己调试下。

@max27149
Copy link
Author

可以尝试把邮件告警功能开启,看看是否能正常收到告警邮件。而且当你不配置wechat自定义模板时,alertmanager会使用默认模板,可以看看这时能否收到消息。如果这样是正常的,应该就是自定义模板的问题了,可以参考 https://godoc.org/text/template 中的语法说明自己调试下。

多谢指点!注释掉模板配置,的确是可以的。
image

试了一下这里的模板,有语法错误:

level=error ts=2019-07-18T02:11:59.582Z caller=notify.go:367 component=dispatcher msg="Error on notify" err="cancelling notify retry for "wechat" due to unrecoverable error: templating error: template: wechat.tmpl:2:11: executing "wechat.tmpl" at <len .Alerts.Firing>: error calling len: len of untyped nil"
level=error ts=2019-07-18T02:11:59.583Z caller=dispatch.go:264 component=dispatcher msg="Notify for alerts failed" num_alerts=1 err="cancelling notify retry for "wechat" due to unrecoverable error: templating error: template: wechat.tmpl:2:11: executing "wechat.tmpl" at <len .Alerts.Firing>: error calling len: len of untyped nil"

@lch0000
Copy link
Contributor

lch0000 commented Jul 18, 2019

 executing "wechat.tmpl" at <len .Alerts.Firing>: error calling len: len of untyped nil"

报错这里其实是要判断一下是否有告警或恢复信息,好为后边的迭代做预判断。我当时调试通过的软件版本如下:

  • prometheus: 2.4.3
  • alertmanager: 0.15.2

我怀疑是不是后来新版本有对这里做调整。请自己debug下,问题解决了欢迎提PR

@max27149
Copy link
Author

 executing "wechat.tmpl" at <len .Alerts.Firing>: error calling len: len of untyped nil"

报错这里其实是要判断一下是否有告警或恢复信息,好为后边的迭代做预判断。我当时调试通过的软件版本如下:

  • prometheus: 2.4.3
  • alertmanager: 0.15.2

我怀疑是不是后来新版本有对这里做调整。请自己debug下,问题解决了欢迎提PR

抱歉,我并不是程序员,不太懂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants