MCPcopy Create free account
hub / github.com/cortexproject/cortex / SendAlertToAlermanager

Method SendAlertToAlermanager

integration/e2ecortex/client.go:1043–1066  ·  view source on GitHub ↗

SendAlertToAlermanager sends alerts to the Alertmanager API

(ctx context.Context, alert *model.Alert)

Source from the content-addressed store, hash-verified

1041
1042// SendAlertToAlermanager sends alerts to the Alertmanager API
1043func (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
1068func (c *Client) GetAlertsV2(ctx context.Context) ([]model.Alert, error) {
1069 u := c.alertmanagerClient.URL("api/prom/api/v2/alerts", nil)

Callers 3

TestAlertmanagerStoreAPIFunction · 0.95
TestAlertmanagerShardingFunction · 0.95
Test_Alertmanager_UTF8Function · 0.95

Calls 4

StringMethod · 0.65
SetMethod · 0.65
DoMethod · 0.65
MarshalMethod · 0.45

Tested by 3

TestAlertmanagerStoreAPIFunction · 0.76
TestAlertmanagerShardingFunction · 0.76
Test_Alertmanager_UTF8Function · 0.76