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

Method GetAlertmanagerConfig

integration/e2ecortex/client.go:951–983  ·  view source on GitHub ↗

GetAlertmanagerConfig gets the status of an alertmanager instance

(ctx context.Context)

Source from the content-addressed store, hash-verified

949
950// GetAlertmanagerConfig gets the status of an alertmanager instance
951func (c *Client) GetAlertmanagerConfig(ctx context.Context) (*alertConfig.Config, error) {
952 u := c.alertmanagerClient.URL("/api/prom/api/v2/status", nil)
953
954 req, err := http.NewRequest(http.MethodGet, u.String(), nil)
955 if err != nil {
956 return nil, fmt.Errorf("error creating request: %v", err)
957 }
958
959 resp, body, err := c.alertmanagerClient.Do(ctx, req)
960 if err != nil {
961 return nil, err
962 }
963
964 if resp.StatusCode == http.StatusNotFound {
965 return nil, ErrNotFound
966 }
967
968 if resp.StatusCode/100 != 2 {
969 return nil, fmt.Errorf("getting config failed with status %d and error %v", resp.StatusCode, string(body))
970 }
971
972 cfg := &open_api_models.AlertmanagerStatus{}
973 err = yaml.Unmarshal(body, cfg)
974
975 if err != nil {
976 return nil, err
977 }
978
979 original := &alertConfig.Config{}
980 err = yaml.Unmarshal([]byte(*cfg.Config.Original), original)
981
982 return original, err
983}
984
985// SetAlertmanagerConfig gets the status of an alertmanager instance
986func (c *Client) SetAlertmanagerConfig(ctx context.Context, amConfig string, templates map[string]string) error {

Callers 3

TestAlertmanagerFunction · 0.95
TestAlertmanagerStoreAPIFunction · 0.95
TestAlertmanagerShardingFunction · 0.80

Calls 3

StringMethod · 0.65
DoMethod · 0.65
UnmarshalMethod · 0.45

Tested by 3

TestAlertmanagerFunction · 0.76
TestAlertmanagerStoreAPIFunction · 0.76
TestAlertmanagerShardingFunction · 0.64