...

Source file src/github.com/prometheus/alertmanager/cli/format/format_json.go

Documentation: github.com/prometheus/alertmanager/cli/format

     1  // Copyright 2018 Prometheus Team
     2  // Licensed under the Apache License, Version 2.0 (the "License");
     3  // you may not use this file except in compliance with the License.
     4  // You may obtain a copy of the License at
     5  //
     6  // http://www.apache.org/licenses/LICENSE-2.0
     7  //
     8  // Unless required by applicable law or agreed to in writing, software
     9  // distributed under the License is distributed on an "AS IS" BASIS,
    10  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package format
    15  
    16  import (
    17  	"encoding/json"
    18  	"io"
    19  	"os"
    20  
    21  	"github.com/prometheus/alertmanager/api/v2/models"
    22  )
    23  
    24  type JSONFormatter struct {
    25  	writer io.Writer
    26  }
    27  
    28  func init() {
    29  	Formatters["json"] = &JSONFormatter{writer: os.Stdout}
    30  }
    31  
    32  func (formatter *JSONFormatter) SetOutput(writer io.Writer) {
    33  	formatter.writer = writer
    34  }
    35  
    36  func (formatter *JSONFormatter) FormatSilences(silences []models.GettableSilence) error {
    37  	enc := json.NewEncoder(formatter.writer)
    38  	return enc.Encode(silences)
    39  }
    40  
    41  func (formatter *JSONFormatter) FormatAlerts(alerts []*models.GettableAlert) error {
    42  	enc := json.NewEncoder(formatter.writer)
    43  	return enc.Encode(alerts)
    44  }
    45  
    46  func (formatter *JSONFormatter) FormatConfig(status *models.AlertmanagerStatus) error {
    47  	enc := json.NewEncoder(formatter.writer)
    48  	return enc.Encode(status)
    49  }
    50  
    51  func (formatter *JSONFormatter) FormatClusterStatus(status *models.ClusterStatus) error {
    52  	enc := json.NewEncoder(formatter.writer)
    53  	return enc.Encode(status)
    54  }
    55  

View as plain text