//DsSummary stats for a datastore
DsSummary stats for a datastore
// DsSummary stats for a datastore
func (c *Client) DsSummary(name, moid string, lim *LimitsStruct, js bool) (err error) {
	start := time.Now()
	ctx := context.Background()
	ctx, _ = context.WithTimeout(ctx, 30*time.Second)
	v, err := c.m.CreateContainerView(ctx, c.c.ServiceContent.RootFolder, []string{"Datastore"}, true)
	if err != nil {
		return nil
	}
	defer func() { _ = v.Destroy(ctx) }()
	id := types.ManagedObjectReference{
		Type:  "Datastore",
		Value: moid,
	}
	if moid == "" {
		id, err = c.findOne(name, id.Type)
		if err != nil {
			return fmt.Errorf("c.findOne %v", err)
		}
	}
	ds := mo.Datastore{}
	err = v.Properties(ctx, id, []string{"name", "summary"}, &ds)
	if err != nil {
		return errCheck(name, id, fmt.Errorf("ds v.properties %v", err))
	}
	pr := newPrtgData(ds.Name)
	pr.moid = id.Value
	whole := ds.Summary.Capacity
	free := ds.Summary.FreeSpace
	p1 := whole / 100
	if p1 > 0 {
		freep := free / p1
		provisioned := 100 - freep
		_ = pr.add(freep, ps.SensorChannel{Channel: "Free space (Percent)", Unit: "Percent", DecimalMode: "1", LimitMinWarning: lim.MinWarn, LimitMinError: lim.MinErr, LimitWarningMsg: "Warning Low Space", LimitErrorMsg: "Critical disk space", LimitMode: "1"})
		_ = pr.add(provisioned, ps.SensorChannel{Channel: "Used Space (Percent)", Unit: "Percent", DecimalMode: "1"})
	}
	_ = pr.add(whole, ps.SensorChannel{Channel: "Total capacity", Unit: "BytesDisk", VolumeSize: "KiloByte"})
	_ = pr.add(free, ps.SensorChannel{Channel: "Free Bytes", Unit: "BytesDisk", VolumeSize: "KiloByte", ShowTable: "0", ShowChart: "0"})
	mm := "0"
	if ds.Summary.MaintenanceMode != "normal" {
		mm = "1"
	}
	_ = pr.add(mm, ps.SensorChannel{Channel: "Maintenance Mode", Unit: "Custom", LimitMaxWarning: "1", ValueLookup: "prtg.standardlookups.boolean.statefalseok"})
	_ = pr.add(boolToInt(ds.Summary.Accessible), ps.SensorChannel{Channel: "Accessible", Unit: "Custom", LimitMaxWarning: "1", ValueLookup: "prtg.standardlookups.boolean.statetrueok"})
	err = c.Metrics(ds.Reference(), pr, dsSummaryDefault, 1800)
	if err != nil {
		return err
	}
	_ = pr.print(time.Since(start), js)
	return nil
}
func ( c * Client ) DsSummary ( name , moid string , lim * LimitsStruct , js bool ) ( err error ) { start := time . Now ( ) ctx := context . Background ( ) ctx , _ = context . WithTimeout ( ctx , 30 * time . Second ) v , err := c . m . CreateContainerView ( ctx , c . c . ServiceContent . RootFolder , [ ] string { " " } , true ) if err != nil { return nil } defer func ( ) { _ = v . Destroy ( ctx ) } ( ) id := types . ManagedObjectReference { Type : " " , Value : moid , } if moid == " " { id , err = c . findOne ( name , id . Type ) if err != nil { return fmt . Errorf ( " " , err ) } } ds := mo . Datastore { } err = v . Properties ( ctx , id , [ ] string { " " , " " } , & ds ) if err != nil { return errCheck ( name , id , fmt . Errorf ( " " , err ) ) } pr := newPrtgData ( ds . Name ) pr . moid = id . Value whole := ds . Summary . Capacity free := ds . Summary . FreeSpace p1 := whole / 100 if p1 > 0 { freep := free / p1 provisioned := 100 - freep _ = pr . add ( freep , ps . SensorChannel { Channel : " " , Unit : " " , DecimalMode : " " , LimitMinWarning : lim . MinWarn , LimitMinError : lim . MinErr , LimitWarningMsg : " " , LimitErrorMsg : " " , LimitMode : " " } ) _ = pr . add ( provisioned , ps . SensorChannel { Channel : " " , Unit : " " , DecimalMode : " " } ) } _ = pr . add ( whole , ps . SensorChannel { Channel : " " , Unit : " " , VolumeSize : " " } ) _ = pr . add ( free , ps . SensorChannel { Channel : " " , Unit : " " , VolumeSize : " " , ShowTable : " " , ShowChart : " " } ) mm := " " if ds . Summary . MaintenanceMode != " " { mm = " " } _ = pr . add ( mm , ps . SensorChannel { Channel : " " , Unit : " " , LimitMaxWarning : " " , ValueLookup : " " } ) _ = pr . add ( boolToInt ( ds . Summary . Accessible ) , ps . SensorChannel { Channel : " " , Unit : " " , LimitMaxWarning : " " , ValueLookup : " " } ) err = c . Metrics ( ds . Reference ( ) , pr , dsSummaryDefault , 1800 ) if err != nil { return err } _ = pr . print ( time . Since ( start ) , js ) return nil }
DsSummary stats for a datastore
DsSummary stats for a datastore