Ah, my bad, misunderstood you there. Yes, it's the third argument of the hook call, so $3 is the correct approach.
First argument is the phase (job-start, job-end or job-abort), second the mode (stop, suspend or snapshot), and third one the vmid. Please also notice the usage of environment...