2018-05-14 12:36:24 +00:00
|
|
|
// Copyright 2018 Prometheus Team
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2017-04-20 09:04:17 +00:00
|
|
|
package format
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
|
2018-04-11 09:17:41 +00:00
|
|
|
"github.com/prometheus/alertmanager/client"
|
2017-04-20 09:04:17 +00:00
|
|
|
"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)
|
|
|
|
}
|
|
|
|
|
2018-04-11 09:17:41 +00:00
|
|
|
func (formatter *JSONFormatter) FormatAlerts(alerts []*client.ExtendedAlert) error {
|
2017-04-20 09:04:17 +00:00
|
|
|
enc := json.NewEncoder(formatter.writer)
|
|
|
|
return enc.Encode(alerts)
|
|
|
|
}
|
|
|
|
|
2018-04-11 09:17:41 +00:00
|
|
|
func (formatter *JSONFormatter) FormatConfig(status *client.ServerStatus) error {
|
2017-04-20 09:04:17 +00:00
|
|
|
enc := json.NewEncoder(formatter.writer)
|
2018-04-11 09:17:41 +00:00
|
|
|
return enc.Encode(status)
|
2017-04-20 09:04:17 +00:00
|
|
|
}
|