cloudflare/pint

Public

mirrored from https://github.com/cloudflare/pintAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.44.2

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

internal/config/alerts.go

54lines · modecode

1package config
2
3import (
4 "fmt"
5
6 "github.com/cloudflare/pint/internal/checks"
7)
8
9type AlertsSettings struct {
10 Range string `hcl:"range" json:"range"`
11 Step string `hcl:"step" json:"step"`
12 Resolve string `hcl:"resolve" json:"resolve"`
13 MinCount int `hcl:"minCount,optional" json:"minCount,omitempty"`
14 Severity string `hcl:"severity,optional" json:"severity,omitempty"`
15}
16
17func (as AlertsSettings) validate() error {
18 if as.Range != "" {
19 if _, err := parseDuration(as.Range); err != nil {
20 return err
21 }
22 }
23 if as.Step != "" {
24 if _, err := parseDuration(as.Step); err != nil {
25 return err
26 }
27 }
28 if as.Resolve != "" {
29 if _, err := parseDuration(as.Resolve); err != nil {
30 return err
31 }
32 }
33 if as.MinCount < 0 {
34 return fmt.Errorf("minCount cannot be < 0, got %d", as.MinCount)
35 }
36 if as.Severity != "" {
37 sev, err := checks.ParseSeverity(as.Severity)
38 if err != nil {
39 return err
40 }
41 if as.MinCount <= 0 && sev > checks.Information {
42 return fmt.Errorf("cannot set serverity to %q when minCount is 0", as.Severity)
43 }
44 }
45 return nil
46}
47
48func (as AlertsSettings) getSeverity(fallback checks.Severity) checks.Severity {
49 if as.Severity != "" {
50 sev, _ := checks.ParseSeverity(as.Severity)
51 return sev
52 }
53 return fallback
54}
55