mirror of
https://github.com/prometheus/alertmanager
synced 2024-12-12 09:26:17 +00:00
f1b920bcc9
The current Alertmanager API v1 is undocumented and written by hand. This patch introduces a new Alertmanager API - v2. The API is fully generated via an OpenAPI 2.0 [1] specification (see `api/v2/openapi.yaml`) with the exception of the http handlers itself. Pros: - Generated server code - Ability to generate clients in all major languages (Go, Java, JS, Python, Ruby, Haskell, *elm* [3] ...) - Strict contract (OpenAPI spec) between server and clients. - Instant feedback on frontend-breaking changes, due to strictly typed frontend language elm. - Generated documentation (See Alertmanager online Swagger UI [4]) Cons: - Dependency on open api ecosystem including go-swagger [2] In addition this patch includes the following changes. - README.md: Add API section - test: Duplicate acceptance test to API v1 & API v2 version The Alertmanager acceptance test framework has a decent test coverage on the Alertmanager API. Introducing the Alertmanager API v2 does not go hand in hand with deprecating API v1. They should live alongside each other for a couple of minor Alertmanager versions. Instead of porting the acceptance test framework to use the new API v2, this patch duplicates the acceptance tests, one using the API v1, the other API v2. Once API v1 is removed we can simply remove `test/with_api_v1` and bring `test/with_api_v2` to `test/`. [1] https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md [2] https://github.com/go-swagger/go-swagger/ [3] https://github.com/ahultgren/swagger-elm [4] http://petstore.swagger.io/?url=https://raw.githubusercontent.com/mxinden/alertmanager/apiv2/api/v2/openapi.yaml Signed-off-by: Max Leonard Inden <IndenML@gmail.com>
258 lines
5.3 KiB
Go
258 lines
5.3 KiB
Go
// Code generated by go-swagger; DO NOT EDIT.
|
|
|
|
package models
|
|
|
|
// This file was generated by the swagger tool.
|
|
// Editing this file might prove futile when you re-run the swagger generate command
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
strfmt "github.com/go-openapi/strfmt"
|
|
|
|
"github.com/go-openapi/errors"
|
|
"github.com/go-openapi/swag"
|
|
"github.com/go-openapi/validate"
|
|
)
|
|
|
|
// Silence silence
|
|
// swagger:model silence
|
|
type Silence struct {
|
|
|
|
// comment
|
|
Comment string `json:"comment,omitempty"`
|
|
|
|
// created by
|
|
CreatedBy string `json:"createdBy,omitempty"`
|
|
|
|
// ends at
|
|
// Format: date-time
|
|
EndsAt strfmt.DateTime `json:"endsAt,omitempty"`
|
|
|
|
// id
|
|
ID string `json:"id,omitempty"`
|
|
|
|
// matchers
|
|
// Required: true
|
|
Matchers Matchers `json:"matchers"`
|
|
|
|
// starts at
|
|
// Format: date-time
|
|
StartsAt strfmt.DateTime `json:"startsAt,omitempty"`
|
|
|
|
// status
|
|
Status *SilenceStatus `json:"status,omitempty"`
|
|
|
|
// updated at
|
|
// Format: date-time
|
|
UpdatedAt strfmt.DateTime `json:"updatedAt,omitempty"`
|
|
}
|
|
|
|
// Validate validates this silence
|
|
func (m *Silence) Validate(formats strfmt.Registry) error {
|
|
var res []error
|
|
|
|
if err := m.validateEndsAt(formats); err != nil {
|
|
res = append(res, err)
|
|
}
|
|
|
|
if err := m.validateMatchers(formats); err != nil {
|
|
res = append(res, err)
|
|
}
|
|
|
|
if err := m.validateStartsAt(formats); err != nil {
|
|
res = append(res, err)
|
|
}
|
|
|
|
if err := m.validateStatus(formats); err != nil {
|
|
res = append(res, err)
|
|
}
|
|
|
|
if err := m.validateUpdatedAt(formats); err != nil {
|
|
res = append(res, err)
|
|
}
|
|
|
|
if len(res) > 0 {
|
|
return errors.CompositeValidationError(res...)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (m *Silence) validateEndsAt(formats strfmt.Registry) error {
|
|
|
|
if swag.IsZero(m.EndsAt) { // not required
|
|
return nil
|
|
}
|
|
|
|
if err := validate.FormatOf("endsAt", "body", "date-time", m.EndsAt.String(), formats); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (m *Silence) validateMatchers(formats strfmt.Registry) error {
|
|
|
|
if err := validate.Required("matchers", "body", m.Matchers); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := m.Matchers.Validate(formats); err != nil {
|
|
if ve, ok := err.(*errors.Validation); ok {
|
|
return ve.ValidateName("matchers")
|
|
}
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (m *Silence) validateStartsAt(formats strfmt.Registry) error {
|
|
|
|
if swag.IsZero(m.StartsAt) { // not required
|
|
return nil
|
|
}
|
|
|
|
if err := validate.FormatOf("startsAt", "body", "date-time", m.StartsAt.String(), formats); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (m *Silence) validateStatus(formats strfmt.Registry) error {
|
|
|
|
if swag.IsZero(m.Status) { // not required
|
|
return nil
|
|
}
|
|
|
|
if m.Status != nil {
|
|
if err := m.Status.Validate(formats); err != nil {
|
|
if ve, ok := err.(*errors.Validation); ok {
|
|
return ve.ValidateName("status")
|
|
}
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (m *Silence) validateUpdatedAt(formats strfmt.Registry) error {
|
|
|
|
if swag.IsZero(m.UpdatedAt) { // not required
|
|
return nil
|
|
}
|
|
|
|
if err := validate.FormatOf("updatedAt", "body", "date-time", m.UpdatedAt.String(), formats); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// MarshalBinary interface implementation
|
|
func (m *Silence) MarshalBinary() ([]byte, error) {
|
|
if m == nil {
|
|
return nil, nil
|
|
}
|
|
return swag.WriteJSON(m)
|
|
}
|
|
|
|
// UnmarshalBinary interface implementation
|
|
func (m *Silence) UnmarshalBinary(b []byte) error {
|
|
var res Silence
|
|
if err := swag.ReadJSON(b, &res); err != nil {
|
|
return err
|
|
}
|
|
*m = res
|
|
return nil
|
|
}
|
|
|
|
// SilenceStatus silence status
|
|
// swagger:model SilenceStatus
|
|
type SilenceStatus struct {
|
|
|
|
// state
|
|
// Enum: [expired active pending]
|
|
State string `json:"state,omitempty"`
|
|
}
|
|
|
|
// Validate validates this silence status
|
|
func (m *SilenceStatus) Validate(formats strfmt.Registry) error {
|
|
var res []error
|
|
|
|
if err := m.validateState(formats); err != nil {
|
|
res = append(res, err)
|
|
}
|
|
|
|
if len(res) > 0 {
|
|
return errors.CompositeValidationError(res...)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
var silenceStatusTypeStatePropEnum []interface{}
|
|
|
|
func init() {
|
|
var res []string
|
|
if err := json.Unmarshal([]byte(`["expired","active","pending"]`), &res); err != nil {
|
|
panic(err)
|
|
}
|
|
for _, v := range res {
|
|
silenceStatusTypeStatePropEnum = append(silenceStatusTypeStatePropEnum, v)
|
|
}
|
|
}
|
|
|
|
const (
|
|
|
|
// SilenceStatusStateExpired captures enum value "expired"
|
|
SilenceStatusStateExpired string = "expired"
|
|
|
|
// SilenceStatusStateActive captures enum value "active"
|
|
SilenceStatusStateActive string = "active"
|
|
|
|
// SilenceStatusStatePending captures enum value "pending"
|
|
SilenceStatusStatePending string = "pending"
|
|
)
|
|
|
|
// prop value enum
|
|
func (m *SilenceStatus) validateStateEnum(path, location string, value string) error {
|
|
if err := validate.Enum(path, location, value, silenceStatusTypeStatePropEnum); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (m *SilenceStatus) validateState(formats strfmt.Registry) error {
|
|
|
|
if swag.IsZero(m.State) { // not required
|
|
return nil
|
|
}
|
|
|
|
// value enum
|
|
if err := m.validateStateEnum("status"+"."+"state", "body", m.State); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// MarshalBinary interface implementation
|
|
func (m *SilenceStatus) MarshalBinary() ([]byte, error) {
|
|
if m == nil {
|
|
return nil, nil
|
|
}
|
|
return swag.WriteJSON(m)
|
|
}
|
|
|
|
// UnmarshalBinary interface implementation
|
|
func (m *SilenceStatus) UnmarshalBinary(b []byte) error {
|
|
var res SilenceStatus
|
|
if err := swag.ReadJSON(b, &res); err != nil {
|
|
return err
|
|
}
|
|
*m = res
|
|
return nil
|
|
}
|