2017-04-20 09:04:17 +00:00
|
|
|
package format
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/prometheus/alertmanager/dispatch"
|
|
|
|
"github.com/prometheus/alertmanager/types"
|
|
|
|
)
|
|
|
|
|
2017-11-01 22:08:34 +00:00
|
|
|
type JSONFormatter struct {
|
2017-04-20 09:04:17 +00:00
|
|
|
writer io.Writer
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2017-11-01 22:08:34 +00:00
|
|
|
Formatters["json"] = &JSONFormatter{writer: os.Stdout}
|
2017-04-20 09:04:17 +00:00
|
|
|
}
|
|
|
|
|
2017-11-01 22:08:34 +00:00
|
|
|
func (formatter *JSONFormatter) SetOutput(writer io.Writer) {
|
2017-04-20 09:04:17 +00:00
|
|
|
formatter.writer = writer
|
|
|
|
}
|
|
|
|
|
2017-11-01 22:08:34 +00:00
|
|
|
func (formatter *JSONFormatter) FormatSilences(silences []types.Silence) error {
|
2017-04-20 09:04:17 +00:00
|
|
|
enc := json.NewEncoder(formatter.writer)
|
|
|
|
return enc.Encode(silences)
|
|
|
|
}
|
|
|
|
|
2017-11-01 22:08:34 +00:00
|
|
|
func (formatter *JSONFormatter) FormatAlerts(alerts []*dispatch.APIAlert) error {
|
2017-04-20 09:04:17 +00:00
|
|
|
enc := json.NewEncoder(formatter.writer)
|
|
|
|
return enc.Encode(alerts)
|
|
|
|
}
|
|
|
|
|
2017-11-01 22:08:34 +00:00
|
|
|
func (formatter *JSONFormatter) FormatConfig(config Config) error {
|
2017-04-20 09:04:17 +00:00
|
|
|
enc := json.NewEncoder(formatter.writer)
|
|
|
|
return enc.Encode(config)
|
|
|
|
}
|