remove # from event

main
bel 2024-04-13 10:03:54 -06:00
parent 10630df394
commit 85d589a570
4 changed files with 12 additions and 7 deletions

View File

@ -38,8 +38,9 @@ func newConfig(ctx context.Context) (Config, error) {
func newConfigFromEnv(ctx context.Context, getEnv func(string) string) (Config, error) { func newConfigFromEnv(ctx context.Context, getEnv func(string) string) (Config, error) {
def := Config{ def := Config{
Port: 38080, Port: 38080,
OllamaModel: "gemma:2b", OllamaModel: "gemma:2b",
AssetPattern: `(dpg|svc|red)-[a-z0-9-]*`,
} }
var m map[string]any var m map[string]any

View File

@ -17,7 +17,7 @@ func TestFillTestdata(t *testing.T) {
defer can() defer can()
ram := NewRAM() ram := NewRAM()
if err := FillWithTestdata(ctx, ram, `(dpg|svc|svc)-[0-9a-z]*`); err != nil { if err := FillWithTestdata(ctx, ram, renderAssetPattern); err != nil {
t.Fatal(err) t.Fatal(err)
} }
n := 0 n := 0

View File

@ -127,7 +127,7 @@ func ParseSlack(b []byte, assetPattern string) (Message, error) {
Channel: s.Event.Channel, Channel: s.Event.Channel,
Thread: s.Event.ID, Thread: s.Event.ID,
EventName: strings.Split(s.Event.Attachments[0].Title, ": Firing: ")[1], EventName: strings.Split(s.Event.Attachments[0].Title, ": Firing: ")[1],
Event: strings.Split(s.Event.Attachments[0].Title, ":")[0], Event: strings.TrimPrefix(strings.Split(s.Event.Attachments[0].Title, ":")[0], "#"),
Plaintext: s.Event.Attachments[0].Text, Plaintext: s.Event.Attachments[0].Text,
Asset: asset.FindString(s.Event.Attachments[0].Text), Asset: asset.FindString(s.Event.Attachments[0].Text),
Resolved: !strings.HasPrefix(s.Event.Attachments[0].Color, "F"), Resolved: !strings.HasPrefix(s.Event.Attachments[0].Color, "F"),

View File

@ -7,6 +7,10 @@ import (
"testing" "testing"
) )
var (
renderAssetPattern = `(dpg|svc|red)-[a-z0-9-]*[a-z0-9]`
)
func TestParseSlackTestdata(t *testing.T) { func TestParseSlackTestdata(t *testing.T) {
cases := map[string]struct { cases := map[string]struct {
slackMessage slackMessage slackMessage slackMessage
@ -74,7 +78,7 @@ func TestParseSlackTestdata(t *testing.T) {
Channel: "C06U1DDBBU4", Channel: "C06U1DDBBU4",
Thread: "1712927439.728409", Thread: "1712927439.728409",
EventName: "Alertconfig Workflow Failed", EventName: "Alertconfig Workflow Failed",
Event: "#11071", Event: "11071",
Plaintext: "At least one alertconfig run has failed unexpectedly.\nDashboard: <https://grafana.render.com/d/VLZU83YVk?orgId=1>\nPanel: <https://grafana.render.com/d/VLZU83YVk?orgId=1&amp;viewPanel=17>\nSource: <https://grafana.render.com/alerting/grafana/fa7b06b8-b4d8-4979-bce7-5e1c432edd81/view?orgId=1>", Plaintext: "At least one alertconfig run has failed unexpectedly.\nDashboard: <https://grafana.render.com/d/VLZU83YVk?orgId=1>\nPanel: <https://grafana.render.com/d/VLZU83YVk?orgId=1&amp;viewPanel=17>\nSource: <https://grafana.render.com/alerting/grafana/fa7b06b8-b4d8-4979-bce7-5e1c432edd81/view?orgId=1>",
Asset: "", Asset: "",
}, },
@ -108,7 +112,7 @@ func TestParseSlackTestdata(t *testing.T) {
Channel: "C06U1DDBBU4", Channel: "C06U1DDBBU4",
Thread: "1712916339.000300", Thread: "1712916339.000300",
EventName: "Alertconfig Workflow Failed", EventName: "Alertconfig Workflow Failed",
Event: "#11069", Event: "11069",
Plaintext: "At least one alertconfig run has failed unexpectedly.\nDashboard: <https://grafana.render.com/d/VLZU83YVk?orgId=1>\nPanel: <https://grafana.render.com/d/VLZU83YVk?orgId=1&amp;viewPanel=17>\nSource: <https://grafana.render.com/alerting/grafana/fa7b06b8-b4d8-4979-bce7-5e1c432edd81/view?orgId=1>", Plaintext: "At least one alertconfig run has failed unexpectedly.\nDashboard: <https://grafana.render.com/d/VLZU83YVk?orgId=1>\nPanel: <https://grafana.render.com/d/VLZU83YVk?orgId=1&amp;viewPanel=17>\nSource: <https://grafana.render.com/alerting/grafana/fa7b06b8-b4d8-4979-bce7-5e1c432edd81/view?orgId=1>",
Asset: "", Asset: "",
Resolved: true, Resolved: true,
@ -135,7 +139,7 @@ func TestParseSlackTestdata(t *testing.T) {
}) })
t.Run("ParseSlack", func(t *testing.T) { t.Run("ParseSlack", func(t *testing.T) {
got, err := ParseSlack(b, `(red|dpg|svc)-[a-z0-9]*`) got, err := ParseSlack(b, renderAssetPattern)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }