未验证 提交 37c83174 编写于 作者: F Feng_Qi 提交者: GitHub

告警信息增加设备名称(name)和设备备注(note) (#460)

* fix port check and push debug log

1:如果服务没有监听在 0.0.0.0 上,而是监听在特定地址上的话,在 127.0.0.1 上无法检测到端口。修改为如果 127.0.0.1 检测不到话,在 identity 的地址上再检测一次。
2. http push 部分缺乏 debug 日志,把 debug log 改到 push 里面以补全。

* Update cron.go

* notify add resource name and note

* Update notify.go
上级 19337b23
......@@ -163,6 +163,14 @@
<th>告警设备:</th>
<td>{{.Endpoint}}</td>
</tr>
<tr>
<th>设备名称:</th>
<td>{{.Name}}</td>
</tr>
<tr>
<th>设备备注:</th>
<td>{{.Note}}</td>
</tr>
<tr>
<th>挂载节点:</th>
<td>
......
......@@ -2,6 +2,8 @@
级别状态:{{.Status}}
策略名称:{{.Sname}}
告警设备:{{.Endpoint}}
设备名称:{{.Name}}
设备备注:{{.Note}}
挂载节点:
{{range .Bindings}}{{.}}
{{end}}监控指标:{{.Metric}}
......
......@@ -54,6 +54,15 @@ func ResourceIdsByIdents(idents []string) ([]int64, error) {
return ids, err
}
func ResourcesByIdents(idents []string) ([]Resource, error) {
if len(idents) == 0 {
return []Resource{}, nil
}
var resouces = []Resource{}
err := DB["rdb"].Table(new(Resource)).In("ident", idents).Find(&resouces)
return resouces, err
}
func ResourceIdentsByIds(ids []int64) ([]string, error) {
if len(ids) == 0 {
return []string{}, nil
......
......@@ -108,11 +108,14 @@ func genContent(isUpgrade bool, events []*models.Event) (string, string) {
}
}
resources := getResources(events)
metric := strings.Join(metricList, ",")
status := genStatus(events)
sname := events[cnt-1].Sname
endpoint := genEndpoint(events)
name, note := genNameAndNoteByResources(resources)
tags := genTags(events)
value := events[cnt-1].Value
info := events[cnt-1].Info
......@@ -156,6 +159,8 @@ func genContent(isUpgrade bool, events []*models.Event) (string, string) {
"Status": status,
"Sname": sname,
"Endpoint": endpoint,
"Name": name,
"Note": note,
"CurNodePath": curNodePath,
"Metric": metric,
"Tags": tags,
......@@ -282,6 +287,38 @@ func HostBindingsForMon(endpointList []string) ([]string, error) {
return list, nil
}
func getResources(events []*models.Event) []models.Resource {
idents := []string{}
for i := 0; i < len(events); i++ {
idents = append(idents, events[i].Endpoint)
}
resources, err := models.ResourcesByIdents(idents)
if err != nil {
logger.Errorf("get resources by idents failed : %v", err)
}
return resources
}
func genNameAndNoteByResources(resources []models.Resource) (name, note string) {
names := []string{}
notes := []string{}
for i := 0; i < len(resources); i++ {
names = append(names, resources[i].Name)
notes = append(notes, resources[i].Note)
}
names = config.Set(names)
notes = config.Set(notes)
if len(resources) == 1 {
name = names[0]
note = notes[0]
return
}
name = fmt.Sprintf("%s(%v)", strings.Join(names, ","), len(names))
note = fmt.Sprintf("%s(%v)", strings.Join(notes, ","), len(notes))
return
}
func getEndpoint(events []*models.Event) []string {
endpointList := []string{}
for i := 0; i < len(events); i++ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册