forked from prometheus/alertmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
format_json.go
37 lines (29 loc) · 811 Bytes
/
format_json.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package format
import (
"encoding/json"
"io"
"os"
"github.com/prometheus/alertmanager/dispatch"
"github.com/prometheus/alertmanager/types"
)
type JSONFormatter struct {
writer io.Writer
}
func init() {
Formatters["json"] = &JSONFormatter{writer: os.Stdout}
}
func (formatter *JSONFormatter) SetOutput(writer io.Writer) {
formatter.writer = writer
}
func (formatter *JSONFormatter) FormatSilences(silences []types.Silence) error {
enc := json.NewEncoder(formatter.writer)
return enc.Encode(silences)
}
func (formatter *JSONFormatter) FormatAlerts(alerts []*dispatch.APIAlert) error {
enc := json.NewEncoder(formatter.writer)
return enc.Encode(alerts)
}
func (formatter *JSONFormatter) FormatConfig(config Config) error {
enc := json.NewEncoder(formatter.writer)
return enc.Encode(config)
}