Added support for config file command line

This commit is contained in:
Mike Liebsch 2017-04-27 20:36:41 +02:00
parent b656d6be88
commit 4856b75ea3
2 changed files with 6 additions and 4 deletions

BIN
vsphere-influxdb Executable file

Binary file not shown.

View File

@ -21,8 +21,6 @@ import (
"encoding/json"
"flag"
"fmt"
"github.com/davecgh/go-spew/spew"
"golang.org/x/net/context"
"log"
"math"
"net/url"
@ -32,6 +30,9 @@ import (
"strings"
"time"
"github.com/davecgh/go-spew/spew"
"golang.org/x/net/context"
influxclient "github.com/influxdata/influxdb/client/v2"
"github.com/vmware/govmomi"
"github.com/vmware/govmomi/property"
@ -613,6 +614,7 @@ func queryVCenter(vcenter VCenter, config Configuration, InfluxDBClient influxcl
func main() {
flag.BoolVar(&debug, "debug", false, "Debug mode")
var cfgFile = flag.String("config", "/etc/"+path.Base(os.Args[0])+".json", "Config file to use. Default is /etc/"+path.Base(os.Args[0])+".json")
flag.Parse()
stdlog = log.New(os.Stdout, "", log.Ldate|log.Ltime)
@ -620,9 +622,9 @@ func main() {
stdlog.Println("Starting :", path.Base(os.Args[0]))
// read the configuration
file, err := os.Open("/etc/" + path.Base(os.Args[0]) + ".json")
file, err := os.Open(*cfgFile)
if err != nil {
errlog.Println("Could not open configuration file")
errlog.Println("Could not open configuration file" + *cfgFile)
errlog.Println(err)
}
jsondec := json.NewDecoder(file)