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"
|
|
|
|
|
2019-03-13 16:01:08 +00:00
|
|
|
"github.com/prometheus/alertmanager/api/v2/models"
|
2017-04-20 09:04:17 +00:00
|
|
|
)
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-03-13 16:01:08 +00:00
|
|
|
func (formatter *JSONFormatter) FormatSilences(silences []models.GettableSilence) error {
|
2017-04-20 09:04:17 +00:00
|
|
|
enc := json.NewEncoder(formatter.writer)
|
|
|
|
return enc.Encode(silences)
|
|
|
|
}
|
|
|
|
|
2019-03-13 16:01:08 +00:00
|
|
|
func (formatter *JSONFormatter) FormatAlerts(alerts []*models.GettableAlert) error {
|
2017-04-20 09:04:17 +00:00
|
|
|
enc := json.NewEncoder(formatter.writer)
|
|
|
|
return enc.Encode(alerts)
|
|
|
|
}
|
|
|
|
|
2019-03-13 16:01:08 +00:00
|
|
|
func (formatter *JSONFormatter) FormatConfig(status *models.AlertmanagerStatus) 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
|
|
|
}
|
2020-05-18 13:25:15 +00:00
|
|
|
|
|
|
|
func (formatter *JSONFormatter) FormatClusterStatus(status *models.ClusterStatus) error {
|
|
|
|
enc := json.NewEncoder(formatter.writer)
|
|
|
|
return enc.Encode(status)
|
|
|
|
}
|