Skip to content

Instantly share code, notes, and snippets.

@embano1
Last active May 3, 2021 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save embano1/98ebad0ed7ff7e9c1ee8f0072d114a24 to your computer and use it in GitHub Desktop.
Save embano1/98ebad0ed7ff7e9c1ee8f0072d114a24 to your computer and use it in GitHub Desktop.
Run govmomi events example

Requirements

  • Access to vCenter (network connection, account to read events)
  • git (to clone the repository)
  • go +v1.13 (to build the example binary)

Steps

Check out the repository

$ git clone https://github.com/vmware/govmomi.git
$ cd govmomi/examples/events

Build the binary

$ GO111MODULE=on go build -o events .

# verify installation worked
$ ./events -h
Usage of ./events:
  -b duration
        Begin time (default 10m0s)
  -e duration
        End time
  -f    Follow event stream
  -insecure
        Don't verify the server's certificate chain [GOVMOMI_INSECURE]
  -url string
        ESX or vCenter URL [GOVMOMI_URL]

Execute the binary against vCenter

# -f will follow the event stream and wait for new events
$ ./events -insecure -url https://administrator@vsphere.local:passw0rd@vcenter.ip.or.fqdn:443/sdk -f

💡 By default the event stream will start from t -10min. This can be configured with the -b parameter, e.g. -b 1h to start streaming events from one hour ago.

Enabel SOAP Debug

Create a git patch file

$ cat << EOF > patch
diff --git a/examples/events/main.go b/examples/events/main.go
index 9a8bf1a2..d20f162c 100644
--- a/examples/events/main.go
+++ b/examples/events/main.go
@@ -26,6 +26,7 @@
 	"github.com/vmware/govmomi/event"
 	"github.com/vmware/govmomi/examples"
 	"github.com/vmware/govmomi/vim25"
+	"github.com/vmware/govmomi/vim25/debug"
 	"github.com/vmware/govmomi/vim25/methods"
 	"github.com/vmware/govmomi/vim25/types"
 )
@@ -37,6 +38,7 @@ func main() {
 	begin := flag.Duration("b", 10*time.Minute, "Begin time") // default BeginTime is 10min ago
 	end := flag.Duration("e", 0, "End time")
 	follow := flag.Bool("f", false, "Follow event stream")
+	debug.SetProvider(&debug.LogProvider{})
 
 	examples.Run(func(ctx context.Context, c *vim25.Client) error {
 		m := event.NewManager(c)
EOF

Apply the patch:

$ git apply patch

Rebuild the events binary as described above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment