2020-02-16 18:59:02 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import "time"
|
|
|
|
|
2020-03-13 10:19:31 +00:00
|
|
|
// Rule is basic alert entity
|
|
|
|
type Rule struct {
|
2020-02-16 18:59:02 +00:00
|
|
|
Name string
|
|
|
|
Expr string
|
|
|
|
For time.Duration
|
2020-02-21 21:15:05 +00:00
|
|
|
Labels map[string]string
|
2020-03-13 10:19:31 +00:00
|
|
|
Annotations map[string]string
|
2020-02-16 18:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Group grouping array of alert
|
|
|
|
type Group struct {
|
|
|
|
Name string
|
2020-03-13 10:19:31 +00:00
|
|
|
Rules []Rule
|
2020-02-16 18:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Parse parses config from given file
|
|
|
|
func Parse(filepath string) ([]Group, error) {
|
2020-03-13 10:19:31 +00:00
|
|
|
return []Group{{
|
|
|
|
Name: "foobar",
|
|
|
|
Rules: []Rule{{
|
|
|
|
Name: "vmrowsalert",
|
|
|
|
Expr: "vm_rows",
|
|
|
|
For: 1 * time.Second,
|
|
|
|
Labels: map[string]string{
|
|
|
|
"alert_label": "value1",
|
|
|
|
"alert_label2": "value2",
|
|
|
|
},
|
|
|
|
Annotations: map[string]string{
|
|
|
|
"summary": "{{ $value }}",
|
|
|
|
"description": "LABELS: {{ $labels }}",
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
}}, nil
|
2020-02-16 18:59:02 +00:00
|
|
|
}
|