VMware Cloud Community
Zsoldier
Expert
Expert
Jump to solution

Task "StartedTime", "QueuedTime", or "CompletedTime" = Snapshot created time?

I'm leaning on StartedTime right now, but need your input.

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
Zsoldier
Expert
Expert
Jump to solution

Submitted reply too soon.  I added a check to look for snapshot object id match.  So now even if I get multiple tasks that match within a 60 second window, I look @ the task's result to match against the snapshot I'm looking for.  Like so:

$Task = Get-VITasksFaster -Entity $VM -Start $Snapshot.created.addseconds(-60) -TimeType "StartedTime" -Finish $Snapshot.created.AddSeconds(1) -Server $VIServer

$Task = $Task | where {$_.result -eq $Snapshot.Id}

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier

View solution in original post

Reply
0 Kudos
7 Replies
Brian_Graf
Enthusiast
Enthusiast
Jump to solution

What's your question? Queued time would most likely be when the command was actually sent. Started time would be when the Snapshot first kicks off, completed time is when the snapshot completes.

Senior Product Manager - Distributed Resource Management | @vBrianGraf
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Afaik the CompletedTime is most of the time not correct.

Have a look at the remark at the beginning of the TaskEvent object.

You would have to follow the eventChainId to get at the actual CompletedTime


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Zsoldier
Expert
Expert
Jump to solution

So here is what I'm trying to do for clarification:

  1. Get list of snapshots, filter for those that are 7 days or older.
  2. Find out the user who generated that snapshot by querying against its created datetime.
  3. Querying against events seems to be way off.  Querying against tasks seems to be most consistent against that task's start time.

I had originally assumed task completedtime would match up to the snapshot created datetime, but that seems to be way off.

Here is the snippet I have for my snapshot management script.  I'm extrapolating an e-mail address from the matching AD account to annoy them.

$Task = Get-VITasksFaster -Entity $VM -Start $Snapshot.created.addseconds(-1) -TimeType "StartedTime" -Finish $Snapshot.created.AddSeconds(1) -Server $VIServer

  $Events = Get-VIEventsFaster -EventChainID $Task.EventChainID -Server $VIServer  # This is really redundant, not needed, just here because I'm too lazy to change the rest of the script.

  If ($Events -ne $null){$Username = Get-QADUser $Events.username}

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
Reply
0 Kudos
Zsoldier
Expert
Expert
Jump to solution

That was my original assumption as well.  StartedTime seems to more closely match the Snapshot object's 'created' time.

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

If you look at Alan's Snapshot Reminder, for which I wrote the Get-SnapshotExtra function, you'll notice I did something similar.

I take the snapshot creation date minus 5 seconds, and then look in the events for a corresponding CreateSnapshot event.

The function does a number of tests to determine the correct event, but it is not fool-proof.

If 2 or more snapshots of the same VM are created in a matter of seconds, the function might not find the correct user.

Also note that this event has the correct State (Success) and the correct user who initiated the snapshot.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Zsoldier
Expert
Expert
Jump to solution

Ok, that is actually helpful.  I'm taking it one step further and adding an 'entity' object in the taskfilterspec which should reduce the possible return of multiple matching tasks within a 2 second window.  After playing w/ my function/script, 'startedtime' seems to match most consistently and I can stay within a two second window.  Thanks LucD and vExpert: Brian Graf for your input.

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
Reply
0 Kudos
Zsoldier
Expert
Expert
Jump to solution

Submitted reply too soon.  I added a check to look for snapshot object id match.  So now even if I get multiple tasks that match within a 60 second window, I look @ the task's result to match against the snapshot I'm looking for.  Like so:

$Task = Get-VITasksFaster -Entity $VM -Start $Snapshot.created.addseconds(-60) -TimeType "StartedTime" -Finish $Snapshot.created.AddSeconds(1) -Server $VIServer

$Task = $Task | where {$_.result -eq $Snapshot.Id}

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
Reply
0 Kudos