MCPcopy Index your code
hub / github.com/cortexproject/cortex / SetAlertmanagerConfig

Method SetAlertmanagerConfig

integration/e2ecortex/client.go:986–1016  ·  view source on GitHub ↗

SetAlertmanagerConfig gets the status of an alertmanager instance

(ctx context.Context, amConfig string, templates map[string]string)

Source from the content-addressed store, hash-verified

984
985// SetAlertmanagerConfig gets the status of an alertmanager instance
986func (c *Client) SetAlertmanagerConfig(ctx context.Context, amConfig string, templates map[string]string) error {
987 u := c.alertmanagerClient.URL("/api/v1/alerts", nil)
988
989 data, err := yaml.Marshal(&userConfig{
990 AlertmanagerConfig: amConfig,
991 TemplateFiles: templates,
992 })
993 if err != nil {
994 return err
995 }
996
997 req, err := http.NewRequest(http.MethodPost, u.String(), bytes.NewReader(data))
998 if err != nil {
999 return fmt.Errorf("error creating request: %v", err)
1000 }
1001
1002 resp, body, err := c.alertmanagerClient.Do(ctx, req)
1003 if err != nil {
1004 return err
1005 }
1006
1007 if resp.StatusCode == http.StatusNotFound {
1008 return ErrNotFound
1009 }
1010
1011 if resp.StatusCode != http.StatusCreated {
1012 return fmt.Errorf("setting config failed with status %d and error %v", resp.StatusCode, string(body))
1013 }
1014
1015 return nil
1016}
1017
1018// DeleteAlertmanagerConfig gets the status of an alertmanager instance
1019func (c *Client) DeleteAlertmanagerConfig(ctx context.Context) error {

Callers 2

TestAlertmanagerStoreAPIFunction · 0.95
Test_Alertmanager_UTF8Function · 0.95

Calls 3

StringMethod · 0.65
DoMethod · 0.65
MarshalMethod · 0.45

Tested by 2

TestAlertmanagerStoreAPIFunction · 0.76
Test_Alertmanager_UTF8Function · 0.76