Linting fixes

This commit is contained in:
ADO 2017-05-24 13:59:37 +02:00
parent eef2388bde
commit d8f101eded
1 changed files with 13 additions and 4 deletions

View File

@ -105,6 +105,7 @@ func (vcenter *VCenter) Connect() (*govmomi.Client, error) {
// Prepare vCenter Connections // Prepare vCenter Connections
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
stdlog.Println("connecting to vcenter: " + vcenter.Hostname) stdlog.Println("connecting to vcenter: " + vcenter.Hostname)
u, err := url.Parse("https://" + vcenter.Username + ":" + vcenter.Password + "@" + vcenter.Hostname + "/sdk") u, err := url.Parse("https://" + vcenter.Username + ":" + vcenter.Password + "@" + vcenter.Hostname + "/sdk")
if err != nil { if err != nil {
@ -112,12 +113,14 @@ func (vcenter *VCenter) Connect() (*govmomi.Client, error) {
errlog.Println("Error: ", err) errlog.Println("Error: ", err)
return nil, err return nil, err
} }
client, err := govmomi.NewClient(ctx, u, true) client, err := govmomi.NewClient(ctx, u, true)
if err != nil { if err != nil {
errlog.Println("Could not connect to vcenter: ", vcenter.Hostname) errlog.Println("Could not connect to vcenter: ", vcenter.Hostname)
errlog.Println("Error: ", err) errlog.Println("Error: ", err)
return nil, err return nil, err
} }
return client, nil return client, nil
} }
@ -125,6 +128,7 @@ func (vcenter *VCenter) Connect() (*govmomi.Client, error) {
func (vcenter *VCenter) Init(config Configuration) { func (vcenter *VCenter) Init(config Configuration) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
client, err := vcenter.Connect() client, err := vcenter.Connect()
if err != nil { if err != nil {
errlog.Println("Could not connect to vcenter: ", vcenter.Hostname) errlog.Println("Could not connect to vcenter: ", vcenter.Hostname)
@ -132,6 +136,7 @@ func (vcenter *VCenter) Init(config Configuration) {
return return
} }
defer client.Logout(ctx) defer client.Logout(ctx)
var perfmanager mo.PerformanceManager var perfmanager mo.PerformanceManager
err = client.RetrieveOne(ctx, *client.ServiceContent.PerfManager, nil, &perfmanager) err = client.RetrieveOne(ctx, *client.ServiceContent.PerfManager, nil, &perfmanager)
if err != nil { if err != nil {
@ -139,6 +144,7 @@ func (vcenter *VCenter) Init(config Configuration) {
errlog.Println("Error: ", err) errlog.Println("Error: ", err)
return return
} }
for _, perf := range perfmanager.PerfCounter { for _, perf := range perfmanager.PerfCounter {
groupinfo := perf.GroupInfo.GetElementDescription() groupinfo := perf.GroupInfo.GetElementDescription()
nameinfo := perf.NameInfo.GetElementDescription() nameinfo := perf.NameInfo.GetElementDescription()
@ -262,7 +268,7 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
respoolRefs = append(respool_refs, mor) respoolRefs = append(respool_refs, mor)
} }
} }
// Copy the mors without the clusters // Copy the mors without the clusters
mors = newMors mors = newMors
pc := property.DefaultCollector(client.Client) pc := property.DefaultCollector(client.Client)
@ -345,6 +351,7 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
spew.Dump(cl.Configuration) spew.Dump(cl.Configuration)
spew.Dump(cl.Configuration.DasVmConfig) spew.Dump(cl.Configuration.DasVmConfig)
} }
for _, vm := range cl.Configuration.DasVmConfig { for _, vm := range cl.Configuration.DasVmConfig {
if debug == true { if debug == true {
stdlog.Println("--VM ID - you should see every VM ID here--") stdlog.Println("--VM ID - you should see every VM ID here--")
@ -565,7 +572,6 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
specialTags[measurementName][tags["name"]][instanceName][k] = v specialTags[measurementName][tags["name"]][instanceName][k] = v
} }
specialTags[measurementName][tags["name"]][instanceName]["instance"] = instanceName specialTags[measurementName][tags["name"]][instanceName]["instance"] = instanceName
} }
} }
@ -614,6 +620,7 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
} }
} }
//InfluxDB send //InfluxDB send
err = InfluxDBClient.Write(bp) err = InfluxDBClient.Write(bp)
if err != nil { if err != nil {
@ -682,7 +689,6 @@ func average(n ...int64) int64 {
func queryVCenter(vcenter VCenter, config Configuration, InfluxDBClient influxclient.Client) { func queryVCenter(vcenter VCenter, config Configuration, InfluxDBClient influxclient.Client) {
stdlog.Println("Querying vcenter") stdlog.Println("Querying vcenter")
vcenter.Query(config, InfluxDBClient) vcenter.Query(config, InfluxDBClient)
} }
func main() { func main() {
@ -695,23 +701,26 @@ func main() {
errlog = log.New(os.Stderr, "", log.Ldate|log.Ltime) errlog = log.New(os.Stderr, "", log.Ldate|log.Ltime)
stdlog.Println("Starting :", path.Base(os.Args[0])) stdlog.Println("Starting :", path.Base(os.Args[0]))
// read the configuration // read the configuration
file, err := os.Open(*cfgFile) file, err := os.Open(*cfgFile)
if err != nil { if err != nil {
errlog.Println("Could not open configuration file " + *cfgFile) errlog.Println("Could not open configuration file " + *cfgFile)
errlog.Println(err) errlog.Println(err)
} }
jsondec := json.NewDecoder(file) jsondec := json.NewDecoder(file)
config := Configuration{} config := Configuration{}
err = jsondec.Decode(&config) err = jsondec.Decode(&config)
if err != nil { if err != nil {
errlog.Println("Could not decode configuration file " + *cfgFile) errlog.Println("Could not decode configuration file " + *cfgFile)
errlog.Println(err) errlog.Println(err)
} }
for _, vcenter := range config.VCenters { for _, vcenter := range config.VCenters {
vcenter.Init(config) vcenter.Init(config)
} }
InfluxDBClient, err := influxclient.NewHTTPClient(influxclient.HTTPConfig{ InfluxDBClient, err := influxclient.NewHTTPClient(influxclient.HTTPConfig{
Addr: config.InfluxDB.Hostname, Addr: config.InfluxDB.Hostname,
Username: config.InfluxDB.Username, Username: config.InfluxDB.Username,