1
0
mirror of https://github.com/Oxalide/vsphere-influxdb-go.git synced 2023-10-10 13:36:51 +02:00

InfluxDB and vSphere can be configured using environemt variables

This commit is contained in:
Mike Liebsch 2017-09-07 11:13:54 +02:00
parent ff4a561165
commit 7c4478c435
2 changed files with 74 additions and 45 deletions

View File

@ -36,6 +36,10 @@ $GOBIN/vsphere-influxdb-go
# Configure
You'll need a JSON file with all your vCenters/ESXi to connect to, the InfluxDB connection details(url, username/password, database to use), and the metrics to collect.
Additionally you can provide a vCenter/ESXi server and InfluxDB connection details via environment variables, wich is extremly helpful when running inside a container.
For InfluxDB set INFLUX\_HOSTNAME, INFLUX\_USERNAME, INFLUX\_PASSWORD and INFLUX\_DATABASE.
For vSphere set VSPHERE\_HOSTNAME, VSPHERE\_USERNAME and VSPHERE\_PASSWORD and keep in mind, that currently only one vCenter/ESXi can be added via environment variable.
If you set a domain, it will be automaticaly removed from the names of the found objects.

View File

@ -763,6 +763,31 @@ func main() {
errlog.Fatalln(err)
}
// Support environemt variables / overrides for Influx Connection
if ihostname := os.Getenv("INFLUX_HOSTNAME"); ihostname != "" {
config.InfluxDB.Hostname = os.Getenv("INFLUX_HOSTNAME")
config.InfluxDB.Username = os.Getenv("INFLUX_USERNAME")
config.InfluxDB.Password = os.Getenv("INFLUX_PASSWORD")
config.InfluxDB.Database = os.Getenv("INFLUX_DATABASE")
}
// Support environment variables for VSphere
// Currently ony one server is supported and added to the list of vSphere servers
if vhostname := os.Getenv("VSPHERE_HOSTNAME"); vhostname != "" {
vc := VCenter{
Hostname: os.Getenv("VSPHERE_HOSTNAME"),
Username: os.Getenv("VSPHERE_USERNAME"),
Password: os.Getenv("VSPHERE_PASSWORD"),
}
config.VCenters = append(config.VCenters, &vc)
}
// Print configuration in debug mode
if debug == true {
stdlog.Println("---Configuration - you should see the config here---")
spew.Dump(config)
}
for _, vcenter := range config.VCenters {
vcenter.Init(config)
}