func ParseGlobal(rootDir string) (*ConfigFile, error) { path := rootDir + "/inspeqtor.conf" exists, err := util.FileExists(path) if err != nil { return nil, err } if exists { util.Debug("Parsing " + path) data, err := ioutil.ReadFile(path) if err != nil { return nil, err } s := lexer.NewLexer([]byte(data)) p := parser.NewParser() obj, err := p.Parse(s) if err != nil { return nil, err } ast := obj.(ast.Config) config := ConfigFile{Defaults, map[string]*AlertRoute{}} config.Variables = ast.Variables if val, has := ast.Variables["log_level"]; has { util.SetLogLevel(val) } parseValue(ast, &config.CycleTime, "cycle_time", 15) parseValue(ast, &config.DeployLength, "deploy_length", 300) parseValue(ast, &config.ExposePort, "expose_port", 4677) for _, v := range ast.Routes { ar, err := ValidateChannel(v.Name, v.Channel, v.Config) if err != nil { return nil, err } if _, ok := config.AlertRoutes[v.Name]; ok { return nil, fmt.Errorf("Duplicate alert config for '%s'", v.Name) } config.AlertRoutes[v.Name] = ar } return &config, nil } util.Info("No configuration file found at " + rootDir + "/inspector.conf") return &ConfigFile{Defaults, nil}, nil }
func ParseArguments() CmdOptions { defaults := CmdOptions{false, false, "/etc/inspeqtor", "info", "/var/run/inspeqtor.sock"} log.Println(inspeqtor.Name, inspeqtor.VERSION) log.Println(fmt.Sprintf("Copyright © %d Contributed Systems LLC", time.Now().Year())) if StartupInfo != nil { StartupInfo() } flag.Usage = help flag.BoolVar(&defaults.TestConfig, "tc", false, "Test configuration and exit") flag.BoolVar(&defaults.TestAlertRoutes, "ta", false, "Test alert routes and exit") flag.StringVar(&defaults.LogLevel, "l", "info", "Logging level (warn, info, debug, verbose)") // undocumented on purpose, for testing only, we don't want people changing these // if possible flag.StringVar(&defaults.SocketPath, "s", "/var/run/inspeqtor.sock", "") flag.StringVar(&defaults.ConfigDirectory, "c", "/etc/inspeqtor", "") helpPtr := flag.Bool("help", false, "You're looking at it") help2Ptr := flag.Bool("h", false, "You're looking at it") versionPtr := flag.Bool("v", false, "Show version") flag.Parse() if *helpPtr || *help2Ptr { help() os.Exit(0) } if *versionPtr { os.Exit(0) } util.SetLogLevel(defaults.LogLevel) return defaults }