From 78e955b8adb9b8f5fdb9777e8189ffd5ed59a7ef Mon Sep 17 00:00:00 2001 From: Sergey <83376337+freak12techno@users.noreply.github.com> Date: Sun, 7 Jan 2024 02:53:45 +0300 Subject: [PATCH] fix: fixed sending messages on errors (#33) --- pkg/alertmanager/alertmanager.go | 10 ++++++++++ pkg/app/silences_create.go | 4 ++-- pkg/app/silences_list.go | 4 ++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/alertmanager/alertmanager.go b/pkg/alertmanager/alertmanager.go index ece2846..23e4839 100644 --- a/pkg/alertmanager/alertmanager.go +++ b/pkg/alertmanager/alertmanager.go @@ -147,10 +147,20 @@ func (g *Alertmanager) DoQuery(method string, url string, body interface{}) (io. resp, err := client.Do(req) if err != nil { + g.Logger.Error(). + Str("url", url). + Str("method", method). + Err(err). + Msg("Error querying Alertmanager") return nil, err } if resp.StatusCode >= http.StatusBadRequest { + g.Logger.Error(). + Str("url", url). + Str("method", method). + Int("status", resp.StatusCode). + Msg("Got error code from Alertmanager") return nil, fmt.Errorf("Could not fetch request. Status code: %d", resp.StatusCode) } diff --git a/pkg/app/silences_create.go b/pkg/app/silences_create.go index a709b65..157a1d2 100644 --- a/pkg/app/silences_create.go +++ b/pkg/app/silences_create.go @@ -17,7 +17,7 @@ func (a *App) HandleNewSilence(c tele.Context) error { silenceInfo, err := utils.ParseSilenceOptions(c.Text(), c) if err != "" { - return c.Reply(err) + return c.Reply(fmt.Sprintf("Error parsing silence option: %s\n", err)) } silenceResponse, silenceErr := a.Grafana.CreateSilence(*silenceInfo) @@ -64,7 +64,7 @@ func (a *App) HandleAlertmanagerNewSilence(c tele.Context) error { silenceInfo, err := utils.ParseSilenceOptions(c.Text(), c) if err != "" { - return c.Reply(err) + return c.Reply(fmt.Sprintf("Error parsing silence option: %s\n", err)) } silenceResponse, silenceErr := a.Alertmanager.CreateSilence(*silenceInfo) diff --git a/pkg/app/silences_list.go b/pkg/app/silences_list.go index 797fba2..e9415ee 100644 --- a/pkg/app/silences_list.go +++ b/pkg/app/silences_list.go @@ -16,7 +16,7 @@ func (a *App) HandleListSilences(c tele.Context) error { silencesWithAlerts, err := types.GetSilencesWithAlerts(a.Grafana) if err != nil { - return c.Reply(err) + return c.Reply(fmt.Sprintf("Error fetching silences: %s\n", err)) } template, err := a.TemplateManager.Render("silences_list", render.RenderStruct{ @@ -44,7 +44,7 @@ func (a *App) HandleAlertmanagerListSilences(c tele.Context) error { silencesWithAlerts, err := types.GetSilencesWithAlerts(a.Alertmanager) if err != nil { - return c.Reply(err) + return c.Reply(fmt.Sprintf("Error fetching silences: %s\n", err)) } template, err := a.TemplateManager.Render("silences_list", render.RenderStruct{