Detecting other events under Virtual Server

Having now talked about how to detect standard Virtual Server and virtual machine events the next question is how do we go about detecting the not-so-standard events?  Thankfully Virtual Server provides a generic event handler that can be used as follows:

Option Explicit

Dim vs, alive, checkEventId

‘Jump to the main routine



sub keepAlive()

‘ This subroutine makes sure that the script hangs around in order
‘ to capture any Virtual Server events

while (alive = 1)

end sub


Sub vs_OnEventLogged(eventID)

   if Cstr(eventID) = checkEventId then
      wscript.echo “Someone connected to VMRC”
      end if

   alive = 0

end sub


sub main()

   alive = 1

   ‘This is the event ID for someone connecting to the server via VMRC

   checkEventId = “1090847744”

   ‘Create Virtual Server COM object and indicate that all subroutines
   ‘that begin with “vs_” are event handlers

   Set vs = WScript.CreateObject( “VirtualServer.Application” )
            WScript.ConnectObject vs, “vs_”


end sub


As you can see this script waits for someone to connect to the Virtual Server via VMRC and then lets you know.  There is one big problem with this approach however – and that is that we have not provided official documentation on any of the EventIDs (I suspect that this was overlooked by accident) which means that in oder to use this approach you will need to output all eventIDs for a while in order to figure out which ones you care about.  The one tip that I can give you is that negative event IDs are used for errors while positive event IDs are used for informational events.