Created
December 11, 2023 00:06
-
-
Save sarfarazahmad19/a5a36ec50c1421e84c19e0e8c7242bdc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "os" | |
| "gopkg.in/yaml.v3" | |
| "github.com/prometheus/common/model" | |
| "github.com/prometheus/prometheus/model/rulefmt" | |
| //"github.com/prometheus/prometheus/rules" | |
| ) | |
| type RuleGroup struct { | |
| Name string `yaml:"name"` | |
| Interval model.Duration `yaml:"interval,omitempty"` | |
| Limit int `yaml:"limit,omitempty"` | |
| Rules []rulefmt.Rule `yaml:"rules"` | |
| } | |
| type Rule struct { | |
| Record string `yaml:"record,omitempty"` | |
| Alert string `yaml:"alert,omitempty"` | |
| Expr string `yaml:"expr"` | |
| For model.Duration `yaml:"for,omitempty"` | |
| KeepFiringFor model.Duration `yaml:"keep_firing_for,omitempty"` | |
| Labels map[string]string `yaml:"labels,omitempty"` | |
| Annotations map[string]string `yaml:"annotations,omitempty"` | |
| } | |
| type RuleGroups struct { | |
| Groups []RuleGroup `yaml:"groups"` | |
| } | |
| type Spec struct { | |
| Spec RuleGroups `yaml:"spec"` | |
| } | |
| func main() { | |
| yamlFile, err := os.ReadFile("./prometheus-operator-rules.yml") | |
| if err != nil { | |
| fmt.Println(err) | |
| return | |
| } | |
| var spec Spec | |
| err = yaml.Unmarshal(yamlFile, &spec) | |
| if err != nil { | |
| fmt.Println(err) | |
| } | |
| for _, rg := range spec.Spec.Groups { | |
| for _, rule := range rg.Rules { | |
| fmt.Printf("%v", rule.Labels) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment