-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ae78ab7
Showing
13 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
alertmanager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
clean: | ||
rm alertmanager | ||
|
||
build: | ||
go build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
configOptionA: yesy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// configCmd represents the config command | ||
// there are 2 subcommands | ||
// validate: used to validate a given config-gile | ||
// generate-template: used to generate a blank template that is filled with defaults | ||
var configCmd = &cobra.Command{ | ||
Use: "config", | ||
Short: "Use this command to validate an existing config-file or to generate a sample template", | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(configCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// generateTemplateCmd represents the generateTemplate command | ||
var generateTemplateCmd = &cobra.Command{ | ||
Use: "generate-template", | ||
Short: "generate a sample config template", | ||
|
||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("generateTemplate called") | ||
}, | ||
} | ||
|
||
func init() { | ||
configCmd.AddCommand(generateTemplateCmd) | ||
|
||
// generateTemplateCmd.Flags().String("output-file", "t", false, "Help message for toggle") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var version = "0.0.1" | ||
var DEFAULT_LOG_LEVEL = "INFO" | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "alertmanager", | ||
Version: version, | ||
Short: "An alertmanager for managing alerts", | ||
Long: `This alertmanager tool can be used to start the alertmanager server or to validate the config. | ||
Additionally you can also generate a bare config-template`, | ||
} | ||
|
||
func Execute() { | ||
err := rootCmd.Execute() | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
rootCmd.PersistentFlags().String("log-level", DEFAULT_LOG_LEVEL, "log-level for alertmanager; options INFO|DEBUG|ERROR") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var serverCmd = &cobra.Command{ | ||
Use: "server", | ||
Short: "Start the AlertManager Webhook Server", | ||
RunE: serverCommandRunE, | ||
} | ||
|
||
func serverCommandRunE(cmd *cobra.Command, args []string) error { | ||
fmt.Println("Server is being called") | ||
ll, _ := cmd.Flags().GetString("log-level") | ||
fmt.Println(ll) | ||
return nil | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(serverCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// serverCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// serverCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// validateCmd represents the validate command | ||
var validateCmd = &cobra.Command{ | ||
Use: "validate", | ||
Short: "validate a config-file for errors", | ||
Run: validateCmdRun, | ||
} | ||
|
||
func init() { | ||
configCmd.AddCommand(validateCmd) | ||
|
||
validateCmd.Flags().String("config-file", "./alert-manager-config.yml", "Path to config for validation") | ||
} | ||
|
||
func validateCmdRun(cmd *cobra.Command, args []string) { | ||
// config.Validate() | ||
fmt.Println("validate called") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package config | ||
|
||
import "fmt" | ||
|
||
type AlertManagerConfig struct { | ||
AlertPipelines []AlertPipelineConfig | ||
} | ||
|
||
type AlertPipelineConfig struct{} | ||
|
||
func (c AlertManagerConfig) String() string { | ||
return | ||
} | ||
|
||
func (c AlertManagerConfig) Validate() { | ||
fmt.Println("Validate Config") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module alertmanager | ||
|
||
go 1.21.0 | ||
|
||
require ( | ||
github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
github.com/spf13/cobra v1.8.1 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= | ||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= | ||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= | ||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= | ||
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= | ||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= | ||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import "alertmanager/cmd" | ||
|
||
func main() { | ||
cmd.Execute() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
- Use https://github.com/alecthomas/kong for config management (or use [flag](https://pkg.go.dev/flag) from the STL) | ||
- CLI params | ||
- --server-port | ||
- --pprof-port | ||
- --alerting-config | ||
- --auth-config | ||
- Use [net/http] | ||
- needs 2 min endpoints | ||
- POST / (for getting webhook) | ||
- POST /~/reload to reload config | ||
- GET /~/config to get current loaded config | ||
- GET /health | ||
- Use logrus for logging | ||
- Tests | ||
|
||
# Tol | ||
|
||
## app cli style | ||
|
||
alertmanager server --port abcd --pprof-port efgh --config /path-to-file --loglevel | ||
|
||
alertmanager config generate-template --out-file | ||
alertmanager config validate --config-file | ||
|
||
## Flow | ||
|
||
Alert -> Enrichment(s) -> Action(s) |