SetAlertmanagerConfig gets the status of an alertmanager instance
(ctx context.Context, amConfig string, templates map[string]string)
| 984 | |
| 985 | // SetAlertmanagerConfig gets the status of an alertmanager instance |
| 986 | func (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 |
| 1019 | func (c *Client) DeleteAlertmanagerConfig(ctx context.Context) error { |