Skip to content

Commit

Permalink
feat: Add support for custom config file path
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-karan committed Jan 11, 2019
1 parent c7d39fc commit 0b744b8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ You are now ready to send alerts to Google Chat!

- Alertmanager has the ability of group similar alerts together and fire only one event, clubbing all the alerts data into one event. `calert` leverages this and sends all alerts in one message by looping over the alerts and passing data in the template. You can configure the rules for grouping the alerts in `alertmanager.yml` config. You can read more about it [here](https://github.com/prometheus/docs/blob/master/content/docs/alerting/alertmanager.md#grouping)

- You can use `--config.file` parameter to supply a custom config file path while running `calert`.

## API

- POST `/create?room_name=<>` (Used to receive new alerts and push to Google Chat)
Expand Down
15 changes: 12 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,30 @@ func initConfig() {
os.Exit(0)
}

viper.SetConfigName("config")
// Config Path flag.
flagSet.String("config.file", "", "Path to config file")

viper.SetDefault("server.address", ":5000")
viper.SetDefault("server.socket", "/tmp/calert.sock")
viper.SetDefault("server.name", "calert")
viper.SetDefault("server.read_timeout", 1000)
viper.SetDefault("server.write_timeout", 5000)
viper.SetDefault("server.keepalive_timeout", 30000)
viper.SetDefault("server.max_body_size", 5000)

// Process flags.
flagSet.Parse(os.Args[1:])
viper.BindPFlags(flagSet)

// Config file.
viper.AddConfigPath(".")
// check if config.file flag is passed and read from the file if it is set
configPath := viper.GetString("config.file")
if configPath != "" {
viper.SetConfigFile(configPath)
} else {
// fallback to default config.
viper.SetConfigName("config")
viper.AddConfigPath(".")
}
err := viper.ReadInConfig()
if err != nil {
errLog.Fatalf("Error reading config: %s", err)
Expand Down

0 comments on commit 0b744b8

Please sign in to comment.