Skip to content

Commit

Permalink
fix: fixed sending messages on errors (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno authored Jan 6, 2024
1 parent 6d64e92 commit 78e955b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
10 changes: 10 additions & 0 deletions pkg/alertmanager/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/app/silences_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/app/silences_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 78e955b

Please sign in to comment.