Skip to content

Commit

Permalink
Initial App binary structure
Browse files Browse the repository at this point in the history
  • Loading branch information
83bytes committed Jun 21, 2024
0 parents commit ae78ab7
Show file tree
Hide file tree
Showing 13 changed files with 206 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alertmanager
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
clean:
rm alertmanager

build:
go build
1 change: 1 addition & 0 deletions alert-manager-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
configOptionA: yesy
18 changes: 18 additions & 0 deletions cmd/config.go
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)
}
23 changes: 23 additions & 0 deletions cmd/generateTemplate.go
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")
}
29 changes: 29 additions & 0 deletions cmd/root.go
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")
}
34 changes: 34 additions & 0 deletions cmd/server.go
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")
}
25 changes: 25 additions & 0 deletions cmd/validate.go
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")
}
17 changes: 17 additions & 0 deletions config/config.go
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")
}
9 changes: 9 additions & 0 deletions go.mod
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
)
10 changes: 10 additions & 0 deletions go.sum
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=
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "alertmanager/cmd"

func main() {
cmd.Execute()
}
27 changes: 27 additions & 0 deletions scratchpad.md
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)

0 comments on commit ae78ab7

Please sign in to comment.