Monitor Horizon logins via Slack webhook

Nico and I are working on a training idea we’re calling Start Coding: Today! The idea is that anybody can learn the basics of coding, but most non-developers have no idea where to start.

We are running training sessions during our annual sales kickoff, and we are using Horizon desktops to deliver the training. We have installed all of the necessary tools in the desktop – PowerCLI, Terraform, cURL, etc. The schedule is such that we have a very short time to get everybody logged into a desktop and actively working on the content.

We wanted a way to be able to monitor the Horizon desktop pool for logins – ideally completely separate from our laptops that are being used. We have one monitor presenting, the other monitor covering Zoom and speaker notes, and we’re using an iPad for continuous verification of the quality of the presentation.

The Horizon connection broker is behind a firewall, so it means we either have to have a separate Horizon session to monitor the desktop pool, and we really didn’t want to have to be flipping back and forth between desktop sessions.

Slack webhooks were fresh in my mind from this post on monitoring VMC maintenance with webhooks. I thought that I should be able to crank out a PowerCLI script that monitors the number of connected sessions in a desktop pool.

Script requirements:

  • Tell me how many people are logged in
  • Tell me how many desktops are available
  • Update every 5 seconds
  • Write the message to Slack

Since I already had a Slack app configured, all I had to do was create a new Slack channel and add an additional webhook targeting that channel.

I created this PowerCLI script. Here is the sample output – I start with 0 logins, then test by logging in one user

A second user logs in

A third and fourth user log in, then one user logs out.

Instant clones are REALLY fast, but we did catch one in the process of refreshing itself after logoff – the total count drops to 34 for 2 iterations.

All of my test users log off and we’re back down to 0.

Hopefully this post helps you automate something in your Horizon environment.

Leave a Reply

Your email address will not be published. Required fields are marked *