...
1
2
3
4
5
6
7
8
9
10
11
12
13
14 package format
15
16 import (
17 "io"
18 "time"
19
20 "github.com/go-openapi/strfmt"
21 "gopkg.in/alecthomas/kingpin.v2"
22
23 "github.com/prometheus/alertmanager/api/v2/models"
24 "github.com/prometheus/alertmanager/pkg/labels"
25 )
26
27 const DefaultDateFormat = "2006-01-02 15:04:05 MST"
28
29 var dateFormat *string
30
31 func InitFormatFlags(app *kingpin.Application) {
32 dateFormat = app.Flag("date.format", "Format of date output").Default(DefaultDateFormat).String()
33 }
34
35
36 type Formatter interface {
37 SetOutput(io.Writer)
38 FormatSilences([]models.GettableSilence) error
39 FormatAlerts([]*models.GettableAlert) error
40 FormatConfig(*models.AlertmanagerStatus) error
41 FormatClusterStatus(status *models.ClusterStatus) error
42 }
43
44
45 var Formatters = map[string]Formatter{}
46
47 func FormatDate(input strfmt.DateTime) string {
48 return time.Time(input).Format(*dateFormat)
49 }
50
51 func labelsMatcher(m models.Matcher) *labels.Matcher {
52 var t labels.MatchType
53
54 if m.IsEqual == nil {
55 isEqual := true
56 m.IsEqual = &isEqual
57 }
58 switch {
59 case !*m.IsRegex && *m.IsEqual:
60 t = labels.MatchEqual
61 case !*m.IsRegex && !*m.IsEqual:
62 t = labels.MatchNotEqual
63 case *m.IsRegex && *m.IsEqual:
64 t = labels.MatchRegexp
65 case *m.IsRegex && !*m.IsEqual:
66 t = labels.MatchNotRegexp
67 }
68
69 return &labels.Matcher{Type: t, Name: *m.Name, Value: *m.Value}
70 }
71
View as plain text