func printInflux(measurement string, tagsMap map[string]string, fieldsMap map[string]string, timestamp int64) {
	var tags string
	var i int
	for k, v := range tagsMap {
		if i == 0 {
			tags = tags + fmt.Sprintf("%s=%s", k, v)
		} else {
			tags = tags + fmt.Sprintf(",%s=%s", k, v)
		}
		i++
	}
	var fields string
	var j int
	for k, v := range fieldsMap {
		if j == 0 {
			fields = fields + fmt.Sprintf("%s=%s", k, v)
		} else {
			fields = fields + fmt.Sprintf(",%s=%s", k, v)
		}
		j++
	}
	fmt.Printf("%s,%s %s %d\n", measurement, tags, fields, timestamp)
}
printInflux purpose is to output data in the influxdb line format
package main
import (
	"flag"
	"fmt"
	"os"
	"strconv"
	"strings"
	"time"
	"github.com/equelin/gounity"
	"github.com/sirupsen/logrus"
)
type pool struct {
	ID             string `json:"id"`
	Name           string `json:"name"`
	SizeFree       uint64 `json:"sizeFree"`
	SizeTotal      uint64 `json:"sizeTotal"`
	SizeUsed       uint64 `json:"sizeUsed"`
	SizeSubscribed uint64 `json:"sizeSubscribed"`
}
type storageresource struct {
	ID            string `json:"id"`
	Name          string `json:"name"`
	SizeAllocated uint64 `json:"sizeAllocated"`
	SizeTotal     uint64 `json:"sizeTotal"`
	SizeUsed      uint64 `json:"sizeUsed"`
	Type          int    `json:"type"`
}
var log = logrus.New()
var unityName string
var unityPools []pool
var unityStorageResource []storageresource
func parseResult(timestamp time.Time, path string, valuesMap map[string]interface{}) {
	tagsMap := make(map[string]string)
	tagNames := make(map[int]string)
	pathSplit := strings.Split(path, ".")
	var measurementName string
	if pathSplit[0] == "kpi" {
		measurementName = fmt.Sprintf("kpi_%s", pathSplit[1])
	} else {
		measurementName = pathSplit[2]
	}
	j := 0
	for i, v := range pathSplit {
		if v == "*" {
			tagName := pathSplit[i-1]
			tagNames[j] = tagName
			j++
		}
	}
	parseMap(
		timestamp,
		0,
		&path,
		&measurementName,
		tagNames,
		tagsMap,
		valuesMap,
	)
}
func parseMap(timestamp time.Time, index int, pathPtr *string, measurementNamePtr *string, tagNames map[int]string, tagsMap map[string]string, valuesMap map[string]interface{}) {
	for key, val := range valuesMap {
		pathSplit := strings.Split(*pathPtr, ".")
		switch concreteVal := val.(type) {
		case map[string]interface{}:
			ok := false
			for i, v := range pathSplit {
				if v == key {
					tagName := pathSplit[i-1]
					tagsMap[tagName] = key
					ok = true
				}
			}
			if ok != true {
				tagsMap[tagNames[index]] = key
				index++
			}
			parseMap(
				timestamp,
				index,
				pathPtr,
				measurementNamePtr,
				tagNames,
				tagsMap,
				val.(map[string]interface{}),
			)
		default:
			if len(tagNames) != 0 {
				tagsMap[tagNames[index]] = key
			} else {
				for i, v := range pathSplit {
					if v == key {
						tagName := pathSplit[i-1]
						tagsMap[tagName] = key
					}
				}
			}
			tagsMap["unity"] = unityName
			fieldsMap := make(map[string]string)
			_, ok := concreteVal.(float64)
			if ok {
				fieldsMap[pathSplit[len(pathSplit)-1]] = fmt.Sprintf("%f", concreteVal)
			} else {
				fieldsMap[pathSplit[len(pathSplit)-1]] = fmt.Sprintf("%s", concreteVal)
			}
			printInflux(*measurementNamePtr, tagsMap, fieldsMap, timestamp.UnixNano())
		}
	}
}
func parsePool(id string, name string, sizeFree uint64, sizeSubscribed uint64, sizeTotal uint64, sizeUsed uint64) {
	tagsMap := make(map[string]string)
	fieldsMap := make(map[string]string)
	tagsMap["unity"] = unityName
	tagsMap["pool"] = id
	tagsMap["poolname"] = name
	fieldsMap["sizefree"] = strconv.FormatUint(sizeFree, 10)
	fieldsMap["sizesubscribed"] = strconv.FormatUint(sizeSubscribed, 10)
	fieldsMap["sizetotal"] = strconv.FormatUint(sizeTotal, 10)
	fieldsMap["sizeused"] = strconv.FormatUint(sizeUsed, 10)
	printInflux("pool", tagsMap, fieldsMap, time.Now().UnixNano())
}
func parseStorageResource(id string, name string, sizeAllocated uint64, sizeTotal uint64, sizeUsed uint64) {
	tagsMap := make(map[string]string)
	fieldsMap := make(map[string]string)
	tagsMap["unity"] = unityName
	tagsMap["storageresource"] = id
	tagsMap["storageresourcename"] = name
	fieldsMap["sizeallocated"] = strconv.FormatUint(sizeAllocated, 10)
	fieldsMap["sizetotal"] = strconv.FormatUint(sizeTotal, 10)
	fieldsMap["sizeused"] = strconv.FormatUint(sizeUsed, 10)
	printInflux("storageresource", tagsMap, fieldsMap, time.Now().UnixNano())
}
func parseKpiValue(id string, name string, path string, value float64) {
	pathSplit := strings.Split(path, ".")
	tagsMap := make(map[string]string)
	fieldsMap := make(map[string]string)
	tagsMap["unity"] = unityName
	for i, v := range pathSplit {
		if v == id {
			tagName := strings.ToLower(pathSplit[i-1])
			tagsMap[tagName] = v
			tagsMap[tagName+"name"] = strings.Replace(name, " ", "_", -1)
		}
		if v == "sp" || v == "rw" || v == "lun" {
			tagsMap["lun"] = pathSplit[i+1]
		}
	}
	fieldsMap[pathSplit[len(pathSplit)-1]] = fmt.Sprintf("%f", value)
	printInflux("kpi_"+pathSplit[1], tagsMap, fieldsMap, time.Now().UnixNano())
}