Skip to content

n9e服务从v7.6升级到v8.0_beta.9后,告警模板Target.HostIp字段报错无法发出告警 #2565

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

Open
c287395834 opened this issue Mar 26, 2025 · 8 comments

Comments

@c287395834
Copy link

Question and Steps to reproduce

v7.6版本中,告警模板配置机器地址: {{.Target.HostIp}}正常告警,升级后测试新的告警,报错:template: content:20:26: executing "content" at <$event.Target.HostIp>: nil pointer evaluating *models.Target.HostIp

模板如下:
{{ if $event.IsRecovered }}
{{- if ne $event.Cate "host" -}}
告警集群: {{$event.Cluster}}{{end}}
级别状态: S{{$event.Severity}} Recovered
告警名称: {{$event.RuleName}}
监控对象: {{$event.TargetIdent}}
机器地址: {{$event.Target.HostIp}}
{{- if .AnnotationsJSON.recovery_value}}
恢复时值: {{formatDecimal .AnnotationsJSON.recovery_value 2}}
{{- end}}
恢复时间: {{timeformat $event.LastEvalTime}}
{{$time_duration := sub now.Unix $event.FirstTriggerTime }}{{if $event.IsRecovered}}{{$time_duration = sub $event.LastEvalTime $event.FirstTriggerTime }}{{end}}持续时长: {{humanizeDurationInterface $time_duration}}
告警描述: 异常已恢复
{{- else }}
{{- if ne $event.Cate "host" -}}
告警集群: {{$event.Cluster}}{{end}}
级别状态: S{{$event.Severity}} Triggered
告警名称: {{$event.RuleName}}
监控对象: {{$event.TargetIdent}}
机器地址: {{$event.Target.HostIp}}
触发时间: {{timeformat $event.TriggerTime}}
触发时值: {{$event.TriggerValue}}
{{$time_duration := sub now.Unix $event.FirstTriggerTime }}{{if $event.IsRecovered}}{{$time_duration = sub $event.LastEvalTime $event.FirstTriggerTime }}{{end}}持续时长: {{humanizeDurationInterface $time_duration}}
{{ if $event.RuleNote }}告警描述: {{$event.RuleNote}}{{end}}
{{- end -}}
{{$domain := "http://192.169.0.18:17000" }}
事件详情|[屏蔽1小时]({{$domain}}/alert-mutes/add?busiGroup={{$event.GroupId}}&cate={{$event.Cate}}&datasource_ids={{$event.DatasourceId}}&prod={{$event.RuleProd}}{{range $key, $value := $event.TagsMap}}&tags={{$key}}%3D{{$value}}{{end}})|查看曲线

测试告警事件如图:
Image

Relevant logs and configurations

报错:template: content:20:26: executing "content" at <$event.Target.HostIp>: nil pointer evaluating *models.Target.HostIp

Version

夜莺v8.0-beta.9版本

@c287395834 c287395834 changed the title n9e服务从v7.6升级到v8.0_beta.9后,告警模板Target.HostIp字段报错 n9e服务从v7.6升级到v8.0_beta.9后,告警模板Target.HostIp字段报错无法发出告警 Mar 27, 2025
@710leo
Copy link
Member

710leo commented Mar 27, 2025

@c287395834 我测试 hostIp 在通知内容中是可以正常展示的,你这个 ident 有什么特殊的地方么?其他的 ident 会正常展示么

@c287395834
Copy link
Author

ident没有特殊的地方,把target.hostip放到告警模板就报错,

Image
ident有hostname+ip的格式,也有hostname的格式

Image

@c287395834
Copy link
Author

Image使用旧的告警通知是正常的,测试新版本的消息模板报错。如果把target.hostip去掉,新版本的消息模板也能发出告警

@c287395834
Copy link
Author

@c287395834 我测试 hostIp 在通知内容中是可以正常展示的,你这个 ident 有什么特殊的地方么?其他的 ident 会正常展示么

