alertmanager/cli/format/format_json.go

38 lines
811 B
Go
Raw Permalink Normal View History

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 {
writer io.Writer
}
func init() {
2017-11-01 22:08:34 +00:00
Formatters["json"] = &JSONFormatter{writer: os.Stdout}
}
2017-11-01 22:08:34 +00:00
func (formatter *JSONFormatter) SetOutput(writer io.Writer) {
formatter.writer = writer
}
2017-11-01 22:08:34 +00:00
func (formatter *JSONFormatter) FormatSilences(silences []types.Silence) error {
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 {
enc := json.NewEncoder(formatter.writer)
return enc.Encode(alerts)
}
2017-11-01 22:08:34 +00:00
func (formatter *JSONFormatter) FormatConfig(config Config) error {
enc := json.NewEncoder(formatter.writer)
return enc.Encode(config)
}