Skip to content

Commit

Permalink
Merge branch 'config_file' of git://github.com/vincentvu/consul-alert…
Browse files Browse the repository at this point in the history
…s into vincentvu-config_file
  • Loading branch information
fusiondog committed Jul 27, 2016
2 parents 6b49b29 + 87b233a commit 781939f
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion consul-alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (
"net/http"
"os/signal"

"encoding/json"
"io/ioutil"

"github.com/AcalephStorage/consul-alerts/consul"
"github.com/AcalephStorage/consul-alerts/notifier"

Expand All @@ -21,7 +24,7 @@ const version = "Consul Alerts 0.3.3"
const usage = `Consul Alerts.
Usage:
consul-alerts start [--alert-addr=<addr>] [--consul-addr=<consuladdr>] [--consul-dc=<dc>] [--consul-acl-token=<token>] [--watch-checks] [--watch-events] [--log-level=<level>]
consul-alerts start [--alert-addr=<addr>] [--consul-addr=<consuladdr>] [--consul-dc=<dc>] [--consul-acl-token=<token>] [--watch-checks] [--watch-events] [--log-level=<level>] [--config-file=<file>]
consul-alerts watch (checks|event) [--alert-addr=<addr>] [--log-level=<level>]
consul-alerts --help
consul-alerts --version
Expand All @@ -36,6 +39,7 @@ Options:
--log-level=<level> Set the logging level - valid values are "debug", "info", "warn", and "err" [default: warn].
--help Show this screen.
--version Show version.
--config-file=<file> Path to the configuration file in JSON format
`

Expand All @@ -59,6 +63,22 @@ func main() {

func daemonMode(arguments map[string]interface{}) {
loglevelString, _ := arguments["--log-level"].(string)
configFile := arguments["--config-file"].(string)

var confData map[string]interface{}
file, err := ioutil.ReadFile(configFile)
if err != nil {
log.Error(err)
}
err = json.Unmarshal(file, &confData)
if err != nil {
log.Error(err)
}
log.Debug("Config data: ", confData)

if confData["consul-acl-token"] != nil {
loglevelString = confData["log-level"].(string)
}

if loglevelString != "" {
loglevel, err := log.ParseLevel(loglevelString)
Expand Down Expand Up @@ -86,6 +106,22 @@ func daemonMode(arguments map[string]interface{}) {
watchChecks := arguments["--watch-checks"].(bool)
watchEvents := arguments["--watch-events"].(bool)

if confData["consul-acl-token"] != nil {
consulAclToken = confData["consul-acl-token"].(string)
}
if confData["consul-addr"] != nil {
consulAddr = confData["consul-addr"].(string)
}
if confData["consul-dc"] != nil {
consulDc = confData["consul-dc"].(string)
}
if confData["watch-checks"] != nil {
watchChecks = confData["watch-checks"].(bool)
}
if confData["watch-events"] != nil {
watchEvents = confData["watch-events"].(bool)
}

consulClient, err = consul.NewClient(consulAddr, consulDc, consulAclToken)
if err != nil {
log.Println("Cluster has no leader or is unreacheable.", err)
Expand Down

0 comments on commit 781939f

Please sign in to comment.