//SnapShotsOlderThan tag focused snapshot reporting
SnapShotsOlderThan tag focused snapshot reporting
// SnapShotsOlderThan tag focused snapshot reporting
func (c *Client) SnapShotsOlderThan(f property.Filter, tagIds []string, lim *LimitsStruct, age time.Duration, txt bool) (err error) {
	start := time.Now()
	ctx := context.Background()
	ctx, _ = context.WithTimeout(ctx, 30*time.Second)
	m := view.NewManager(c.c)
	v, err := m.CreateContainerView(ctx, c.c.ServiceContent.RootFolder, []string{"VirtualMachine"}, true)
	if err != nil {
		return
	}
	defer func() { _ = v.Destroy(ctx) }()
	var vms []mo.VirtualMachine
	err = v.RetrieveWithFilter(ctx, []string{"ManagedEntity"}, []string{"snapshot", "name"}, &vms, f)
	if err != nil {
		return fmt.Errorf("retrieve issue %v", err)
	}
	pr := newPrtgData("snapshots")
	tm := NewTagMap()
	err = c.list(tagIds, tm)
	if err != nil {
		return err
	}
	respTime := time.Since(start)
	b := time.Now().Add(-age)
	wg := sync.WaitGroup{}
	noTags := len(tagIds) == 0
	for _, v := range vms {
		wg.Add(1)
		go func(v mo.VirtualMachine) {
			defer wg.Done()
			var co int
			if v.Snapshot != nil {
				co, err = snapshotCount(b, v.Snapshot.RootSnapshotList)
				if err != nil {
					return
				}
			}
			if noTags || tm.check(v.Self.Value, tagIds) {
				stat := fmt.Sprintf("%v", v.Name)
				err = pr.add(co, ps.SensorChannel{Channel: stat, Unit: "Custom", CustomUnit: "Found", LimitErrorMsg: lim.ErrMsg, LimitMaxError: lim.MaxErr, LimitMaxWarning: lim.MaxWarn, LimitWarningMsg: lim.WarnMsg})
				if err != nil {
					return
				}
			}
		}(v)
	}
	wg.Wait()
	_ = pr.print(respTime, txt)
	return err
}
func ( c * Client ) SnapShotsOlderThan ( f property . Filter , tagIds [ ] string , lim * LimitsStruct , age time . Duration , txt bool ) ( err error ) { start := time . Now ( ) ctx := context . Background ( ) ctx , _ = context . WithTimeout ( ctx , 30 * time . Second ) m := view . NewManager ( c . c ) v , err := m . CreateContainerView ( ctx , c . c . ServiceContent . RootFolder , [ ] string { " " } , true ) if err != nil { return } defer func ( ) { _ = v . Destroy ( ctx ) } ( ) var vms [ ] mo . VirtualMachine err = v . RetrieveWithFilter ( ctx , [ ] string { " " } , [ ] string { " " , " " } , & vms , f ) if err != nil { return fmt . Errorf ( " " , err ) } pr := newPrtgData ( " " ) tm := NewTagMap ( ) err = c . list ( tagIds , tm ) if err != nil { return err } respTime := time . Since ( start ) b := time . Now ( ) . Add ( - age ) wg := sync . WaitGroup { } noTags := len ( tagIds ) == 0 for _ , v := range vms { wg . Add ( 1 ) go func ( v mo . VirtualMachine ) { defer wg . Done ( ) var co int if v . Snapshot != nil { co , err = snapshotCount ( b , v . Snapshot . RootSnapshotList ) if err != nil { return } } if noTags || tm . check ( v . Self . Value , tagIds ) { stat := fmt . Sprintf ( " " , v . Name ) err = pr . add ( co , ps . SensorChannel { Channel : stat , Unit : " " , CustomUnit : " " , LimitErrorMsg : lim . ErrMsg , LimitMaxError : lim . MaxErr , LimitMaxWarning : lim . MaxWarn , LimitWarningMsg : lim . WarnMsg } ) if err != nil { return } } } ( v ) } wg . Wait ( ) _ = pr . print ( respTime , txt ) return err }
SnapShotsOlderThan tag focused snapshot reporting
SnapShotsOlderThan tag focused snapshot reporting
// retrieve snapshot info // retrieve tags and object associations