add html for prometheus

This commit is contained in:
Martin/Geno 2019-07-16 00:53:20 +02:00
parent 18676475d3
commit 7934b6893d
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
1 changed files with 16 additions and 1 deletions

View File

@ -29,16 +29,31 @@ func init() {
return return
} }
// title
content := strings.Join(request.GroupLabels.Values(), " ") content := strings.Join(request.GroupLabels.Values(), " ")
html := fmt.Sprintf(`<span style="font-weight: bold;">%s</span>`, content)
statusColor := "#ffff00"
switch request.Status {
case "resolved":
statusColor = "#00ff00"
case "firing":
statusColor = "#ff8700"
}
firingAlerts := request.Alerts.Firing() firingAlerts := request.Alerts.Firing()
if len(firingAlerts) > 0 { if len(firingAlerts) > 0 {
for _, a := range firingAlerts { for _, a := range firingAlerts {
if description, ok := a.Annotations["message"]; ok { if description, ok := a.Annotations["message"]; ok {
content = fmt.Sprintf("%s\n%s", content, description) content = fmt.Sprintf("%s\n%s", content, description)
html = fmt.Sprintf("%s<br/>%s", html, description)
} }
} }
content = fmt.Sprintf("[%s:%d] %s", request.Status, len(firingAlerts), content) content = fmt.Sprintf("[%s:%d] %s", request.Status, len(firingAlerts), content)
html = fmt.Sprintf(`<span style="color:%s">%s:%d</span> %s`, statusColor, request.Status, len(firingAlerts), html)
} else { } else {
html = fmt.Sprintf(`<span style="color:%s">%s</span> %s`, statusColor, request.Status, content)
content = fmt.Sprintf("[%s] %s", request.Status, content) content = fmt.Sprintf("[%s] %s", request.Status, content)
} }
@ -51,7 +66,7 @@ func init() {
continue continue
} }
logger.Infof("run hook") logger.Infof("run hook")
runtime.Notify(client, hook, content, content) runtime.Notify(client, hook, content, html)
ok = true ok = true
} }
if !ok { if !ok {