Skip to content
This repository has been archived by the owner on Aug 14, 2022. It is now read-only.

Link to Prometheus on alertname #171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion default.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{ define "telegram.default" }}
{{ range .Alerts }}
{{ if eq .Status "firing"}}🔥 <b>{{ .Labels.alertname }}</b> 🔥{{ else }}✅ <b>{{ .Labels.alertname }}</b> ✅{{ end }}
{{ if eq .Status "firing"}}🔥 <a href="{{ .GeneratorURL }}"><b>{{ .Labels.alertname }}</b></a> 🔥{{ else }}✅ <b>{{ .Labels.alertname }}</b> ✅{{ end }}
<b>Labels:</b>{{ range $key, $value := .Labels }}{{ if ne $key "alertname" }}
{{ $key }}: {{ $value }}{{ end }}{{ end }}
<b>Annotations:</b>{{ range $key, $value := .Annotations }}
Expand Down
8 changes: 4 additions & 4 deletions tests/workflows/telegram/alerts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var alertsWorkflows = []workflow{{
}},
replies: []reply{{
recipient: "123",
message: "🔥 <b>damn</b> 🔥\n<b>Labels:</b>\n bot: alertmanager-bot\n<b>Annotations:</b>\n msg: sup?!\n runbook: https://example.com/runbook\n<b>Duration:</b> 1 hour",
message: "🔥 <a href=\"http://exmaple.com/graph?g0.expr=damn\"><b>damn</b></a> 🔥\n<b>Labels:</b>\n bot: alertmanager-bot\n<b>Annotations:</b>\n msg: sup?!\n runbook: https://example.com/runbook\n<b>Duration:</b> 1 hour",
}},
counter: map[string]uint{telegram.CommandAlerts: 1},
logs: []string{
Expand All @@ -56,7 +56,7 @@ var alertsWorkflows = []workflow{{
require.Equal(t, "true", r.URL.Query().Get("unprocessed"))

return fmt.Sprintf(
`[{"labels":{"alertname":"damn","bot":"alertmanager-bot"},"annotations":{"msg":"sup?!","runbook":"https://example.com/runbook"},"startsAt":"%s"}]`,
`[{"labels":{"alertname":"damn","bot":"alertmanager-bot"},"annotations":{"msg":"sup?!","runbook":"https://example.com/runbook"},"startsAt":"%s","generatorURL": "http://exmaple.com/graph?g0.expr=damn"}]`,
time.Now().Add(-time.Hour).Format(time.RFC3339),
)
},
Expand All @@ -74,7 +74,7 @@ var alertsWorkflows = []workflow{{
}},
replies: []reply{{
recipient: "123",
message: "🔥 <b>damn</b> 🔥\n<b>Labels:</b>\n bot: alertmanager-bot\n<b>Annotations:</b>\n msg: sup?!\n runbook: https://example.com/runbook\n<b>Duration:</b> 1 hour",
message: "🔥 <a href=\"http://exmaple.com/graph?g0.expr=damn\"><b>damn</b></a> 🔥\n<b>Labels:</b>\n bot: alertmanager-bot\n<b>Annotations:</b>\n msg: sup?!\n runbook: https://example.com/runbook\n<b>Duration:</b> 1 hour",
}},
counter: map[string]uint{telegram.CommandAlerts: 1},
logs: []string{
Expand All @@ -88,7 +88,7 @@ var alertsWorkflows = []workflow{{
require.Equal(t, "true", r.URL.Query().Get("unprocessed"))

return fmt.Sprintf(
`[{"labels":{"alertname":"damn","bot":"alertmanager-bot"},"annotations":{"msg":"sup?!","runbook":"https://example.com/runbook"},"startsAt":"%s"}]`,
`[{"labels":{"alertname":"damn","bot":"alertmanager-bot"},"annotations":{"msg":"sup?!","runbook":"https://example.com/runbook"},"startsAt":"%s","generatorURL": "http://exmaple.com/graph?g0.expr=damn"}]`,
time.Now().Add(-time.Hour).Format(time.RFC3339),
)
},
Expand Down
2 changes: 1 addition & 1 deletion tests/workflows/telegram/telegram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var (
Annotations: template.KV{"message": "Something is on fire"},
//StartsAt: time.Now().Add(-time.Hour),
EndsAt: time.Time{},
GeneratorURL: "http://localhost:9090/graph?g0.expr=vector%28666%29\\u0026g0.tab=1",
GeneratorURL: "http://localhost:9090/graph?g0.expr=fire",
Fingerprint: "",
}},
GroupLabels: template.KV{"alertname": "Fire"},
Expand Down
6 changes: 3 additions & 3 deletions tests/workflows/telegram/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var webhookWorkflows = []workflow{{
message: "Hey, Elliot! I will now keep you up to date!\n/help",
}, {
recipient: "123",
message: "🔥 <b>fire</b> 🔥\n<b>Labels:</b>\n severity: critical\n<b>Annotations:</b>\n message: Something is on fire\n<b>Duration:</b> 1 hour",
message: "🔥 <a href=\"http://localhost:9090/graph?g0.expr=fire\"><b>fire</b></a> 🔥\n<b>Labels:</b>\n severity: critical\n<b>Annotations:</b>\n message: Something is on fire\n<b>Duration:</b> 1 hour",
}},
counter: map[string]uint{telegram.CommandStart: 1},
logs: []string{
Expand Down Expand Up @@ -61,7 +61,7 @@ var webhookWorkflows = []workflow{{
message: "Hey! I will now keep you all up to date!\n/help",
}, {
recipient: "-1234",
message: "🔥 <b>fire</b> 🔥\n<b>Labels:</b>\n severity: critical\n<b>Annotations:</b>\n message: Something is on fire\n<b>Duration:</b> 1 hour",
message: "🔥 <a href=\"http://localhost:9090/graph?g0.expr=fire\"><b>fire</b></a> 🔥\n<b>Labels:</b>\n severity: critical\n<b>Annotations:</b>\n message: Something is on fire\n<b>Duration:</b> 1 hour",
}},
counter: map[string]uint{telegram.CommandStart: 1},
logs: []string{
Expand Down Expand Up @@ -101,7 +101,7 @@ var webhookWorkflows = []workflow{{
message: "Hey! I will now keep you all up to date!\n/help",
}, {
recipient: "-1234",
message: "🔥 <b>fire</b> 🔥\n<b>Labels:</b>\n severity: critical\n<b>Annotations:</b>\n message: Something is on fire\n<b>Duration:</b> 1 hour",
message: "🔥 <a href=\"http://localhost:9090/graph?g0.expr=fire\"><b>fire</b></a> 🔥\n<b>Labels:</b>\n severity: critical\n<b>Annotations:</b>\n message: Something is on fire\n<b>Duration:</b> 1 hour",
}},
counter: map[string]uint{telegram.CommandStart: 2},
logs: []string{
Expand Down