GetRuleGroups gets the configured rule groups from the ruler.
()
| 784 | |
| 785 | // GetRuleGroups gets the configured rule groups from the ruler. |
| 786 | func (c *Client) GetRuleGroups() (map[string][]rulefmt.RuleGroup, error) { |
| 787 | // Create HTTP request |
| 788 | req, err := http.NewRequest("GET", fmt.Sprintf("http://%s/api/prom/rules", c.rulerAddress), nil) |
| 789 | if err != nil { |
| 790 | return nil, err |
| 791 | } |
| 792 | req.Header.Set("X-Scope-OrgID", c.orgID) |
| 793 | |
| 794 | ctx, cancel := context.WithTimeout(context.Background(), c.timeout) |
| 795 | defer cancel() |
| 796 | |
| 797 | // Execute HTTP request |
| 798 | res, err := c.httpClient.Do(req.WithContext(ctx)) |
| 799 | if err != nil { |
| 800 | return nil, err |
| 801 | } |
| 802 | |
| 803 | defer res.Body.Close() |
| 804 | rgs := map[string][]rulefmt.RuleGroup{} |
| 805 | |
| 806 | data, err := io.ReadAll(res.Body) |
| 807 | if err != nil { |
| 808 | return nil, err |
| 809 | } |
| 810 | |
| 811 | err = yaml.Unmarshal(data, rgs) |
| 812 | if err != nil { |
| 813 | return nil, err |
| 814 | } |
| 815 | |
| 816 | return rgs, nil |
| 817 | } |
| 818 | |
| 819 | // SetRuleGroup configures the provided rulegroup to the ruler. |
| 820 | func (c *Client) SetRuleGroup(rulegroup rulefmt.RuleGroup, namespace string) error { |