//VMSummary  stats for a VM
VMSummary  stats for a VM
// VMSummary stats for a VM
func (c *Client) VMSummary(name, moid string, lim *LimitsStruct, age time.Duration, txt bool, sensors []string) error {
	vmSummaryDefault = append(vmSummaryDefault, sensors...)
	start := time.Now()
	ctx := context.Background()
	ctx, _ = context.WithTimeout(ctx, 30*time.Second)
	if c.m == nil {
		return fmt.Errorf("no manager")
	}
	v, err := c.m.CreateContainerView(ctx, c.c.ServiceContent.RootFolder, []string{"VirtualMachine"}, true)
	if err != nil {
		return fmt.Errorf("con view 1 %v", err)
	}
	defer func() { _ = v.Destroy(ctx) }()
	id := types.ManagedObjectReference{
		Type: "VirtualMachine", Value: moid,
	}
	v0 := mo.VirtualMachine{}
	if moid == "" {
		id, err = c.findOne(name, "VirtualMachine")
		if err != nil {
			return fmt.Errorf("c.findOne %v", err)
		}
	}
	err = v.Properties(ctx, id, []string{"name", "summary", "snapshot", "guest", "runtime"}, &v0)
	if err != nil {
		return errCheck(name, id, fmt.Errorf("vm v.properties %v", err))
	}
	elapsed := time.Since(start)
	var co int
	if v0.Snapshot != nil {
		co, err = snapshotCount(time.Now().Add(-age), v0.Snapshot.RootSnapshotList)
		if err != nil {
			return fmt.Errorf("snapshot %v", err)
		}
	}
	pr := newPrtgData(v0.Name)
	pr.moid = id.Value
	_ = pr.add(co, ps.SensorChannel{Channel: fmt.Sprintf("Snapshots Older Than %v", age), Unit: "Custom", CustomUnit: "Found", LimitErrorMsg: lim.ErrMsg, LimitMaxError: lim.MaxErr, LimitMaxWarning: lim.MaxWarn, LimitWarningMsg: lim.WarnMsg})
	gt := ps.SensorChannel{Channel: "guest tools running", Unit: "Custom", ValueLookup: "prtg.standardlookups.exchangedag.yesno.allstatesok"}
	var gtv int
	switch v0.Guest.ToolsRunningStatus {
	case "guestToolsRunning":
		gtv = 1
	default:
		gtv = 0
	}
	_ = pr.add(gtv, gt)
	hs := mo.HostSystem{}
	err = v.Properties(ctx, v0.Runtime.Host.Reference(), []string{"name"}, &hs)
	if err != nil {
		return fmt.Errorf("hostsystem properties failure %v", err)
	}
	for _, v := range v0.Guest.Disk {
		d := v.DiskPath
		if strings.Contains(d, "overlay") {
			continue
		}
		ca := v.Capacity
		free := v.FreeSpace
		one := ca / 100
		perc := free / one
		_ = pr.add(free, ps.SensorChannel{Channel: "free Bytes " + d, Unit: "BytesDisk", VolumeSize: "KiloByte", ShowChart: "0", ShowTable: "0"})
		_ = pr.add(perc, ps.SensorChannel{Channel: "free Space (Percent) " + d, Unit: "Percent", LimitMinWarning: "20", LimitMinError: "10", LimitWarningMsg: "Warning Low Space", LimitErrorMsg: "Critical disk space", LimitMode: "1"})
	}
	if v0.Runtime.PowerState == "poweredOn" {
		pr.text = "OK running on Host " + hs.Name
		err = c.Metrics(v0.Reference(), pr, vmSummaryDefault, 20)
		if err != nil {
			return err
		}
	} else {
		pr.text = fmt.Sprint(v0.Runtime.PowerState)
	}
	err = pr.print(elapsed, txt)
	_ = c.vmTracker(v0.Name, hs.Name)
	return err
}
func ( c * Client ) VMSummary ( name , moid string , lim * LimitsStruct , age time . Duration , txt bool , sensors [ ] string ) error { vmSummaryDefault = append ( vmSummaryDefault , sensors ... ) start := time . Now ( ) ctx := context . Background ( ) ctx , _ = context . WithTimeout ( ctx , 30 * time . Second ) if c . m == nil { return fmt . Errorf ( " " ) } v , err := c . m . CreateContainerView ( ctx , c . c . ServiceContent . RootFolder , [ ] string { " " } , true ) if err != nil { return fmt . Errorf ( " " , err ) } defer func ( ) { _ = v . Destroy ( ctx ) } ( ) id := types . ManagedObjectReference { Type : " " , Value : moid , } v0 := mo . VirtualMachine { } if moid == " " { id , err = c . findOne ( name , " " ) if err != nil { return fmt . Errorf ( " " , err ) } } err = v . Properties ( ctx , id , [ ] string { " " , " " , " " , " " , " " } , & v0 ) if err != nil { return errCheck ( name , id , fmt . Errorf ( " " , err ) ) } elapsed := time . Since ( start ) var co int if v0 . Snapshot != nil { co , err = snapshotCount ( time . Now ( ) . Add ( - age ) , v0 . Snapshot . RootSnapshotList ) if err != nil { return fmt . Errorf ( " " , err ) } } pr := newPrtgData ( v0 . Name ) pr . moid = id . Value _ = pr . add ( co , ps . SensorChannel { Channel : fmt . Sprintf ( " " , age ) , Unit : " " , CustomUnit : " " , LimitErrorMsg : lim . ErrMsg , LimitMaxError : lim . MaxErr , LimitMaxWarning : lim . MaxWarn , LimitWarningMsg : lim . WarnMsg } ) gt := ps . SensorChannel { Channel : " " , Unit : " " , ValueLookup : " " } var gtv int switch v0 . Guest . ToolsRunningStatus { case " " : gtv = 1 default : gtv = 0 } _ = pr . add ( gtv , gt ) hs := mo . HostSystem { } err = v . Properties ( ctx , v0 . Runtime . Host . Reference ( ) , [ ] string { " " } , & hs ) if err != nil { return fmt . Errorf ( " " , err ) } for _ , v := range v0 . Guest . Disk { d := v . DiskPath if strings . Contains ( d , " " ) { continue } ca := v . Capacity free := v . FreeSpace one := ca / 100 perc := free / one _ = pr . add ( free , ps . SensorChannel { Channel : " " + d , Unit : " " , VolumeSize : " " , ShowChart : " " , ShowTable : " " } ) _ = pr . add ( perc , ps . SensorChannel { Channel : " " + d , Unit : " " , LimitMinWarning : " " , LimitMinError : " " , LimitWarningMsg : " " , LimitErrorMsg : " " , LimitMode : " " } ) } if v0 . Runtime . PowerState == " " { pr . text = " " + hs . Name err = c . Metrics ( v0 . Reference ( ) , pr , vmSummaryDefault , 20 ) if err != nil { return err } } else { pr . text = fmt . Sprint ( v0 . Runtime . PowerState ) } err = pr . print ( elapsed , txt ) _ = c . vmTracker ( v0 . Name , hs . Name ) return err }
VMSummary  stats for a VM
VMSummary stats for a VM