cloudflare/pint

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.73.7

Branches

Tags

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

Clone

HTTPS

Download ZIP

internal/config/alerts.go

55lines · 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 Comment string `hcl:"comment,optional" json:"comment,omitempty"`
14 Severity string `hcl:"severity,optional" json:"severity,omitempty"`
15 MinCount int `hcl:"minCount,optional" json:"minCount,omitempty"`
16}
17
18func (as AlertsSettings) validate() error {
19 if as.Range != "" {
20 if _, err := parseDuration(as.Range); err != nil {
21 return err
22 }
23 }
24 if as.Step != "" {
25 if _, err := parseDuration(as.Step); err != nil {
26 return err
27 }
28 }
29 if as.Resolve != "" {
30 if _, err := parseDuration(as.Resolve); err != nil {
31 return err
32 }
33 }
34 if as.MinCount < 0 {
35 return fmt.Errorf("minCount cannot be < 0, got %d", as.MinCount)
36 }
37 if as.Severity != "" {
38 sev, err := checks.ParseSeverity(as.Severity)
39 if err != nil {
40 return err
41 }
42 if as.MinCount <= 0 && sev > checks.Information {
43 return fmt.Errorf("cannot set serverity to %q when minCount is 0", as.Severity)
44 }
45 }
46 return nil
47}
48
49func (as AlertsSettings) getSeverity(fallback checks.Severity) checks.Severity {
50 if as.Severity != "" {
51 sev, _ := checks.ParseSeverity(as.Severity)
52 return sev
53 }
54 return fallback
55}
56