root

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2020 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ForwardCmd = &cobra.Command{
	Use:   "forward",
	Short: "Forward a messages to receivers",
}

ForwardCmd represents the serve command

View Source
var ForwardHangoutsChatCmd = &cobra.Command{
	Use:   "hangouts-chat [text]",
	Short: "",
	Args:  cobra.MinimumNArgs(1),
	Long:  ``,
	RunE:  ForwardHangoutsChat,
}
View Source
var RootCmd = &cobra.Command{
	Use:           "alertmanager-webhook-forwarder",
	Short:         "Use subcomamnds.",
	SilenceUsage:  true,
	SilenceErrors: true,
	Long: `
Example:

	$ ./alertmanager-webhook-forwarder forward hangouts-chat "test message" --template gotemplate-yaml --verbose --dry-run

`,
}
View Source
var ServeCmd = &cobra.Command{
	Use:   "serve",
	Short: "Run as HTTP server",
	Long: `
Run as golang HTTP server with /healthz and /v1/webhook/hangouts-chat endpoints.

Example:

	# first terminal
	alertmanager-webhook-forwarder serve

	# second terminal
	curl http://localhost:8080/healthz
`,
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		listenHost := viper.GetString("server.host")
		listenPort := viper.GetInt("server.port")
		gracefulShutdownTimeout := viper.GetInt("server.gracefulShutdownTimeout")
		accessLogEnabled := viper.GetBool("server.accessLog.enabled")
		listenAddress := fmt.Sprintf("%s:%d", listenHost, listenPort)

		done := make(chan bool, 1)
		quit := make(chan os.Signal, 1)
		signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)

		router := http.NewServeMux()
		router.HandleFunc("/healthz", handleHealthz)
		router.HandleFunc("/v1/webhook/hangouts-chat", providerWebhookHandlerFactory(utils.ProviderHangoutsChat))

		var handler http.Handler

		if accessLogEnabled {
			handler = handlers.LoggingHandler(os.Stdout, router)
		} else {
			handler = router
		}

		http2server := &http2.Server{}
		handler = h2c.NewHandler(handler, http2server)

		server := &http.Server{
			Addr:         listenAddress,
			Handler:      handler,
			ReadTimeout:  5 * time.Second,
			WriteTimeout: 10 * time.Second,
			IdleTimeout:  15 * time.Second,
		}

		go gracefulShutdown(server, quit, done, gracefulShutdownTimeout)

		klog.Infof("Server is listening on http://%s:%d", listenHost, listenPort)
		if err = server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
			klog.Fatalf("Could not listen on %s: %v\n", listenAddress, err)
		}

		<-done
		klog.Info("Server has been stopped")

		return nil
	},
}

ServeCmd represents the serve command

View Source
var SleepCmd = &cobra.Command{
	Use:   "sleep",
	Short: "Sleep some seconds",
	Args:  cobra.ExactArgs(1),
	Long: `
alertmanager-webhook-forwarder sleep 5

`,
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		sleepPeriodSeconds, err := strconv.ParseInt(args[0], 10, 64)
		if err != nil {
			return err
		}
		if sleepPeriodSeconds < 0 {
			return fmt.Errorf("provided argument must be a positive number, %v given", sleepPeriodSeconds)
		}

		klog.V(7).Infof("sleeping for %d second(s)", sleepPeriodSeconds)
		conditional_runner.NotDryRun().Run(func() {
			time.Sleep(time.Duration(sleepPeriodSeconds) * time.Second)
		})

		return nil
	},
}

Functions

func Execute

func Execute()

func ForwardHangoutsChat

func ForwardHangoutsChat(cmd *cobra.Command, args []string) (err error)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL