SendAlertToAlermanager sends alerts to the Alertmanager API
(ctx context.Context, alert *model.Alert)
| 1041 | |
| 1042 | // SendAlertToAlermanager sends alerts to the Alertmanager API |
| 1043 | func (c *Client) SendAlertToAlermanager(ctx context.Context, alert *model.Alert) error { |
| 1044 | u := c.alertmanagerClient.URL("/api/prom/api/v2/alerts", nil) |
| 1045 | |
| 1046 | data, err := json.Marshal([]types.Alert{{Alert: *alert}}) |
| 1047 | if err != nil { |
| 1048 | return fmt.Errorf("error marshaling the alert: %v", err) |
| 1049 | } |
| 1050 | |
| 1051 | req, err := http.NewRequest(http.MethodPost, u.String(), bytes.NewReader(data)) |
| 1052 | if err != nil { |
| 1053 | return fmt.Errorf("error creating request: %v", err) |
| 1054 | } |
| 1055 | req.Header.Set("Content-Type", "application/json") |
| 1056 | resp, body, err := c.alertmanagerClient.Do(ctx, req) |
| 1057 | if err != nil { |
| 1058 | return err |
| 1059 | } |
| 1060 | |
| 1061 | if resp.StatusCode != http.StatusOK { |
| 1062 | return fmt.Errorf("sending alert failed with status %d and error %v", resp.StatusCode, string(body)) |
| 1063 | } |
| 1064 | |
| 1065 | return nil |
| 1066 | } |
| 1067 | |
| 1068 | func (c *Client) GetAlertsV2(ctx context.Context) ([]model.Alert, error) { |
| 1069 | u := c.alertmanagerClient.URL("api/prom/api/v2/alerts", nil) |