Skip to content

Commit

Permalink
added a single debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Todorov committed Aug 10, 2016
1 parent 301a758 commit 143b0d1
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions vsphere-influxdb.go
Expand Up @@ -19,7 +19,9 @@ package main

import (
"encoding/json"
"flag"
"fmt"
// "github.com/davecgh/go-spew/spew"
"golang.org/x/net/context"
"log"
"math"
Expand Down Expand Up @@ -78,6 +80,7 @@ type MetricDef struct {

// Metrics description in config
var vm_refs []types.ManagedObjectReference
var debug bool

type Metric struct {
ObjectType []string
Expand Down Expand Up @@ -284,14 +287,27 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.

// Retrieve properties for clusters, if any
if len(cluster_refs) > 0 {
if debug == true {
stdlog.Println("going inside clusters")
}
var clmo []mo.ClusterComputeResource
err = pc.Retrieve(ctx, cluster_refs, []string{"name", "configuration"}, &clmo)
if err != nil {
fmt.Println(err)
return
}
for _, cl := range clmo {
if debug == true {
stdlog.Println("---cluster name - you should see every cluster here---")
stdlog.Println(cl.Name)
}

for _, vm := range cl.Configuration.DasVmConfig {
if debug == true {
stdlog.Println("--VM ID - you should see every VM ID here--")
stdlog.Println(vm.Key.Value)
}

vmToCluster[vm.Key] = cl.Name
}
}
Expand Down Expand Up @@ -591,6 +607,10 @@ func queryVCenter(vcenter VCenter, config Configuration, InfluxDBClient influxcl
}

func main() {

flag.BoolVar(&debug, "debug", false, "Debug mode")
flag.Parse()

stdlog = log.New(os.Stdout, "", log.Ldate|log.Ltime)
errlog = log.New(os.Stderr, "", log.Ldate|log.Ltime)

Expand Down

0 comments on commit 143b0d1

Please sign in to comment.