ident的格式有两种:gdgz_yd_r730xd_1和gslz_dx_r730xd_16@192.168.1.12,两种都无法在新版本的消息模板里发送成功
把$event.Target.HostIp在模板里剔除的话就发送正常了

Image

@c287395834
Copy link
Author

@710leo 大佬有空帮给看下,新版本对于ident的格式有啥特殊要求吗,目前已经升级到v8.0.0-beta10还是不行

@710leo
Copy link
Member

710leo commented Apr 15, 2025

@c287395834 v8.0.0-beta10 我们没复现你这个问题,可以再说下你的机器有什么特殊的地方

@c287395834
Copy link
Author

c287395834 commented Apr 16, 2025

@c287395834 v8.0.0-beta10 我们没复现你这个问题,可以再说下你的机器有什么特殊的地方

@710leo 命名格式也没啥特殊的吧,英文+下划线+数字的格式 ident=debian@192.168.1.11 ident=hnzz_yd_r2200_7这两种机器命名格式没问题吧

Image这是用来测试的告警信息。还是说需要把categraf升级到最新版本,目前categraf版本不是最新的
以下是消息模板
{{ if $event.IsRecovered }}
{{- if ne $event.Cate "host" -}}
告警集群: {{$event.Cluster}}{{end}}
级别状态: S{{$event.Severity}} Recovered
告警名称: {{$event.RuleName}}
监控对象: {{$event.TargetIdent}}
机器地址: {{$event.Target.HostIp}}
{{- if .AnnotationsJSON.recovery_value}}
恢复时值: {{formatDecimal $event.AnnotationsJSON.recovery_value 2}}
{{- end}}
恢复时间: {{timeformat $event.LastEvalTime}}
{{$time_duration := sub now.Unix $event.FirstTriggerTime }}{{if $event.IsRecovered}}{{$time_duration = sub $event.LastEvalTime $event.FirstTriggerTime }}{{end}}持续时长: {{humanizeDurationInterface $time_duration}}
告警描述: 异常已恢复
{{- else }}
{{- if ne $event.Cate "host" -}}
告警集群: {{$event.Cluster}}{{end}}
级别状态: S{{$event.Severity}} Triggered
告警名称: {{$event.RuleName}}
监控对象: {{$event.TargetIdent}}
机器地址: {{$event.Target.HostIp}}
触发时间: {{timeformat $event.TriggerTime}}
触发时值: {{$event.TriggerValue}}
{{$time_duration := sub now.Unix $event.FirstTriggerTime }}{{if $event.IsRecovered}}{{$time_duration = sub $event.LastEvalTime $event.FirstTriggerTime }}{{end}}持续时长: {{humanizeDurationInterface $time_duration}}
{{ if $event.RuleNote }}告警描述: {{$event.RuleNote}}{{end}}
{{- end -}}
{{$domain := "http://192.168.0.18:17000" }}
事件详情|[屏蔽1小时]({{$domain}}/alert-mutes/add?busiGroup={{$event.GroupId}}&cate={{$event.Cate}}&datasource_ids={{$event.DatasourceId}}&prod={{$event.RuleProd}}{{range $key, $value := $event.TagsMap}}&tags={{$key}}%3D{{$value}}{{end}})|查看曲线
事件详情|[屏蔽1小时]({{$domain}}/alert-mutes/add?busiGroup={{$event.GroupId}}&cate={{$event.Cate}}&datasource_ids={{$event.DatasourceId}}&prod={{$event.RuleProd}}{{range $key, $value := $event.TagsMap}}&tags={{$key}}%3D{{$value}}{{end}})|查看曲线`

@c287395834
Copy link
Author

c287395834 commented Apr 16, 2025

@c287395834 v8.0.0-beta10 我们没复现你这个问题,可以再说下你的机器有什么特殊的地方

$event.Target是不是不是这么引用的啊,在模板预览里$event.Target是

Image

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