告警信息增加设备名称(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
This commit is contained in:
parent
19337b230c
commit
37c8317410
|
@ -163,6 +163,14 @@
|
||||||
<th>告警设备:</th>
|
<th>告警设备:</th>
|
||||||
<td>{{.Endpoint}}</td>
|
<td>{{.Endpoint}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>设备名称:</th>
|
||||||
|
<td>{{.Name}}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>设备备注:</th>
|
||||||
|
<td>{{.Note}}</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>挂载节点:</th>
|
<th>挂载节点:</th>
|
||||||
<td>
|
<td>
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
级别状态:{{.Status}}
|
级别状态:{{.Status}}
|
||||||
策略名称:{{.Sname}}
|
策略名称:{{.Sname}}
|
||||||
告警设备:{{.Endpoint}}
|
告警设备:{{.Endpoint}}
|
||||||
|
设备名称:{{.Name}}
|
||||||
|
设备备注:{{.Note}}
|
||||||
挂载节点:
|
挂载节点:
|
||||||
{{range .Bindings}}{{.}}
|
{{range .Bindings}}{{.}}
|
||||||
{{end}}监控指标:{{.Metric}}
|
{{end}}监控指标:{{.Metric}}
|
||||||
|
|
|
@ -54,6 +54,15 @@ func ResourceIdsByIdents(idents []string) ([]int64, error) {
|
||||||
return ids, err
|
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) {
|
func ResourceIdentsByIds(ids []int64) ([]string, error) {
|
||||||
if len(ids) == 0 {
|
if len(ids) == 0 {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
|
|
|
@ -108,11 +108,14 @@ func genContent(isUpgrade bool, events []*models.Event) (string, string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resources := getResources(events)
|
||||||
|
|
||||||
metric := strings.Join(metricList, ",")
|
metric := strings.Join(metricList, ",")
|
||||||
|
|
||||||
status := genStatus(events)
|
status := genStatus(events)
|
||||||
sname := events[cnt-1].Sname
|
sname := events[cnt-1].Sname
|
||||||
endpoint := genEndpoint(events)
|
endpoint := genEndpoint(events)
|
||||||
|
name, note := genNameAndNoteByResources(resources)
|
||||||
tags := genTags(events)
|
tags := genTags(events)
|
||||||
value := events[cnt-1].Value
|
value := events[cnt-1].Value
|
||||||
info := events[cnt-1].Info
|
info := events[cnt-1].Info
|
||||||
|
@ -156,6 +159,8 @@ func genContent(isUpgrade bool, events []*models.Event) (string, string) {
|
||||||
"Status": status,
|
"Status": status,
|
||||||
"Sname": sname,
|
"Sname": sname,
|
||||||
"Endpoint": endpoint,
|
"Endpoint": endpoint,
|
||||||
|
"Name": name,
|
||||||
|
"Note": note,
|
||||||
"CurNodePath": curNodePath,
|
"CurNodePath": curNodePath,
|
||||||
"Metric": metric,
|
"Metric": metric,
|
||||||
"Tags": tags,
|
"Tags": tags,
|
||||||
|
@ -282,6 +287,38 @@ func HostBindingsForMon(endpointList []string) ([]string, error) {
|
||||||
return list, nil
|
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 {
|
func getEndpoint(events []*models.Event) []string {
|
||||||
endpointList := []string{}
|
endpointList := []string{}
|
||||||
for i := 0; i < len(events); i++ {
|
for i := 0; i < len(events); i++ {
|
||||||
|
|
Loading…
Reference in New Issue