mirror of
https://github.com/prometheus/alertmanager
synced 2025-03-01 17:20:51 +00:00
* cli: move commands to cli/cmd * cli: use StatusAPI interface for config command * cli: use SilenceAPI interface for silence commands * cli: use AlertAPI for alert command * cli: move back commands to cli package And move API client code to its own package. * cli: remove unused structs
38 lines
826 B
Go
38 lines
826 B
Go
package format
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
"os"
|
|
|
|
"github.com/prometheus/alertmanager/client"
|
|
"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 []*client.ExtendedAlert) error {
|
|
enc := json.NewEncoder(formatter.writer)
|
|
return enc.Encode(alerts)
|
|
}
|
|
|
|
func (formatter *JSONFormatter) FormatConfig(status *client.ServerStatus) error {
|
|
enc := json.NewEncoder(formatter.writer)
|
|
return enc.Encode(status)
|
|
}
|