...

Source file src/github.com/prometheus/alertmanager/api/v2/restapi/configure_alertmanager.go

Documentation: github.com/prometheus/alertmanager/api/v2/restapi

     1  // This file is safe to edit. Once it exists it will not be overwritten
     2  
     3  // Copyright Prometheus Team
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  // http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  //
    16  
    17  package restapi
    18  
    19  import (
    20  	"crypto/tls"
    21  	"net/http"
    22  
    23  	"github.com/go-openapi/errors"
    24  	"github.com/go-openapi/runtime"
    25  	"github.com/go-openapi/runtime/middleware"
    26  
    27  	"github.com/prometheus/alertmanager/api/v2/restapi/operations"
    28  	"github.com/prometheus/alertmanager/api/v2/restapi/operations/alert"
    29  	"github.com/prometheus/alertmanager/api/v2/restapi/operations/alertgroup"
    30  	"github.com/prometheus/alertmanager/api/v2/restapi/operations/general"
    31  	"github.com/prometheus/alertmanager/api/v2/restapi/operations/receiver"
    32  	"github.com/prometheus/alertmanager/api/v2/restapi/operations/silence"
    33  )
    34  
    35  //go:generate swagger generate server --target ../../v2 --name Alertmanager --spec ../openapi.yaml --principal interface{} --exclude-main
    36  
    37  func configureFlags(api *operations.AlertmanagerAPI) {
    38  	// api.CommandLineOptionsGroups = []swag.CommandLineOptionsGroup{ ... }
    39  }
    40  
    41  func configureAPI(api *operations.AlertmanagerAPI) http.Handler {
    42  	// configure the api here
    43  	api.ServeError = errors.ServeError
    44  
    45  	// Set your custom logger if needed. Default one is log.Printf
    46  	// Expected interface func(string, ...interface{})
    47  	//
    48  	// Example:
    49  	// api.Logger = log.Printf
    50  
    51  	api.UseSwaggerUI()
    52  	// To continue using redoc as your UI, uncomment the following line
    53  	// api.UseRedoc()
    54  
    55  	api.JSONConsumer = runtime.JSONConsumer()
    56  
    57  	api.JSONProducer = runtime.JSONProducer()
    58  
    59  	if api.SilenceDeleteSilenceHandler == nil {
    60  		api.SilenceDeleteSilenceHandler = silence.DeleteSilenceHandlerFunc(func(params silence.DeleteSilenceParams) middleware.Responder {
    61  			return middleware.NotImplemented("operation silence.DeleteSilence has not yet been implemented")
    62  		})
    63  	}
    64  	if api.AlertgroupGetAlertGroupsHandler == nil {
    65  		api.AlertgroupGetAlertGroupsHandler = alertgroup.GetAlertGroupsHandlerFunc(func(params alertgroup.GetAlertGroupsParams) middleware.Responder {
    66  			return middleware.NotImplemented("operation alertgroup.GetAlertGroups has not yet been implemented")
    67  		})
    68  	}
    69  	if api.AlertGetAlertsHandler == nil {
    70  		api.AlertGetAlertsHandler = alert.GetAlertsHandlerFunc(func(params alert.GetAlertsParams) middleware.Responder {
    71  			return middleware.NotImplemented("operation alert.GetAlerts has not yet been implemented")
    72  		})
    73  	}
    74  	if api.ReceiverGetReceiversHandler == nil {
    75  		api.ReceiverGetReceiversHandler = receiver.GetReceiversHandlerFunc(func(params receiver.GetReceiversParams) middleware.Responder {
    76  			return middleware.NotImplemented("operation receiver.GetReceivers has not yet been implemented")
    77  		})
    78  	}
    79  	if api.SilenceGetSilenceHandler == nil {
    80  		api.SilenceGetSilenceHandler = silence.GetSilenceHandlerFunc(func(params silence.GetSilenceParams) middleware.Responder {
    81  			return middleware.NotImplemented("operation silence.GetSilence has not yet been implemented")
    82  		})
    83  	}
    84  	if api.SilenceGetSilencesHandler == nil {
    85  		api.SilenceGetSilencesHandler = silence.GetSilencesHandlerFunc(func(params silence.GetSilencesParams) middleware.Responder {
    86  			return middleware.NotImplemented("operation silence.GetSilences has not yet been implemented")
    87  		})
    88  	}
    89  	if api.GeneralGetStatusHandler == nil {
    90  		api.GeneralGetStatusHandler = general.GetStatusHandlerFunc(func(params general.GetStatusParams) middleware.Responder {
    91  			return middleware.NotImplemented("operation general.GetStatus has not yet been implemented")
    92  		})
    93  	}
    94  	if api.AlertPostAlertsHandler == nil {
    95  		api.AlertPostAlertsHandler = alert.PostAlertsHandlerFunc(func(params alert.PostAlertsParams) middleware.Responder {
    96  			return middleware.NotImplemented("operation alert.PostAlerts has not yet been implemented")
    97  		})
    98  	}
    99  	if api.SilencePostSilencesHandler == nil {
   100  		api.SilencePostSilencesHandler = silence.PostSilencesHandlerFunc(func(params silence.PostSilencesParams) middleware.Responder {
   101  			return middleware.NotImplemented("operation silence.PostSilences has not yet been implemented")
   102  		})
   103  	}
   104  
   105  	api.PreServerShutdown = func() {}
   106  
   107  	api.ServerShutdown = func() {}
   108  
   109  	return setupGlobalMiddleware(api.Serve(setupMiddlewares))
   110  }
   111  
   112  // The TLS configuration before HTTPS server starts.
   113  func configureTLS(tlsConfig *tls.Config) {
   114  	// Make all necessary changes to the TLS configuration here.
   115  }
   116  
   117  // As soon as server is initialized but not run yet, this function will be called.
   118  // If you need to modify a config, store server instance to stop it individually later, this is the place.
   119  // This function can be called multiple times, depending on the number of serving schemes.
   120  // scheme value will be set accordingly: "http", "https" or "unix".
   121  func configureServer(s *http.Server, scheme, addr string) {
   122  }
   123  
   124  // The middleware configuration is for the handler executors. These do not apply to the swagger.json document.
   125  // The middleware executes after routing but before authentication, binding and validation.
   126  func setupMiddlewares(handler http.Handler) http.Handler {
   127  	return handler
   128  }
   129  
   130  // The middleware configuration happens before anything, this middleware also applies to serving the swagger.json document.
   131  // So this is a good place to plug in a panic handling middleware, logging and metrics.
   132  func setupGlobalMiddleware(handler http.Handler) http.Handler {
   133  	return handler
   134  }
   135  

View as plain text